feat: Enhance query processing with logging and recursion limit configuration
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -18,6 +20,7 @@ from sqlalchemy.orm import selectinload
|
||||
|
||||
from services.compatibility_score import calculate_project_investor_compatibility
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
# Connect to SQLite
|
||||
prompt_template = hub.pull("langchain-ai/sql-agent-system-prompt")
|
||||
db = SQLDatabase.from_uri(DATABASE_URL)
|
||||
@@ -58,15 +61,15 @@ class QueryProcessor:
|
||||
# Let the LLM handle all database interactions and filtering to get fund IDs
|
||||
response = self.agent.invoke(
|
||||
{"messages": [("user", question)]},
|
||||
config={"recursion_limit": 50},
|
||||
)
|
||||
|
||||
# Extract the actual message content
|
||||
ai_response = (
|
||||
response["messages"][-1].content if response.get("messages") else ""
|
||||
)
|
||||
|
||||
logger.info(f"{response}")
|
||||
final_message_content = response["messages"][-1].content
|
||||
logger.info(f"AI Response: \n{final_message_content}")
|
||||
# Extract fund IDs from the AI response
|
||||
fund_ids = self._extract_fund_ids_from_response(ai_response)
|
||||
fund_ids = self._extract_fund_ids_from_response(final_message_content)
|
||||
|
||||
# Fetch full fund data with investor relationships using the IDs
|
||||
return self._fetch_funds_by_ids(fund_ids, project_id)
|
||||
|
||||
Reference in New Issue
Block a user