feat:修复投顾agent功能
This commit is contained in:
@@ -13,6 +13,7 @@ from config.settings import settings
|
||||
from nl2sql.contracts import DataQueryRequest, DataQueryResult
|
||||
from nl2sql.embedding import EmbeddingError
|
||||
from nl2sql.retrieval import retrieve_metadata
|
||||
from nl2sql.cache import cache_get, cache_set, build_question_cache_key
|
||||
from nl2sql.runtime_config import runtime_config
|
||||
from nl2sql.schema import load_authoritative_schema
|
||||
from repositories.customer_relation import CustomerRelationRepo
|
||||
@@ -154,6 +155,7 @@ async def execute_advisor_data_query(
|
||||
pass
|
||||
|
||||
if scope == "customer" and _is_current_holdings_query(question):
|
||||
redis = redis or database.redis.client()
|
||||
return await _query_current_holdings(
|
||||
db,
|
||||
customer_id=customer_id,
|
||||
@@ -166,6 +168,21 @@ async def execute_advisor_data_query(
|
||||
|
||||
milvus = milvus or database.milvus.client()
|
||||
redis = redis or database.redis.client()
|
||||
cache_key = build_question_cache_key(
|
||||
question,
|
||||
permission=permission,
|
||||
data_scope={"customer_ids": customer_ids},
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
)
|
||||
cached = await cache_get(redis, cache_key)
|
||||
if cached is not None:
|
||||
cached["trace_id"] = trace_id
|
||||
cached["customer_id"] = customer_id
|
||||
cached["warnings"] = [*cached.get("warnings", []), "cache_hit"]
|
||||
return cached
|
||||
llm_client = llm_client or default_llm
|
||||
request = DataQueryRequest(
|
||||
question=question,
|
||||
@@ -222,4 +239,5 @@ async def execute_advisor_data_query(
|
||||
payload["answer"] = f"{existing_answer.rstrip('。')}。客户姓名:{enriched['name_summary']}。"
|
||||
payload["sql"] = None
|
||||
payload["customer_id"] = customer_id
|
||||
await cache_set(redis, cache_key, payload, ttl=runtime_config.cache_ttl)
|
||||
return payload
|
||||
|
||||
Reference in New Issue
Block a user