Perplexica/ui/lib/actions.ts

34 lines
921 B
TypeScript
Raw Normal View History

2024-05-18 13:10:39 +05:30
import { Message } from '@/components/ChatWindow';
import { Settings } from '@/types/Settings';
2024-05-18 13:10:39 +05:30
export const getSuggestions = async (chatHistory: Message[]) => {
2024-05-18 13:10:39 +05:30
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: chatHistory,
2024-05-18 13:10:39 +05:30
chat_model: chatModel,
chat_model_provider: chatModelProvider,
}),
});
const data = (await res.json()) as { suggestions: string[] };
return data.suggestions;
};
export async function getConfig() {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/config`, {
headers: {
'Content-Type': 'application/json',
},
});
return (await res.json()) as Settings;
}