优化了第二次对用户问题的提示词

This commit is contained in:
xxm
2025-12-05 09:12:44 +00:00
parent 8f52fad41c
commit 9cf81a1200
3 changed files with 13 additions and 7 deletions

Binary file not shown.

View File

@@ -239,18 +239,24 @@ def message(req: MessageReq):
class QueryFromMsgReq(BaseModel): class QueryFromMsgReq(BaseModel):
session_id: str session_id: str
message: str | None = None
@app.post("/query_from_message", tags=["opro"]) @app.post("/query_from_message", tags=["opro"])
def query_from_message(req: QueryFromMsgReq): def query_from_message(req: QueryFromMsgReq):
s = get_session(req.session_id) s = get_session(req.session_id)
if not s: if not s:
raise AppException(404, "session not found", "SESSION_NOT_FOUND") raise AppException(404, "session not found", "SESSION_NOT_FOUND")
last_user = None base = None
for m in reversed(s.get("chat_history", [])): if req.message:
if m.get("role") == "user" and m.get("content"): log_chat_message(req.session_id, "user", req.message)
last_user = m["content"] base = req.message
break else:
base = last_user or s["original_query"] for m in reversed(s.get("chat_history", [])):
if m.get("role") == "user" and m.get("content"):
base = m["content"]
break
base = base or s["original_query"]
cands = generate_candidates(base, s["history_candidates"], model_name=s.get("model_name")) cands = generate_candidates(base, s["history_candidates"], model_name=s.get("model_name"))
update_session_add_candidates(req.session_id, cands) update_session_add_candidates(req.session_id, cands)
return ok({"session_id": req.session_id, "round": s["round"], "candidates": cands}) return ok({"session_id": req.session_id, "round": s["round"], "candidates": cands})

View File

@@ -272,7 +272,7 @@
const candRes = await fetch(API_BASE + '/query_from_message', { const candRes = await fetch(API_BASE + '/query_from_message', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ session_id: currentSession }) body: JSON.stringify({ session_id: currentSession, message: msg })
}); });
const candData = await candRes.json(); const candData = await candRes.json();
const payload = candData && candData.data ? candData.data : {}; const payload = candData && candData.data ? candData.data : {};