增加了调试信息
This commit is contained in:
parent
86c7f5d182
commit
44630f04d3
@ -214,8 +214,9 @@ async def converse_with_chat_assistant(
|
||||
|
||||
# 检查是否应该使用搜索服务 (Router Strategy)
|
||||
# Using 'glm-4-flash' to classify intent: SEARCH vs RAG
|
||||
t0 = time.perf_counter()
|
||||
intent = await SearchService.classify_intent(converse_params.question)
|
||||
logger.info(f"Intent Router ({converse_params.chat_id}): {intent} | Query: {converse_params.question}")
|
||||
logger.info(f"[RAG_PROFILE] Intent Router ({converse_params.chat_id}): {intent} | Time: {time.perf_counter() - t0:.3f}s | Query: {converse_params.question}")
|
||||
|
||||
if intent == 'SEARCH':
|
||||
return await SearchService.handle_search_chat(converse_params, redis)
|
||||
@ -228,7 +229,9 @@ async def converse_with_chat_assistant(
|
||||
return ResponseUtil.success(json.loads(cached))
|
||||
|
||||
# Revert to Native RAGFlow Service (OpenAI endpoint failed with Auth error)
|
||||
t1 = time.perf_counter()
|
||||
result = await RAGFlowService.converse_with_chat_assistant_services(converse_params)
|
||||
logger.info(f"[RAG_PROFILE] RAG Init/Connect ({converse_params.chat_id}): {time.perf_counter() - t1:.3f}s")
|
||||
|
||||
if converse_params.stream:
|
||||
async def stream_response():
|
||||
@ -241,7 +244,7 @@ async def converse_with_chat_assistant(
|
||||
if not first_token_received:
|
||||
first_token_received = True
|
||||
latency = time.perf_counter() - start_stream_time
|
||||
logger.info(f"RAGFlow Stream Start Latency: {latency:.3f}s")
|
||||
logger.info(f"[RAG_PROFILE] Time to First Token ({converse_params.chat_id}): {latency:.3f}s")
|
||||
|
||||
# Native RAGFlow returns cumulative text in 'answer' field
|
||||
# Chunk structure: {'data': {'answer': 'Cumulative Text...'}}
|
||||
@ -273,17 +276,18 @@ async def converse_with_chat_assistant(
|
||||
|
||||
yield format_sse({'status': 'completed'}, event='end')
|
||||
except Exception as exc:
|
||||
logger.exception('ragflow流式对话异常: %s', exc)
|
||||
logger.exception('[RAG_PROFILE] ragflow流式对话异常: %s', exc)
|
||||
yield format_sse({'message': str(exc)}, event='error')
|
||||
finally:
|
||||
logger.info('ragflow流式对话耗时 %.3fs', time.perf_counter() - start_time)
|
||||
total_time = time.perf_counter() - start_time
|
||||
logger.info(f'[RAG_PROFILE] Total Stream Duration ({converse_params.chat_id}): {total_time:.3f}s')
|
||||
|
||||
return StreamingResponse(stream_response(), media_type='text/event-stream')
|
||||
|
||||
response = parse_result(result)
|
||||
if redis and cache_key and isinstance(result, dict) and result.get('code') == 0:
|
||||
await redis.set(cache_key, json.dumps(result.get('data'), ensure_ascii=False), ex=60)
|
||||
logger.info('ragflow对话耗时 %.3fs', time.perf_counter() - start_time)
|
||||
logger.info(f'[RAG_PROFILE] Total Sync Duration ({converse_params.chat_id}): {time.perf_counter() - start_time:.3f}s')
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user