2024-05-18 07:40:39 +00:00
|
|
|
import { Message } from '@/components/ChatWindow';
|
|
|
|
|
|
|
|
export const getSuggestions = async (chatHisory: Message[]) => {
|
|
|
|
const chatModel = localStorage.getItem('chatModel');
|
|
|
|
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
|
|
|
|
2024-10-30 04:58:31 +00:00
|
|
|
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
|
|
|
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
|
|
|
|
2024-05-18 07:40:39 +00:00
|
|
|
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2024-10-30 04:58:31 +00:00
|
|
|
chatHistory: chatHisory,
|
|
|
|
chatModel: {
|
|
|
|
provider: chatModelProvider,
|
|
|
|
model: chatModel,
|
|
|
|
...(chatModelProvider === 'custom_openai' && {
|
|
|
|
customOpenAIKey,
|
|
|
|
customOpenAIBaseURL,
|
|
|
|
}),
|
|
|
|
},
|
2024-05-18 07:40:39 +00:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = (await res.json()) as { suggestions: string[] };
|
|
|
|
|
|
|
|
return data.suggestions;
|
|
|
|
};
|