Skip to content

Commit 642beea

Browse files
authored
Merge pull request #33 from mckaywrigley/main
Fork Sync: Update from parent repository
2 parents 4381409 + fa3f6e9 commit 642beea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+749
-263
lines changed

README.md

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chatbot UI
22

3-
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.
3+
Chatbot UI is an open source chat UI for AI models.
44

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

@@ -14,36 +14,8 @@ Expect frequent improvements.
1414

1515
**Next up:**
1616

17-
- [ ] Delete messages
18-
- [ ] More model settings
19-
- [ ] Plugins
20-
21-
**Recent updates:**
22-
23-
- [x] Prompt templates (3/27/23)
24-
- [x] Regenerate & edit responses (3/25/23)
25-
- [x] Folders (3/24/23)
26-
- [x] Search chat content (3/23/23)
27-
- [x] Stop message generation (3/22/23)
28-
- [x] Import/Export chats (3/22/23)
29-
- [x] Custom system prompt (3/21/23)
30-
- [x] Error handling (3/20/23)
31-
- [x] GPT-4 support (access required) (3/20/23)
32-
- [x] Search conversations (3/19/23)
33-
- [x] Code syntax highlighting (3/18/23)
34-
- [x] Toggle sidebar (3/18/23)
35-
- [x] Conversation naming (3/18/23)
36-
- [x] Github flavored markdown (3/18/23)
37-
- [x] Add OpenAI API key in app (3/18/23)
38-
- [x] Markdown support (3/17/23)
39-
40-
## Modifications
41-
42-
Modify the chat interface in `components/Chat`.
43-
44-
Modify the sidebar interface in `components/Sidebar`.
45-
46-
Modify the system prompt in `utils/server/index.ts`.
17+
- [ ] Sharing
18+
- [ ] "Bots"
4719

4820
## Deploy
4921

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

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

56-
**Replit**
57-
58-
Fork Chatbot UI on Replit [here](https://replit.com/@MckayWrigley/chatbot-ui-pro?v=1).
59-
6028
**Docker**
6129

6230
Build locally:
@@ -112,24 +80,26 @@ You should be able to start chatting.
11280

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

115-
| Environment Variable | Default value | Description |
116-
| --------------------- | ------------------------------ | ------------------------------------------------------- |
117-
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
118-
| OPENAI_API_HOST | `https://api.openai.com` | The base url, for Azure use `https://<endpoint>.openai.azure.com` |
119-
| OPENAI_API_TYPE | `openai` | The API type, options are `openai` or `azure` |
120-
| OPENAI_API_VERSION | `2023-03-15-preview` | Only applicable for Azure OpenAI |
121-
| AZURE_DEPLOYMENT_ID | | Needed when Azure OpenAI, Ref [Azure OpenAI API](https://learn.microsoft.com/zh-cn/azure/cognitive-services/openai/reference#completions) |
122-
| OPENAI_ORGANIZATION | | Your OpenAI organization ID |
123-
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations, for Azure use `gpt-35-turbo` |
124-
| NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT | [see here](utils/app/const.ts) | The default system prompt to use on new conversations |
125-
| GOOGLE_API_KEY | | See [Custom Search JSON API documentation][GCSE] |
126-
| GOOGLE_CSE_ID | | See [Custom Search JSON API documentation][GCSE] |
83+
| Environment Variable | Default value | Description |
84+
| --------------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
85+
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
86+
| OPENAI_API_HOST | `https://api.openai.com` | The base url, for Azure use `https://<endpoint>.openai.azure.com` |
87+
| OPENAI_API_TYPE | `openai` | The API type, options are `openai` or `azure` |
88+
| OPENAI_API_VERSION | `2023-03-15-preview` | Only applicable for Azure OpenAI |
89+
| AZURE_DEPLOYMENT_ID | | Needed when Azure OpenAI, Ref [Azure OpenAI API](https://learn.microsoft.com/zh-cn/azure/cognitive-services/openai/reference#completions) |
90+
| OPENAI_ORGANIZATION | | Your OpenAI organization ID |
91+
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations, for Azure use `gpt-35-turbo` |
92+
| NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT | [see here](utils/app/const.ts) | The default system prompt to use on new conversations |
93+
| NEXT_PUBLIC_DEFAULT_TEMPERATURE | 1 | The default temperature to use on new conversations |
94+
| GOOGLE_API_KEY | | See [Custom Search JSON API documentation][GCSE] |
95+
| GOOGLE_CSE_ID | | See [Custom Search JSON API documentation][GCSE] |
12796

12897
If you do not provide an OpenAI API key with `OPENAI_API_KEY`, users will have to provide their own key.
98+
12999
If you don't have an OpenAI API key, you can get one [here](https://platform.openai.com/account/api-keys).
130100

131101
## Contact
132102

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

135105
[GCSE]: https://developers.google.com/custom-search/v1/overview

SECURITY.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Security Policy
2+
3+
4+
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.
5+
6+
## Reporting a Vulnerability
7+
8+
If you discover a vulnerability within the code, dependencies, or any other component of this repository, please follow these steps:
9+
10+
1. **Do not disclose the vulnerability publicly.** Publicly disclosing a vulnerability may put the project at risk and could potentially harm other users.
11+
12+
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:
13+
14+
- The affected component(s)
15+
- Steps to reproduce the issue
16+
- Potential impact of the vulnerability
17+
- Any possible mitigations or workarounds
18+
19+
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.
20+
21+
4. **Cooperate with the maintainer(s).** If requested, provide additional information or assistance to help resolve the issue.
22+
23+
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.
24+
25+
## Reporting Secrets
26+
27+
If you discover any secrets, such as API keys or passwords, within the repository, follow these steps:
28+
29+
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.
30+
31+
2. **Contact the repository maintainer(s) privately.** Notify them of the discovered secret, its location, and any potential risks associated with it.
32+
33+
3. **Wait for a response and further instructions.**
34+
35+
## Responsible Disclosure
36+
37+
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.
38+
39+
## Patching and Updates
40+
41+
We are committed to maintaining the security of our project. When vulnerabilities are reported and confirmed, we will:
42+
43+
1. Work diligently to develop and apply a patch or implement a mitigation strategy.
44+
2. Keep the reporter informed about the progress of the fix.
45+
3. Update the repository with the necessary patches and document the changes in the release notes or changelog.
46+
4. Credit the reporter for the discovery, if they wish to be acknowledged.
47+
48+
## Contributing to Security
49+
50+
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.
51+
52+
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.
53+

components/Chat/Chat.tsx

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IconArrowDown, IconClearAll, IconSettings } from '@tabler/icons-react';
1+
import { IconClearAll, IconSettings } from '@tabler/icons-react';
22
import {
33
MutableRefObject,
44
memo,
@@ -28,11 +28,11 @@ import HomeContext from '@/pages/api/home/home.context';
2828
import Spinner from '../Spinner';
2929
import { ChatInput } from './ChatInput';
3030
import { ChatLoader } from './ChatLoader';
31-
import { ChatMessage } from './ChatMessage';
3231
import { ErrorMessageDiv } from './ErrorMessageDiv';
3332
import { ModelSelect } from './ModelSelect';
3433
import { SystemPrompt } from './SystemPrompt';
3534
import { TemperatureSlider } from './Temperature';
35+
import { MemoizedChatMessage } from './MemoizedChatMessage';
3636

3737
interface Props {
3838
stopConversationRef: MutableRefObject<boolean>;
@@ -98,7 +98,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
9898
messages: updatedConversation.messages,
9999
key: apiKey,
100100
prompt: updatedConversation.prompt,
101-
temperature: updatedConversation.temperature
101+
temperature: updatedConversation.temperature,
102102
};
103103
const endpoint = getEndpoint(plugin);
104104
let body;
@@ -398,7 +398,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
398398
>
399399
{selectedConversation?.messages.length === 0 ? (
400400
<>
401-
<div className="mx-auto flex w-[350px] flex-col space-y-10 pt-12 sm:w-[600px]">
401+
<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]">
402402
<div className="text-center text-3xl font-semibold text-gray-800 dark:text-gray-100">
403403
{models.length === 0 ? (
404404
<div>
@@ -425,22 +425,23 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
425425
/>
426426

427427
<TemperatureSlider
428-
label="Temperature"
429-
onChangeTemperature={(temperature) =>
430-
handleUpdateConversation(selectedConversation, {
431-
key: 'temperature',
432-
value: temperature,
433-
})
434-
}
435-
/>
428+
label={t('Temperature')}
429+
onChangeTemperature={(temperature) =>
430+
handleUpdateConversation(selectedConversation, {
431+
key: 'temperature',
432+
value: temperature,
433+
})
434+
}
435+
/>
436436
</div>
437437
)}
438438
</div>
439439
</>
440440
) : (
441441
<>
442-
<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">
443-
{t('Model')}: {selectedConversation?.model.name}
442+
<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">
443+
{t('Model')}: {selectedConversation?.model.name} | {t('Temp')}
444+
: {selectedConversation?.temperature} |
444445
<button
445446
className="ml-2 cursor-pointer hover:opacity-50"
446447
onClick={handleSettings}
@@ -463,10 +464,18 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
463464
)}
464465

465466
{selectedConversation?.messages.map((message, index) => (
466-
<ChatMessage
467+
<MemoizedChatMessage
467468
key={index}
468469
message={message}
469470
messageIndex={index}
471+
onEdit={(editedMessage) => {
472+
setCurrentMessage(editedMessage);
473+
// discard edited message and the ones that come after then resend
474+
handleSend(
475+
editedMessage,
476+
selectedConversation?.messages.length - index,
477+
);
478+
}}
470479
/>
471480
))}
472481

@@ -487,24 +496,16 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
487496
setCurrentMessage(message);
488497
handleSend(message, 0, plugin);
489498
}}
499+
onScrollDownClick={handleScrollDown}
490500
onRegenerate={() => {
491501
if (currentMessage) {
492502
handleSend(currentMessage, 2, null);
493503
}
494504
}}
505+
showScrollDownButton={showScrollDownButton}
495506
/>
496507
</>
497508
)}
498-
{showScrollDownButton && (
499-
<div className="absolute bottom-0 right-0 mb-4 mr-4 pb-20">
500-
<button
501-
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"
502-
onClick={handleScrollDown}
503-
>
504-
<IconArrowDown size={18} />
505-
</button>
506-
</div>
507-
)}
508509
</div>
509510
);
510511
});

components/Chat/ChatInput.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
IconArrowDown,
23
IconBolt,
34
IconBrandGoogle,
45
IconPlayerStop,
@@ -30,15 +31,19 @@ import { VariableModal } from './VariableModal';
3031
interface Props {
3132
onSend: (message: Message, plugin: Plugin | null) => void;
3233
onRegenerate: () => void;
34+
onScrollDownClick: () => void;
3335
stopConversationRef: MutableRefObject<boolean>;
3436
textareaRef: MutableRefObject<HTMLTextAreaElement | null>;
37+
showScrollDownButton: boolean;
3538
}
3639

3740
export const ChatInput = ({
3841
onSend,
3942
onRegenerate,
43+
onScrollDownClick,
4044
stopConversationRef,
4145
textareaRef,
46+
showScrollDownButton,
4247
}: Props) => {
4348
const { t } = useTranslation('chat');
4449

@@ -341,6 +346,17 @@ export const ChatInput = ({
341346
)}
342347
</button>
343348

349+
{showScrollDownButton && (
350+
<div className="absolute bottom-12 right-0 lg:bottom-0 lg:-right-10">
351+
<button
352+
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"
353+
onClick={onScrollDownClick}
354+
>
355+
<IconArrowDown size={18} />
356+
</button>
357+
</div>
358+
)}
359+
344360
{showPromptList && filteredPrompts.length > 0 && (
345361
<div className="absolute bottom-12 w-full">
346362
<PromptList
@@ -355,7 +371,7 @@ export const ChatInput = ({
355371

356372
{isModalVisible && (
357373
<VariableModal
358-
prompt={prompts[activePromptIndex]}
374+
prompt={filteredPrompts[activePromptIndex]}
359375
variables={variables}
360376
onSubmit={handleSubmit}
361377
onClose={() => setIsModalVisible(false)}

components/Chat/ChatLoader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IconRobot } from '@tabler/icons-react';
2-
import { IconDots } from '@tabler/icons-react';
32
import { FC } from 'react';
43

54
interface Props { }
@@ -14,7 +13,7 @@ export const ChatLoader: FC<Props> = () => {
1413
<div className="min-w-[40px] items-end">
1514
<IconRobot size={30} />
1615
</div>
17-
<IconDots className="animate-pulse" />
16+
<span className="animate-pulse cursor-default mt-1"></span>
1817
</div>
1918
</div>
2019
);

0 commit comments

Comments
 (0)