UPDATED cache in suggestions
This commit is contained in:
parent
dcb7c54800
commit
7a887f59bc
5 changed files with 70 additions and 21 deletions
|
@ -1,22 +1,31 @@
|
|||
import { Message } from '@/components/ChatWindow';
|
||||
|
||||
export const getSuggestions = async (chatHisory: Message[]) => {
|
||||
const chatModel = localStorage.getItem('chatModel');
|
||||
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
||||
export const getSuggestions = async (chatHistory: Message[]) => {
|
||||
try {
|
||||
const chatModel = localStorage.getItem('chatModel');
|
||||
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
||||
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
chat_history: chatHisory,
|
||||
chat_model: chatModel,
|
||||
chat_model_provider: chatModelProvider,
|
||||
}),
|
||||
});
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
chat_history: chatHistory,
|
||||
chat_model: chatModel,
|
||||
chat_model_provider: chatModelProvider,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = (await res.json()) as { suggestions: string[] };
|
||||
if (!res.ok) {
|
||||
throw new Error(`Error: ${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
||||
return data.suggestions;
|
||||
const data = (await res.json()) as { suggestions: string[] };
|
||||
|
||||
return data.suggestions;
|
||||
} catch (error) {
|
||||
console.error('Error fetching suggestions:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue