Skip to content

Commit

Permalink
Add more log info and error
Browse files Browse the repository at this point in the history
  • Loading branch information
wwxxzz committed Nov 27, 2024
1 parent dc3d1a0 commit 15e4eb0
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/pai_rag/app/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,33 @@ async def aquery_analysis(query: RagQuery):
)


@router.post("/query/custom_test")
@router.post("/query/custom_search")
async def aquery_custom_test(query: RagQuery):
response = await rag_service.aquery_llm(query)
answer = json.loads(response.answer)
input_list = [res["型号"] for res in answer]
unique_input_list = list(set(input_list))
# TODO
response = await rag_service.aquery_analysis(unique_input_list)
if not query.stream:
return response
else:
return StreamingResponse(
response,
media_type="text/event-stream",
)
try:
response = await rag_service.aquery_llm(query)

try:
answer = json.loads(response.answer)
except json.JSONDecodeError as e:
logger.error(f"Error decoding JSON: {e}")
return "Parsing Error: The LLM response is not a valid JSON format."

This comment has been minimized.

Copy link
@moria97

moria97 Nov 27, 2024

Collaborator

这个api是直接return raw string吗?我建议返回一个统一的json格式,便于下游解析

This comment has been minimized.

Copy link
@wwxxzz

wwxxzz Nov 27, 2024

Author Collaborator

Fixed.


input_list = [res.get("型号") for res in answer if "型号" in res]
logger.info(f"Extracted input list: {input_list}")
if not input_list:
logger.warning("No model information found in response.")
return "Parsing Error: The '型号' key is not found in the JSON."

unique_input_list = list(set(input_list))
logger.info(f"Unique input list: {unique_input_list}")
# TODO
try:
sql_response = await rag_service.aquery_analysis(unique_input_list)
return sql_response
except Exception as e:
logger.error(f"SQL query failed: {e}")
return "SQL query failed: No information found for the relevant input list."

except Exception as e:
logger.error(f"Unexpected error: {e}")
return "Unexpected error, please try again later."

0 comments on commit 15e4eb0

Please sign in to comment.