Skip to content

Commit

Permalink
Various bug fixes around model/provider selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderwhy-er committed Nov 13, 2024
1 parent e55fb57 commit 9396734
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 12 additions & 3 deletions app/components/chat/BaseChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Menu } from '~/components/sidebar/Menu.client';
import { IconButton } from '~/components/ui/IconButton';
import { Workbench } from '~/components/workbench/Workbench.client';
import { classNames } from '~/utils/classNames';
import { MODEL_LIST, DEFAULT_PROVIDER, PROVIDER_LIST, ProviderInfo } from '~/utils/constants';
import { MODEL_LIST, DEFAULT_PROVIDER, PROVIDER_LIST, ProviderInfo, initializeModelList } from '~/utils/constants';
import { Messages } from './Messages.client';
import { SendButton } from './SendButton.client';
import { useState } from 'react';
Expand Down Expand Up @@ -45,8 +45,10 @@ const ModelSelector = ({ model, setModel, provider, setProvider, modelList, prov
))}
</select>
<select
key={provider?.name}
value={model}
onChange={(e) => setModel(e.target.value)}
style={{maxWidth: "70%"}}
className="flex-1 p-2 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus transition-all"
>
{[...modelList]
Expand Down Expand Up @@ -111,6 +113,8 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
console.log(provider);
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
const [apiKeys, setApiKeys] = useState<Record<string, string>>({});
const [modelList, setModelList] = useState(MODEL_LIST);


useEffect(() => {
// Load API keys from cookies on component mount
Expand All @@ -127,6 +131,10 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
// Clear invalid cookie data
Cookies.remove('apiKeys');
}

initializeModelList().then(modelList => {
setModelList(modelList);
});
}, []);

const updateApiKey = (provider: string, key: string) => {
Expand Down Expand Up @@ -190,12 +198,13 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
})}
>
<ModelSelector
key={provider?.name + ':' + modelList.length}
model={model}
setModel={setModel}
modelList={MODEL_LIST}
modelList={modelList}
provider={provider}
setProvider={setProvider}
providerList={providerList}
providerList={PROVIDER_LIST}
/>
{provider &&
<APIKeyManager
Expand Down
12 changes: 6 additions & 6 deletions app/components/chat/Chat.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useChatHistory } from '~/lib/persistence';
import { chatStore } from '~/lib/stores/chat';
import { workbenchStore } from '~/lib/stores/workbench';
import { fileModificationsToHTML } from '~/utils/diff';
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from '~/utils/constants';
import { DEFAULT_MODEL, DEFAULT_PROVIDER, PROVIDER_LIST, ProviderInfo } from '~/utils/constants';
import { cubicEasingFn } from '~/utils/easings';
import { createScopedLogger, renderLogger } from '~/utils/logger';
import { BaseChat } from './BaseChat';
Expand Down Expand Up @@ -80,7 +80,7 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
});
const [provider, setProvider] = useState(() => {
const savedProvider = Cookies.get('selectedProvider');
return savedProvider || DEFAULT_PROVIDER;
return PROVIDER_LIST.find(p => p.name === savedProvider) || DEFAULT_PROVIDER;
});

const { showChat } = useStore(chatStore);
Expand All @@ -96,7 +96,7 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
},
onError: (error) => {
logger.error('Request failed\n\n', error);
toast.error('There was an error processing your request');
toast.error('There was an error processing your request: ' + (error.message ? error.message : "No details were returned"));
},
onFinish: () => {
logger.debug('Finished streaming');
Expand Down Expand Up @@ -227,9 +227,9 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
Cookies.set('selectedModel', newModel, { expires: 30 });
};

const handleProviderChange = (newProvider: string) => {
const handleProviderChange = (newProvider: ProviderInfo) => {
setProvider(newProvider);
Cookies.set('selectedProvider', newProvider, { expires: 30 });
Cookies.set('selectedProvider', newProvider.name, { expires: 30 });
};

return (
Expand Down Expand Up @@ -263,7 +263,7 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
})}
enhancePrompt={() => {
enhancePrompt(
input,
input,
(input) => {
setInput(input);
scrollTextArea();
Expand Down

0 comments on commit 9396734

Please sign in to comment.