From 52042bc12978e0e44f5d4fc743ae4526a1a27d05 Mon Sep 17 00:00:00 2001 From: SubhadityaMukherjee Date: Fri, 23 Aug 2024 12:36:47 +0200 Subject: [PATCH] better chat interface, added answer generation bot and fixed previously mysteriously deleted files --- backend/config.json | 2 +- structured_query/chroma_store_utilis.py | 2 +- .../llm_service_structured_query.py | 26 ++++++++++++++----- .../llm_service_structured_query_utils.py | 2 +- structured_query/structuring_query.py | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/backend/config.json b/backend/config.json index f587538..ce8cb54 100644 --- a/backend/config.json +++ b/backend/config.json @@ -17,7 +17,7 @@ "search_type" : "similarity", "reranking" : false, "long_context_reorder" : false, - "structured_query": false, + "structured_query": true, "use_chroma_for_saving_metadata": false, "chunk_size": 1000, "chroma_metadata_dir": "../data/chroma_db_metadata" diff --git a/structured_query/chroma_store_utilis.py b/structured_query/chroma_store_utilis.py index fa75044..9765153 100644 --- a/structured_query/chroma_store_utilis.py +++ b/structured_query/chroma_store_utilis.py @@ -44,4 +44,4 @@ def load_chroma_metadata(): if collec.get(ids=ids) == []: collec.add(ids=ids, documents=documents, metadatas=metadatas) - return collec + return collec \ No newline at end of file diff --git a/structured_query/llm_service_structured_query.py b/structured_query/llm_service_structured_query.py index fb801ac..f44c40e 100644 --- a/structured_query/llm_service_structured_query.py +++ b/structured_query/llm_service_structured_query.py @@ -17,7 +17,17 @@ app = FastAPI() -print("[INFO] Starting structured query service.") +try: + print("[INFO] Sending first query to structured query llm to avoid cold start.") + + query = "mushroom data with 2 classess" + response = chain.invoke({"query": query}) + obj = ChromaTranslator() + filter_condition = obj.visit_structured_query(structured_query=response)[1] + print(response, filter_condition) + +except Exception as e: + print("Error in first query: ", e) # Create port @@ -33,10 +43,14 @@ async def get_structured_query(query: str): query = query.replace("%20", " ") response = chain.invoke({"query": query}) print(response) - # obj = ChromaTranslator() - # filter_condition = obj.visit_structured_query(structured_query=response)[1] - return JSONResponse(content=str(response)) + obj = ChromaTranslator() + filter_condition = obj.visit_structured_query(structured_query=response)[1] except Exception as e: - print(f"An error occurred: {e}") - raise HTTPException(status_code=500, detail=f"An error occurred: {e}") + print(f"An error occurred: ", HTTPException(status_code=500, detail=f"An error occurred: {e}")) + + return response, filter_condition + + + + \ No newline at end of file diff --git a/structured_query/llm_service_structured_query_utils.py b/structured_query/llm_service_structured_query_utils.py index c04382f..88a43f3 100644 --- a/structured_query/llm_service_structured_query_utils.py +++ b/structured_query/llm_service_structured_query_utils.py @@ -42,4 +42,4 @@ def create_query_structuring_chain( fix_invalid=True, ) - return chain + return chain \ No newline at end of file diff --git a/structured_query/structuring_query.py b/structured_query/structuring_query.py index b70835c..c667d28 100644 --- a/structured_query/structuring_query.py +++ b/structured_query/structuring_query.py @@ -45,4 +45,4 @@ def structuring_query(query: str): structured_query = chain.invoke(query) - return structured_query.query, structured_query.filter + return structured_query.query, structured_query.filter \ No newline at end of file