From 8500091478560cbcdfa1c5c90674a5f22103d4e0 Mon Sep 17 00:00:00 2001 From: Yee Kit Date: Sat, 27 Jan 2024 00:50:08 +0800 Subject: [PATCH] Fix: query api not working --- backend/backend/app/api/routers/query.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/backend/app/api/routers/query.py b/backend/backend/app/api/routers/query.py index 57e1b69..a00e7bf 100644 --- a/backend/backend/app/api/routers/query.py +++ b/backend/backend/app/api/routers/query.py @@ -28,8 +28,8 @@ class _ChatData(BaseModel): messages: List[_Message] -@r.get("") -async def search( +@r.post("") +async def query( request: Request, # Note: To support clients sending a JSON object using content-type "text/plain", # we need to use Depends(json_to_model(_ChatData)) here @@ -42,18 +42,18 @@ async def search( status_code=status.HTTP_400_BAD_REQUEST, detail="No query provided", ) - query = data.messages.pop() - if query.role != MessageRole.USER: + lastMessage = data.messages.pop() + if lastMessage.role != MessageRole.USER: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Last message must be from user", ) logger = logging.getLogger("uvicorn") - logger.info(f"Query: {query}") + logger.info(f"Query: {lastMessage}") # Query index - query_engine = index.as_query_engine(streaming=True, similarity_top_k=1) - response = query_engine.query(query) + query_engine = index.as_query_engine(streaming=True, similarity_top_k=5) + response = query_engine.query(lastMessage.content) # stream response async def event_generator():