feat(image-search): handle chat history

This commit is contained in:
ItzCrazyKns 2024-04-28 11:15:28 +05:30
parent f14050840b
commit 5df3c5ad8c
No known key found for this signature in database
GPG key ID: 8162927C7CCE3065
4 changed files with 24 additions and 5 deletions

View file

@ -3,12 +3,21 @@ import handleImageSearch from '../agents/imageSearchAgent';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { getAvailableProviders } from '../lib/providers';
import { getChatModel, getChatModelProvider } from '../config';
import { HumanMessage, AIMessage } from '@langchain/core/messages';
const router = express.Router();
router.post('/', async (req, res) => {
try {
const { query, chat_history } = req.body;
let { query, chat_history } = req.body;
chat_history = chat_history.map((msg: any) => {
if (msg.role === 'user') {
return new HumanMessage(msg.content);
} else if (msg.role === 'assistant') {
return new AIMessage(msg.content);
}
});
const models = await getAvailableProviders();
const provider = getChatModelProvider();