mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-23 20:18:15 +00:00
37 lines
949 B
TypeScript
37 lines
949 B
TypeScript
import generateSuggestions from '@/lib/agents/suggestions';
|
|
import ModelRegistry from '@/lib/models/registry';
|
|
import { ModelWithProvider } from '@/lib/models/types';
|
|
|
|
interface SuggestionsGenerationBody {
|
|
chatHistory: any[];
|
|
chatModel: ModelWithProvider;
|
|
}
|
|
|
|
export const POST = async (req: Request) => {
|
|
try {
|
|
const body: SuggestionsGenerationBody = await req.json();
|
|
|
|
const registry = new ModelRegistry();
|
|
|
|
const llm = await registry.loadChatModel(
|
|
body.chatModel.providerId,
|
|
body.chatModel.key,
|
|
);
|
|
|
|
const suggestions = await generateSuggestions(
|
|
{
|
|
chatHistory: body.chatHistory,
|
|
},
|
|
llm,
|
|
);
|
|
|
|
return Response.json({ suggestions }, { status: 200 });
|
|
} catch (err) {
|
|
console.error(`An error occurred while generating suggestions: ${err}`);
|
|
return Response.json(
|
|
{ message: 'An error occurred while generating suggestions' },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
};
|