✨ feat: add DEFAULT_MODEL environment variable (#280)
* ✨ feat: add DEFAULT_MODEL environment variable
* set the model maxLength setting in the models definition
* set the model tokenLimit setting in the models definition
This commit is contained in:
@@ -2,7 +2,7 @@ import { Conversation, Message } from '@/types/chat';
|
||||
import { IconArrowDown } from '@tabler/icons-react';
|
||||
import { KeyValuePair } from '@/types/data';
|
||||
import { ErrorMessage } from '@/types/error';
|
||||
import { OpenAIModel } from '@/types/openai';
|
||||
import { OpenAIModel, OpenAIModelID } from '@/types/openai';
|
||||
import { Prompt } from '@/types/prompt';
|
||||
import { throttle } from '@/utils';
|
||||
import { IconClearAll, IconKey, IconSettings } from '@tabler/icons-react';
|
||||
@@ -29,6 +29,7 @@ interface Props {
|
||||
models: OpenAIModel[];
|
||||
apiKey: string;
|
||||
serverSideApiKeyIsSet: boolean;
|
||||
defaultModelId: OpenAIModelID;
|
||||
messageIsStreaming: boolean;
|
||||
modelError: ErrorMessage | null;
|
||||
loading: boolean;
|
||||
@@ -48,6 +49,7 @@ export const Chat: FC<Props> = memo(
|
||||
models,
|
||||
apiKey,
|
||||
serverSideApiKeyIsSet,
|
||||
defaultModelId,
|
||||
messageIsStreaming,
|
||||
modelError,
|
||||
loading,
|
||||
@@ -206,6 +208,7 @@ export const Chat: FC<Props> = memo(
|
||||
<ModelSelect
|
||||
model={conversation.model}
|
||||
models={models}
|
||||
defaultModelId={defaultModelId}
|
||||
onModelChange={(model) =>
|
||||
onUpdateConversation(conversation, {
|
||||
key: 'model',
|
||||
@@ -236,12 +239,13 @@ export const Chat: FC<Props> = memo(
|
||||
className="ml-2 cursor-pointer hover:opacity-50"
|
||||
onClick={handleSettings}
|
||||
>
|
||||
<IconSettings size={18} />
|
||||
<IconSettings size={18} />
|
||||
</button>
|
||||
<button
|
||||
className="ml-2 cursor-pointer hover:opacity-50"
|
||||
onClick={onClearAll}>
|
||||
<IconClearAll size={18} />
|
||||
onClick={onClearAll}
|
||||
>
|
||||
<IconClearAll size={18} />
|
||||
</button>
|
||||
</div>
|
||||
{showSettings && (
|
||||
@@ -250,6 +254,7 @@ export const Chat: FC<Props> = memo(
|
||||
<ModelSelect
|
||||
model={conversation.model}
|
||||
models={models}
|
||||
defaultModelId={defaultModelId}
|
||||
onModelChange={(model) =>
|
||||
onUpdateConversation(conversation, {
|
||||
key: 'model',
|
||||
@@ -306,7 +311,7 @@ export const Chat: FC<Props> = memo(
|
||||
className="flex h-7 w-7 items-center justify-center rounded-full bg-white shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-[#515152d7]"
|
||||
onClick={handleScrollDown}
|
||||
>
|
||||
<IconArrowDown size={18}/>
|
||||
<IconArrowDown size={18} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Message } from '@/types/chat';
|
||||
import { OpenAIModel, OpenAIModelID } from '@/types/openai';
|
||||
import { OpenAIModel } from '@/types/openai';
|
||||
import { Prompt } from '@/types/prompt';
|
||||
import { IconPlayerStop, IconRepeat, IconSend } from '@tabler/icons-react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -56,7 +56,7 @@ export const ChatInput: FC<Props> = ({
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const value = e.target.value;
|
||||
const maxLength = model.id === OpenAIModelID.GPT_3_5 ? 12000 : 24000;
|
||||
const maxLength = model.maxLength;
|
||||
|
||||
if (value.length > maxLength) {
|
||||
alert(
|
||||
@@ -109,7 +109,10 @@ export const ChatInput: FC<Props> = ({
|
||||
const selectedPrompt = filteredPrompts[activePromptIndex];
|
||||
if (selectedPrompt) {
|
||||
setContent((prevContent) => {
|
||||
const newContent = prevContent?.replace(/\/\w*$/, selectedPrompt.content);
|
||||
const newContent = prevContent?.replace(
|
||||
/\/\w*$/,
|
||||
selectedPrompt.content,
|
||||
);
|
||||
return newContent;
|
||||
});
|
||||
handlePromptSelect(selectedPrompt);
|
||||
@@ -211,8 +214,9 @@ export const ChatInput: FC<Props> = ({
|
||||
if (textareaRef && textareaRef.current) {
|
||||
textareaRef.current.style.height = 'inherit';
|
||||
textareaRef.current.style.height = `${textareaRef.current?.scrollHeight}px`;
|
||||
textareaRef.current.style.overflow = `${textareaRef?.current?.scrollHeight > 400 ? 'auto' : 'hidden'
|
||||
}`;
|
||||
textareaRef.current.style.overflow = `${
|
||||
textareaRef?.current?.scrollHeight > 400 ? 'auto' : 'hidden'
|
||||
}`;
|
||||
}
|
||||
}, [content]);
|
||||
|
||||
@@ -257,15 +261,16 @@ export const ChatInput: FC<Props> = ({
|
||||
<div className="relative mx-2 flex w-full flex-grow flex-col rounded-md border border-black/10 bg-white shadow-[0_0_10px_rgba(0,0,0,0.10)] dark:border-gray-900/50 dark:bg-[#40414F] dark:text-white dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] sm:mx-4">
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
className="m-0 w-full resize-none border-0 bg-transparent p-0 pr-8 pl-2 text-black dark:bg-transparent dark:text-white py-2 md:py-3 md:pl-4"
|
||||
className="m-0 w-full resize-none border-0 bg-transparent p-0 py-2 pr-8 pl-2 text-black dark:bg-transparent dark:text-white md:py-3 md:pl-4"
|
||||
style={{
|
||||
resize: 'none',
|
||||
bottom: `${textareaRef?.current?.scrollHeight}px`,
|
||||
maxHeight: '400px',
|
||||
overflow: `${textareaRef.current && textareaRef.current.scrollHeight > 400
|
||||
? 'auto'
|
||||
: 'hidden'
|
||||
}`,
|
||||
overflow: `${
|
||||
textareaRef.current && textareaRef.current.scrollHeight > 400
|
||||
? 'auto'
|
||||
: 'hidden'
|
||||
}`,
|
||||
}}
|
||||
placeholder={
|
||||
t('Type a message or type "/" to select a prompt...') || ''
|
||||
@@ -278,7 +283,7 @@ export const ChatInput: FC<Props> = ({
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
<button
|
||||
className="absolute right-2 top-2 rounded-sm p-1 text-neutral-800 hover:bg-neutral-200 hover:text-neutral-900 dark:bg-opacity-50 dark:text-neutral-100 dark:hover:text-neutral-200 opacity-60"
|
||||
className="absolute right-2 top-2 rounded-sm p-1 text-neutral-800 opacity-60 hover:bg-neutral-200 hover:text-neutral-900 dark:bg-opacity-50 dark:text-neutral-100 dark:hover:text-neutral-200"
|
||||
onClick={handleSend}
|
||||
>
|
||||
<IconSend size={18} />
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import { OpenAIModel } from '@/types/openai';
|
||||
import { OpenAIModel, OpenAIModelID } from '@/types/openai';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { FC } from 'react';
|
||||
|
||||
interface Props {
|
||||
model: OpenAIModel;
|
||||
models: OpenAIModel[];
|
||||
defaultModelId: OpenAIModelID;
|
||||
onModelChange: (model: OpenAIModel) => void;
|
||||
}
|
||||
|
||||
export const ModelSelect: FC<Props> = ({ model, models, onModelChange }) => {
|
||||
export const ModelSelect: FC<Props> = ({
|
||||
model,
|
||||
models,
|
||||
defaultModelId,
|
||||
onModelChange,
|
||||
}) => {
|
||||
const { t } = useTranslation('chat');
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<label className="mb-2 text-left text-neutral-700 dark:text-neutral-400">
|
||||
@@ -19,7 +26,7 @@ export const ModelSelect: FC<Props> = ({ model, models, onModelChange }) => {
|
||||
<select
|
||||
className="w-full bg-transparent p-2"
|
||||
placeholder={t('Select a model') || ''}
|
||||
value={model.id}
|
||||
value={model?.id || defaultModelId}
|
||||
onChange={(e) => {
|
||||
onModelChange(
|
||||
models.find(
|
||||
@@ -34,7 +41,9 @@ export const ModelSelect: FC<Props> = ({ model, models, onModelChange }) => {
|
||||
value={model.id}
|
||||
className="dark:bg-[#343541] dark:text-white"
|
||||
>
|
||||
{model.name}
|
||||
{model.id === defaultModelId
|
||||
? `Default (${model.name})`
|
||||
: model.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
@@ -43,8 +43,7 @@ export const SystemPrompt: FC<Props> = ({
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const value = e.target.value;
|
||||
const maxLength =
|
||||
conversation.model.id === OpenAIModelID.GPT_3_5 ? 12000 : 24000;
|
||||
const maxLength = conversation.model.maxLength;
|
||||
|
||||
if (value.length > maxLength) {
|
||||
alert(
|
||||
|
||||
Reference in New Issue
Block a user