From 27217a330def9e7066a53c05e2b01d628cc4996a Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Mar 2023 20:39:41 +0700 Subject: [PATCH] Time chat API sub-components for performance analysis Time and the search query extraction, search and response generation components --- src/khoj/routers/api.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index c6bb8dee..c0274cba 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -207,16 +207,19 @@ def chat(q: Optional[str] = None): return {"status": "ok", "response": []} # Infer search queries from user message - inferred_queries = extract_questions(q, model=model, api_key=api_key, conversation_log=meta_log) + with timer("Extracting search queries took", logger): + inferred_queries = extract_questions(q, model=model, api_key=api_key, conversation_log=meta_log) # Collate search results as context for GPT - result_list = [] - for query in inferred_queries: - result_list.extend(search(query, n=5, r=True, score_threshold=-5.0, dedupe=False)) - collated_result = "\n\n".join({f"# {item.additional['compiled']}" for item in result_list}) + with timer("Searching knowledge base took", logger): + result_list = [] + for query in inferred_queries: + result_list.extend(search(query, n=5, r=True, score_threshold=-5.0, dedupe=False)) + collated_result = "\n\n".join({f"# {item.additional['compiled']}" for item in result_list}) try: - gpt_response = converse(collated_result, q, meta_log, api_key=api_key) + with timer("Generating chat response took", logger): + gpt_response = converse(collated_result, q, meta_log, api_key=api_key) status = "ok" except Exception as e: gpt_response = str(e)