main
zc 2 months ago
parent 282f515b6f
commit 12517293ed
  1. 4
      app/api/chat/ai/chat_router.py
  2. 10
      app/api/chat/ai/chat_service.py

@ -100,7 +100,7 @@ async def h5_chat_stream(request: Request, inp: ChatIn):
knowledge = await knowledge_task
#如果知识库返回的内容不包含"知识库内未找到相应资源"则拼接字符串
if knowledge and "知识库内未找到相应资源" not in knowledge:
data += "知识库查询到的景区内容:"+ knowledge
data += "\n\n知识库查询到的景区内容:"+ knowledge
async for chunk in gen_markdown_stream(inp.message, data, inp.language, conversation_history):
yield chunk
else:
@ -108,7 +108,7 @@ async def h5_chat_stream(request: Request, inp: ChatIn):
if spot:
knowledge = await knowledge_task
if knowledge and "知识库内未找到相应资源" not in knowledge:
inp.message += "知识库查询到的景区内容:"+ knowledge
inp.message += "\n\n知识库查询到的景区内容:"+ knowledge
async for chunk in ai_chat_stream(inp, conversation_history):
yield chunk

@ -342,7 +342,7 @@ async def query_flow(request: Request, spot: str) -> str:
return f"**未找到景区【{spot}】的信息,请检查名称是否正确。\n\n(内容仅供参考)"
result = ""
if row and scenic_id and all(v is not None for v in row):
if row and all(v is not None for v in row):
# 使用变量名访问客流数据
in_num, capacity = row
#in_num/capacity 计算承载率,取两位小数
@ -353,9 +353,7 @@ async def query_flow(request: Request, spot: str) -> str:
0.7-0.9较拥挤
大于0.9拥挤"""
hold_level = "舒适" if hold_rate < 0.3 else "较舒适" if hold_rate < 0.5 else "一般" if hold_rate < 0.7 else "较拥挤" if hold_rate < 0.9 else "拥挤"
result = f"{spot} 客流\n\n在园人数: {in_num}\n\n舒适度等级:{hold_level}\n\n注:全部内容输出完以后,最后输出一段固定内容,内容为:<hr class=\"keliu\" data-id=\"{scenic_id}\"/>;"
elif scenic_id:
result = f"未找到景区【{spot}】的客流相关信息;注:全部内容输出完以后,最后输出一段固定内容,内容为:<hr class=\"keliu\" data-id=\"{scenic_id}\"/>;"
result = f"{spot} 客流\n\n在园人数: {in_num}\n\n舒适度等级:{hold_level}"
else:
result = f"未找到景区【{spot}】的客流相关信息"
if park_rows:
@ -365,6 +363,10 @@ async def query_flow(request: Request, spot: str) -> str:
result += f"停车场名称:{park_name} ,距离:{distance_value}米,空余车位:{space},总车位:{total_count},收费标准:{rate_info}"
else:
result += "停车场信息:暂无数据。"
if scenic_id:
result += f"注:全部内容输出完以后,最后输出一段固定内容,内容为:<hr class=\"keliu\" data-id=\"{scenic_id}\"/>;"
try:
await redis_client.setex(cache_key, 120, result)
except Exception as e:

Loading…
Cancel
Save