Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into scrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkan1 committed Apr 20, 2023
2 parents 9d4fa1b + 063ce50 commit dc5dbbb
Show file tree
Hide file tree
Showing 70 changed files with 662 additions and 259 deletions.
66 changes: 18 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chatbot UI

Chatbot UI is an advanced chatbot kit for OpenAI's chat models built on top of [Chatbot UI Lite](https://github.com/mckaywrigley/chatbot-ui-lite) using Next.js, TypeScript, and Tailwind CSS.
Chatbot UI is an open source chat UI for AI models.

See a [demo](https://twitter.com/mckaywrigley/status/1640380021423603713?s=46&t=AowqkodyK6B4JccSOxSPew).

Expand All @@ -14,36 +14,8 @@ Expect frequent improvements.

**Next up:**

- [ ] Delete messages
- [ ] More model settings
- [ ] Plugins

**Recent updates:**

- [x] Prompt templates (3/27/23)
- [x] Regenerate & edit responses (3/25/23)
- [x] Folders (3/24/23)
- [x] Search chat content (3/23/23)
- [x] Stop message generation (3/22/23)
- [x] Import/Export chats (3/22/23)
- [x] Custom system prompt (3/21/23)
- [x] Error handling (3/20/23)
- [x] GPT-4 support (access required) (3/20/23)
- [x] Search conversations (3/19/23)
- [x] Code syntax highlighting (3/18/23)
- [x] Toggle sidebar (3/18/23)
- [x] Conversation naming (3/18/23)
- [x] Github flavored markdown (3/18/23)
- [x] Add OpenAI API key in app (3/18/23)
- [x] Markdown support (3/17/23)

## Modifications

Modify the chat interface in `components/Chat`.

Modify the sidebar interface in `components/Sidebar`.

Modify the system prompt in `utils/server/index.ts`.
- [ ] Sharing
- [ ] "Bots"

## Deploy

Expand All @@ -53,10 +25,6 @@ Host your own live version of Chatbot UI with Vercel.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fmckaywrigley%2Fchatbot-ui)

**Replit**

Fork Chatbot UI on Replit [here](https://replit.com/@MckayWrigley/chatbot-ui-pro?v=1).

**Docker**

Build locally:
Expand Down Expand Up @@ -112,24 +80,26 @@ You should be able to start chatting.

When deploying the application, the following environment variables can be set:

| Environment Variable | Default value | Description |
| --------------------- | ------------------------------ | ------------------------------------------------------- |
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
| OPENAI_API_HOST | `https://api.openai.com` | The base url, for Azure use `https://<endpoint>.openai.azure.com` |
| OPENAI_API_TYPE | `openai` | The API type, options are `openai` or `azure` |
| OPENAI_API_VERSION | `2023-03-15-preview` | Only applicable for Azure OpenAI |
| AZURE_DEPLOYMENT_ID | | Needed when Azure OpenAI, Ref [Azure OpenAI API](https://learn.microsoft.com/zh-cn/azure/cognitive-services/openai/reference#completions) |
| OPENAI_ORGANIZATION | | Your OpenAI organization ID |
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations, for Azure use `gpt-35-turbo` |
| NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT | [see here](utils/app/const.ts) | The default system prompt to use on new conversations |
| GOOGLE_API_KEY | | See [Custom Search JSON API documentation][GCSE] |
| GOOGLE_CSE_ID | | See [Custom Search JSON API documentation][GCSE] |
| Environment Variable | Default value | Description |
| --------------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
| OPENAI_API_HOST | `https://api.openai.com` | The base url, for Azure use `https://<endpoint>.openai.azure.com` |
| OPENAI_API_TYPE | `openai` | The API type, options are `openai` or `azure` |
| OPENAI_API_VERSION | `2023-03-15-preview` | Only applicable for Azure OpenAI |
| AZURE_DEPLOYMENT_ID | | Needed when Azure OpenAI, Ref [Azure OpenAI API](https://learn.microsoft.com/zh-cn/azure/cognitive-services/openai/reference#completions) |
| OPENAI_ORGANIZATION | | Your OpenAI organization ID |
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations, for Azure use `gpt-35-turbo` |
| NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT | [see here](utils/app/const.ts) | The default system prompt to use on new conversations |
| NEXT_PUBLIC_DEFAULT_TEMPERATURE | 1 | The default temperature to use on new conversations |
| GOOGLE_API_KEY | | See [Custom Search JSON API documentation][GCSE] |
| GOOGLE_CSE_ID | | See [Custom Search JSON API documentation][GCSE] |

If you do not provide an OpenAI API key with `OPENAI_API_KEY`, users will have to provide their own key.

If you don't have an OpenAI API key, you can get one [here](https://platform.openai.com/account/api-keys).

## Contact

If you have any questions, feel free to reach out to me on [Twitter](https://twitter.com/mckaywrigley).
If you have any questions, feel free to reach out to Mckay on [Twitter](https://twitter.com/mckaywrigley).

[GCSE]: https://developers.google.com/custom-search/v1/overview
53 changes: 53 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Security Policy


This security policy outlines the process for reporting vulnerabilities and secrets found within this GitHub repository. It is essential that all contributors and users adhere to this policy in order to maintain a secure and stable environment.

## Reporting a Vulnerability

If you discover a vulnerability within the code, dependencies, or any other component of this repository, please follow these steps:

1. **Do not disclose the vulnerability publicly.** Publicly disclosing a vulnerability may put the project at risk and could potentially harm other users.

2. **Contact the repository maintainer(s) privately.** Send a private message or email to the maintainer(s) with a detailed description of the vulnerability. Include the following information:

- The affected component(s)
- Steps to reproduce the issue
- Potential impact of the vulnerability
- Any possible mitigations or workarounds

3. **Wait for a response from the maintainer(s).** Please be patient, as they may need time to investigate and verify the issue. The maintainer(s) should acknowledge receipt of your report and provide an estimated time frame for addressing the vulnerability.

4. **Cooperate with the maintainer(s).** If requested, provide additional information or assistance to help resolve the issue.

5. **Do not disclose the vulnerability until the maintainer(s) have addressed it.** Once the issue has been resolved, the maintainer(s) may choose to publicly disclose the vulnerability and credit you for the discovery.

## Reporting Secrets

If you discover any secrets, such as API keys or passwords, within the repository, follow these steps:

1. **Do not share the secret or use it for unauthorized purposes.** Misusing a secret could have severe consequences for the project and its users.

2. **Contact the repository maintainer(s) privately.** Notify them of the discovered secret, its location, and any potential risks associated with it.

3. **Wait for a response and further instructions.**

## Responsible Disclosure

We encourage responsible disclosure of vulnerabilities and secrets. If you follow the steps outlined in this policy, we will work with you to understand and address the issue. We will not take legal action against individuals who discover and report vulnerabilities or secrets in accordance with this policy.

## Patching and Updates

We are committed to maintaining the security of our project. When vulnerabilities are reported and confirmed, we will:

1. Work diligently to develop and apply a patch or implement a mitigation strategy.
2. Keep the reporter informed about the progress of the fix.
3. Update the repository with the necessary patches and document the changes in the release notes or changelog.
4. Credit the reporter for the discovery, if they wish to be acknowledged.

## Contributing to Security

We welcome contributions that help improve the security of our project. If you have suggestions or want to contribute code to address security issues, please follow the standard contribution guidelines for this repository. When submitting a pull request related to security, please mention that it addresses a security issue and provide any necessary context.

By adhering to this security policy, you contribute to the overall security and stability of the project. Thank you for your cooperation and responsible handling of vulnerabilities and secrets.

51 changes: 26 additions & 25 deletions components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconArrowDown, IconClearAll, IconSettings } from '@tabler/icons-react';
import { IconClearAll, IconSettings } from '@tabler/icons-react';
import {
MutableRefObject,
memo,
Expand Down Expand Up @@ -28,11 +28,11 @@ import HomeContext from '@/pages/api/home/home.context';
import Spinner from '../Spinner';
import { ChatInput } from './ChatInput';
import { ChatLoader } from './ChatLoader';
import { ChatMessage } from './ChatMessage';
import { ErrorMessageDiv } from './ErrorMessageDiv';
import { ModelSelect } from './ModelSelect';
import { SystemPrompt } from './SystemPrompt';
import { TemperatureSlider } from './Temperature';
import { MemoizedChatMessage } from './MemoizedChatMessage';

interface Props {
stopConversationRef: MutableRefObject<boolean>;
Expand Down Expand Up @@ -98,7 +98,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
messages: updatedConversation.messages,
key: apiKey,
prompt: updatedConversation.prompt,
temperature: updatedConversation.temperature
temperature: updatedConversation.temperature,
};
const endpoint = getEndpoint(plugin);
let body;
Expand Down Expand Up @@ -398,7 +398,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
>
{selectedConversation?.messages.length === 0 ? (
<>
<div className="mx-auto flex w-[350px] flex-col space-y-10 pt-12 sm:w-[600px]">
<div className="mx-auto flex flex-col space-y-5 md:space-y-10 px-3 pt-5 md:pt-12 sm:max-w-[600px]">
<div className="text-center text-3xl font-semibold text-gray-800 dark:text-gray-100">
{models.length === 0 ? (
<div>
Expand All @@ -425,22 +425,23 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
/>

<TemperatureSlider
label="Temperature"
onChangeTemperature={(temperature) =>
handleUpdateConversation(selectedConversation, {
key: 'temperature',
value: temperature,
})
}
/>
label={t('Temperature')}
onChangeTemperature={(temperature) =>
handleUpdateConversation(selectedConversation, {
key: 'temperature',
value: temperature,
})
}
/>
</div>
)}
</div>
</>
) : (
<>
<div className="flex justify-center border border-b-neutral-300 bg-neutral-100 py-2 text-sm text-neutral-500 dark:border-none dark:bg-[#444654] dark:text-neutral-200">
{t('Model')}: {selectedConversation?.model.name}
<div className="sticky top-0 z-10 flex justify-center border border-b-neutral-300 bg-neutral-100 py-2 text-sm text-neutral-500 dark:border-none dark:bg-[#444654] dark:text-neutral-200">
{t('Model')}: {selectedConversation?.model.name} | {t('Temp')}
: {selectedConversation?.temperature} |
<button
className="ml-2 cursor-pointer hover:opacity-50"
onClick={handleSettings}
Expand All @@ -463,10 +464,18 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
)}

{selectedConversation?.messages.map((message, index) => (
<ChatMessage
<MemoizedChatMessage
key={index}
message={message}
messageIndex={index}
onEdit={(editedMessage) => {
setCurrentMessage(editedMessage);
// discard edited message and the ones that come after then resend
handleSend(
editedMessage,
selectedConversation?.messages.length - index,
);
}}
/>
))}

Expand All @@ -487,24 +496,16 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
setCurrentMessage(message);
handleSend(message, 0, plugin);
}}
onScrollDownClick={handleScrollDown}
onRegenerate={() => {
if (currentMessage) {
handleSend(currentMessage, 2, null);
}
}}
showScrollDownButton={showScrollDownButton}
/>
</>
)}
{showScrollDownButton && (
<div className="absolute bottom-0 right-0 mb-4 mr-4 pb-20">
<button
className="flex h-7 w-7 items-center justify-center rounded-full bg-neutral-300 text-gray-800 shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-neutral-200"
onClick={handleScrollDown}
>
<IconArrowDown size={18} />
</button>
</div>
)}
</div>
);
});
Expand Down
18 changes: 17 additions & 1 deletion components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
IconArrowDown,
IconBolt,
IconBrandGoogle,
IconPlayerStop,
Expand Down Expand Up @@ -30,15 +31,19 @@ import { VariableModal } from './VariableModal';
interface Props {
onSend: (message: Message, plugin: Plugin | null) => void;
onRegenerate: () => void;
onScrollDownClick: () => void;
stopConversationRef: MutableRefObject<boolean>;
textareaRef: MutableRefObject<HTMLTextAreaElement | null>;
showScrollDownButton: boolean;
}

export const ChatInput = ({
onSend,
onRegenerate,
onScrollDownClick,
stopConversationRef,
textareaRef,
showScrollDownButton,
}: Props) => {
const { t } = useTranslation('chat');

Expand Down Expand Up @@ -341,6 +346,17 @@ export const ChatInput = ({
)}
</button>

{showScrollDownButton && (
<div className="absolute bottom-12 right-0 lg:bottom-0 lg:-right-10">
<button
className="flex h-7 w-7 items-center justify-center rounded-full bg-neutral-300 text-gray-800 shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-neutral-200"
onClick={onScrollDownClick}
>
<IconArrowDown size={18} />
</button>
</div>
)}

{showPromptList && filteredPrompts.length > 0 && (
<div className="absolute bottom-12 w-full">
<PromptList
Expand All @@ -355,7 +371,7 @@ export const ChatInput = ({

{isModalVisible && (
<VariableModal
prompt={prompts[activePromptIndex]}
prompt={filteredPrompts[activePromptIndex]}
variables={variables}
onSubmit={handleSubmit}
onClose={() => setIsModalVisible(false)}
Expand Down

0 comments on commit dc5dbbb

Please sign in to comment.