Skip to content

Commit

Permalink
Fix: query api not working
Browse files Browse the repository at this point in the history
  • Loading branch information
xKhronoz committed Jan 26, 2024
1 parent 82d0321 commit 8500091
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions backend/backend/app/api/routers/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit 8500091

Please sign in to comment.