mirror of
				https://github.com/ItzCrazyKns/Perplexica.git
				synced 2025-11-03 20:28:14 +00:00 
			
		
		
		
	feat(image-search): handle chat history
This commit is contained in:
		@@ -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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user