Skip to content

Commit

Permalink
refine the lamp output
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHuSh committed Oct 11, 2024
1 parent 5e7c1fb commit 9c8fa2a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/db/services/dialog_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def chat(dialog, messages, stream=True, **kwargs):
questions = [full_question(dialog.tenant_id, dialog.llm_id, messages)]
else:
questions = questions[-1:]
refineQ_tm = timer()

rerank_mdl = None
if dialog.rerank_id:
Expand Down Expand Up @@ -197,7 +198,7 @@ def chat(dialog, messages, stream=True, **kwargs):
max_tokens - used_token_count)

def decorate_answer(answer):
nonlocal prompt_config, knowledges, kwargs, kbinfos, prompt, retrieval_tm
nonlocal prompt_config, knowledges, kwargs, kbinfos, prompt, retrieval_tm, refineQ_tm
refs = []
if knowledges and (prompt_config.get("quote", True) and kwargs.get("quote", True)):
answer, idx = retr.insert_citations(answer,
Expand All @@ -222,7 +223,8 @@ def decorate_answer(answer):
if answer.lower().find("invalid key") >= 0 or answer.lower().find("invalid api") >= 0:
answer += " Please set LLM API-Key in 'User Setting -> Model Providers -> API-Key'"
done_tm = timer()
prompt += "\n\n### Elapsed\n - Retrieval: %.1f ms\n - LLM: %.1f ms"%((retrieval_tm-st)*1000, (done_tm-st)*1000)
prompt += "\n\n### Elapsed\n - Refine Question: %.1f ms\n - Retrieval: %.1f ms\n - LLM: %.1f ms" % (
(refineQ_tm - st) * 1000, (retrieval_tm - refineQ_tm) * 1000, (done_tm - retrieval_tm) * 1000)
return {"answer": answer, "reference": refs, "prompt": prompt}

if stream:
Expand Down

0 comments on commit 9c8fa2a

Please sign in to comment.