Skip to content

Commit

Permalink
Merge pull request #16 from curieo-org/caching
Browse files Browse the repository at this point in the history
Search Query Endpoint Change and Bug Fixing
  • Loading branch information
raahulrahl authored Mar 20, 2024
2 parents 5f2a1d9 + 8f38d8f commit 65f7f5a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Steps and commands for running the app are to be included here
- Example API for Top 10 Search:
```
curl --location 'http://127.0.0.1:8000/top-search-queries' \
curl --location 'http://127.0.0.1:8000/topqueries?limit=10' \
--header 'Authorization: Bearer <access token>'
```
Expand Down
9 changes: 6 additions & 3 deletions backend/app/api/endpoints/search_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@ async def get_search_results(


@router.get(
"/top-search-queries",
"/topqueries",
summary="List all top search queries",
description="List all Top Search Queries",
dependencies=[Depends(security.access_token_required)],
response_model=list[str]
)
@version(1, 0)
async def get_top_search_queries() -> JSONResponse:
async def get_top_search_queries(limit: int) -> JSONResponse:
logger.debug(f"Search_Endpoint.get_top_search_queries")

if limit <= 0:
raise HTTPException(status_code=400, detail="Limit should be greater than 0")

cache = Redis()
last_x_keys = await cache.get_sorted_set("searched_queries", 0, 10)
last_x_keys = await cache.get_sorted_set("searched_queries", 0, limit - 1)

logger.debug(f"Search_Endpoint.get_top_search_queries. result: {last_x_keys}")

Expand Down
3 changes: 2 additions & 1 deletion backend/app/router/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, config):
self.selector = LLMSingleSelector.from_defaults(llm=OpenAI(model="gpt-3.5-turbo", api_key=str(OPENAPI_KEY)), prompt_template_str=self.ROUTER_PROMPT)


async def query_and_get_answer(self, search_text):
async def query_and_get_answer(self, search_text) -> str:

# search router call
logger.debug(f"Orchestrator.query_and_get_answer.router_id search_text: {search_text}")
Expand Down Expand Up @@ -102,6 +102,7 @@ async def query_and_get_answer(self, search_text):
search_text=search_text,
reranked_results=rerankResponse_sliced
)
result = result.get('result', '') + "\n\n" + "Source: " + ', '.join(result.get('source', []))
logger.debug(f"Orchestrator.query_and_get_answer.response_synthesis: {result}")

return result

0 comments on commit 65f7f5a

Please sign in to comment.