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