made querying async
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
@@ -126,14 +127,19 @@ Return ONLY the SQL query, no explanations or markdown.""",
|
||||
"""Generate cache key from normalized question."""
|
||||
return hashlib.md5(question.lower().strip().encode()).hexdigest()
|
||||
|
||||
def process_query(
|
||||
async def process_query(
|
||||
self, question: str, project_id: Optional[int] = None
|
||||
) -> PaginatedResponse[InvestmentResponse]:
|
||||
"""Process a query by generating and executing SQL directly.
|
||||
"""Async wrapper for process_query. Runs blocking work in a thread to avoid
|
||||
blocking the event loop.
|
||||
"""
|
||||
return await asyncio.to_thread(self._process_query_sync, question, project_id)
|
||||
|
||||
Args:
|
||||
question: The natural language query to process
|
||||
project_id: Optional project ID for compatibility scoring
|
||||
def _process_query_sync(
|
||||
self, question: str, project_id: Optional[int] = None
|
||||
) -> PaginatedResponse[InvestmentResponse]:
|
||||
"""Synchronous implementation of process_query. This is run in a thread by
|
||||
the async wrapper above.
|
||||
"""
|
||||
cache_key = self._get_cache_key(question)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user