mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-17 17:18:14 +00:00
39 lines
937 B
TypeScript
39 lines
937 B
TypeScript
import searchImages from '@/lib/agents/media/image';
|
|
import ModelRegistry from '@/lib/models/registry';
|
|
import { ModelWithProvider } from '@/lib/models/types';
|
|
|
|
interface ImageSearchBody {
|
|
query: string;
|
|
chatHistory: any[];
|
|
chatModel: ModelWithProvider;
|
|
}
|
|
|
|
export const POST = async (req: Request) => {
|
|
try {
|
|
const body: ImageSearchBody = await req.json();
|
|
|
|
const registry = new ModelRegistry();
|
|
|
|
const llm = await registry.loadChatModel(
|
|
body.chatModel.providerId,
|
|
body.chatModel.key,
|
|
);
|
|
|
|
const images = await searchImages(
|
|
{
|
|
chatHistory: body.chatHistory,
|
|
query: body.query,
|
|
},
|
|
llm,
|
|
);
|
|
|
|
return Response.json({ images }, { status: 200 });
|
|
} catch (err) {
|
|
console.error(`An error occurred while searching images: ${err}`);
|
|
return Response.json(
|
|
{ message: 'An error occurred while searching images' },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
};
|