fix convo fr fr
This commit is contained in:
parent
981b96dc04
commit
24c1957fb9
2 changed files with 53 additions and 39 deletions
|
@ -1,40 +1,9 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import InputFrontend from './InputFrontend';
|
||||
import ConversationFrontend from './ConversationFrontend';
|
||||
import { Mistral } from '@mistralai/mistralai';
|
||||
|
||||
var messages = [
|
||||
'User: Hello!',
|
||||
'AI: Hi there!',
|
||||
'User: How are you?',
|
||||
'AI: I’m good, thank you!'
|
||||
];
|
||||
|
||||
async function prompt_mistral(model: string, prompt: string, system: string) {
|
||||
const apiKey = "m3kZRjN8DRSIo88r8Iti9hmKGWIklrLY";
|
||||
|
||||
const client = new Mistral({ apiKey: apiKey });
|
||||
|
||||
var chatResponse = await client.chat.complete({
|
||||
model: model,
|
||||
messages: [{ role: 'user', content: prompt }, { role: 'system', content: system, }],
|
||||
});
|
||||
|
||||
if (chatResponse && chatResponse.choices && chatResponse.choices.length > 0) {
|
||||
if (chatResponse.choices[0].message.content) {
|
||||
messages.push('AI: ' + chatResponse.choices[0].message.content);
|
||||
console.error('Error: Brain Not Found');
|
||||
console.log(messages)
|
||||
}
|
||||
} else {
|
||||
console.error('Error: Unexpected API response:', chatResponse);
|
||||
}
|
||||
}
|
||||
|
||||
const handleSendClick = (message: string) => {
|
||||
messages.push('User: ' + message);
|
||||
prompt_mistral("mistral-large-latest", message, "You are a helpful assistant.")
|
||||
};
|
||||
|
||||
const handleMicClick = () => {
|
||||
console.log('Mic clicked!');
|
||||
|
@ -57,7 +26,42 @@ const handleCopyClick = () => {
|
|||
// Handle copy action
|
||||
};
|
||||
|
||||
const InputBackend = () => {
|
||||
const InputBackend:React.FC = () => {
|
||||
async function prompt_mistral(model: string, prompt: string, system: string) {
|
||||
const apiKey = "m3kZRjN8DRSIo88r8Iti9hmKGWIklrLY";
|
||||
|
||||
const client = new Mistral({ apiKey: apiKey });
|
||||
|
||||
var chatResponse = await client.chat.complete({
|
||||
model: model,
|
||||
messages: [{ role: 'user', content: prompt }, { role: 'system', content: system, }],
|
||||
});
|
||||
|
||||
if (chatResponse && chatResponse.choices && chatResponse.choices.length > 0) {
|
||||
if (chatResponse.choices[0].message.content) {
|
||||
addMessage('AI: ' + chatResponse.choices[0].message.content);
|
||||
console.error('Error: Brain Not Found');
|
||||
console.log(messages)
|
||||
}
|
||||
} else {
|
||||
console.error('Error: Unexpected API response:', chatResponse);
|
||||
}
|
||||
}
|
||||
|
||||
const handleSendClick = (message: string) => {
|
||||
addMessage('User: ' + message);
|
||||
prompt_mistral("mistral-large-latest", message, "You are a helpful assistant.")
|
||||
};
|
||||
const [messages, setMessages] = useState([
|
||||
'User: Hello!',
|
||||
'AI: Hi there!',
|
||||
'User: How are you?',
|
||||
'AI: I’m good, thank you!'
|
||||
]);
|
||||
|
||||
const addMessage = (message: string) => {
|
||||
setMessages((prevMessages) => [...prevMessages, message]);
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<ConversationFrontend
|
||||
|
@ -65,12 +69,12 @@ const InputBackend = () => {
|
|||
onResendClick={handleResendClick}
|
||||
onEditClick={handleEditClick}
|
||||
onCopyClick={handleCopyClick}
|
||||
/>
|
||||
/>
|
||||
<InputFrontend
|
||||
message=""
|
||||
onSendClick={handleSendClick}
|
||||
onMicClick={handleMicClick}
|
||||
/>
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue