chat history.

This commit is contained in:
Patrick_Pluto 2024-09-18 16:16:53 +02:00
parent 74945cb18b
commit 30edc6e795

View file

@ -26,39 +26,44 @@ const handleCopyClick = () => {
// Handle copy action // Handle copy action
}; };
const InputBackend:React.FC = () => { const InputBackend: React.FC = () => {
async function prompt_mistral(model: string, prompt: string, system: string) { async function prompt_mistral(model: string, prompt: string, system: string) {
const apiKey = "m3kZRjN8DRSIo88r8Iti9hmKGWIklrLY"; const apiKey = "m3kZRjN8DRSIo88r8Iti9hmKGWIklrLY";
const client = new Mistral({ apiKey: apiKey }); const client = new Mistral({ apiKey: apiKey });
var chatResponse = await client.chat.complete({ var chatResponse = await client.chat.complete({
model: model, model: model,
messages: [{ role: 'user', content: prompt }, { role: 'system', content: system, }], messages: [{ role: 'user', content: prompt }, { role: 'system', content: system, }],
}); });
if (chatResponse && chatResponse.choices && chatResponse.choices.length > 0) { if (chatResponse && chatResponse.choices && chatResponse.choices.length > 0) {
if (chatResponse.choices[0].message.content) { if (chatResponse.choices[0].message.content) {
addMessage('AI: ' + chatResponse.choices[0].message.content); addMessage('AI: ' + chatResponse.choices[0].message.content);
console.error('Error: Brain Not Found');
console.log(messages) console.log(messages)
} }
} else { } else {
console.error('Error: Unexpected API response:', chatResponse); console.error('Error: Unexpected API response:', chatResponse);
} }
} }
const handleSendClick = (message: string) => { const handleSendClick = (message: string) => {
var system = "You are a helpful assistant. The following is the chat history."
for (let index = 0; index < messages.length; index++) {
system += messages[index] + " ";
};
addMessage('User: ' + message); addMessage('User: ' + message);
prompt_mistral("mistral-large-latest", message, "You are a helpful assistant.") prompt_mistral("mistral-large-latest", message, system)
}; };
const [messages, setMessages] = useState([ const [messages, setMessages] = useState([
'User: Hello!', 'User: Hello!',
'AI: Hi there!', 'AI: Hi there!',
'User: How are you?', 'User: How are you?',
'AI: Im good, thank you!' 'AI: Im good, thank you!'
]); ]);
const addMessage = (message: string) => { const addMessage = (message: string) => {
setMessages((prevMessages) => [...prevMessages, message]); setMessages((prevMessages) => [...prevMessages, message]);
}; };
@ -69,12 +74,12 @@ const InputBackend:React.FC = () => {
onResendClick={handleResendClick} onResendClick={handleResendClick}
onEditClick={handleEditClick} onEditClick={handleEditClick}
onCopyClick={handleCopyClick} onCopyClick={handleCopyClick}
/> />
<InputFrontend <InputFrontend
message="" message=""
onSendClick={handleSendClick} onSendClick={handleSendClick}
onMicClick={handleMicClick} onMicClick={handleMicClick}
/> />
</div> </div>
); );
}; };