mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
🔗 [feat] Integrate model selection with chat functionality
- Add selectedModel state and pass it to ChatImpl component - Update useChat hook to include selectedModel in API request body - Refactor message appending logic to include selectedModel
This commit is contained in:
parent
bd2cab8a9d
commit
b25000924c
@ -27,7 +27,12 @@ export function Chat() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{ready && <ChatImpl initialMessages={initialMessages} storeMessageHistory={storeMessageHistory} />}
|
{ready && (
|
||||||
|
<ChatImpl
|
||||||
|
initialMessages={initialMessages}
|
||||||
|
storeMessageHistory={storeMessageHistory}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<ToastContainer
|
<ToastContainer
|
||||||
closeButton={({ closeToast }) => {
|
closeButton={({ closeToast }) => {
|
||||||
return (
|
return (
|
||||||
@ -75,6 +80,8 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
|
|||||||
|
|
||||||
const [animationScope, animate] = useAnimate();
|
const [animationScope, animate] = useAnimate();
|
||||||
|
|
||||||
|
const [selectedModel, setSelectedModel] = useState('claude');
|
||||||
|
|
||||||
const { messages, isLoading, input, handleInputChange, setInput, stop, append } = useChat({
|
const { messages, isLoading, input, handleInputChange, setInput, stop, append } = useChat({
|
||||||
api: '/api/chat',
|
api: '/api/chat',
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
@ -85,6 +92,9 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
|
|||||||
logger.debug('Finished streaming');
|
logger.debug('Finished streaming');
|
||||||
},
|
},
|
||||||
initialMessages,
|
initialMessages,
|
||||||
|
body: {
|
||||||
|
selectedModel: selectedModel,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
|
const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer();
|
||||||
@ -153,13 +163,6 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @note (delm) Usually saving files shouldn't take long but it may take longer if there
|
|
||||||
* many unsaved files. In that case we need to block user input and show an indicator
|
|
||||||
* of some kind so the user is aware that something is happening. But I consider the
|
|
||||||
* happy case to be no unsaved files and I would expect users to save their changes
|
|
||||||
* before they send another message.
|
|
||||||
*/
|
|
||||||
await workbenchStore.saveAllFiles();
|
await workbenchStore.saveAllFiles();
|
||||||
|
|
||||||
const fileModifications = workbenchStore.getFileModifcations();
|
const fileModifications = workbenchStore.getFileModifcations();
|
||||||
@ -171,22 +174,25 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
|
|||||||
if (fileModifications !== undefined) {
|
if (fileModifications !== undefined) {
|
||||||
const diff = fileModificationsToHTML(fileModifications);
|
const diff = fileModificationsToHTML(fileModifications);
|
||||||
|
|
||||||
/**
|
append(
|
||||||
* If we have file modifications we append a new user message manually since we have to prefix
|
{ role: 'user', content: `${diff}\n\n${_input}` },
|
||||||
* the user input with the file modifications and we don't want the new user input to appear
|
{
|
||||||
* in the prompt. Using `append` is almost the same as `handleSubmit` except that we have to
|
body: {
|
||||||
* manually reset the input and we'd have to manually pass in file attachments. However, those
|
selectedModel: selectedModel,
|
||||||
* aren't relevant here.
|
},
|
||||||
*/
|
}
|
||||||
append({ role: 'user', content: `${diff}\n\n${_input}` });
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* After sending a new message we reset all modifications since the model
|
|
||||||
* should now be aware of all the changes.
|
|
||||||
*/
|
|
||||||
workbenchStore.resetAllFileModifications();
|
workbenchStore.resetAllFileModifications();
|
||||||
} else {
|
} else {
|
||||||
append({ role: 'user', content: _input });
|
append(
|
||||||
|
{ role: 'user', content: _input },
|
||||||
|
{
|
||||||
|
body: {
|
||||||
|
selectedModel: selectedModel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInput('');
|
setInput('');
|
||||||
@ -229,6 +235,8 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp
|
|||||||
scrollTextArea();
|
scrollTextArea();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
selectedModel={selectedModel}
|
||||||
|
setSelectedModel={setSelectedModel}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user