2024-04-09 16:21:05 +05:30
|
|
|
import express from 'express';
|
2024-04-20 09:32:19 +05:30
|
|
|
import handleImageSearch from '../agents/imageSearchAgent';
|
|
|
|
|
import { ChatOpenAI } from '@langchain/openai';
|
|
|
|
|
import { getOpenaiApiKey } from '../config';
|
2024-04-09 16:21:05 +05:30
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
router.post('/', async (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const { query, chat_history } = req.body;
|
|
|
|
|
|
2024-04-20 09:32:19 +05:30
|
|
|
const llm = new ChatOpenAI({
|
|
|
|
|
temperature: 0.7,
|
|
|
|
|
openAIApiKey: getOpenaiApiKey(),
|
2024-04-09 16:21:05 +05:30
|
|
|
});
|
|
|
|
|
|
2024-04-20 09:32:19 +05:30
|
|
|
const images = await handleImageSearch({ query, chat_history }, llm);
|
|
|
|
|
|
2024-04-09 16:21:05 +05:30
|
|
|
res.status(200).json({ images });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
res.status(500).json({ message: 'An error has occurred.' });
|
|
|
|
|
console.log(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|