-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add simple query endpoint (#458)
- Loading branch information
1 parent
71f29ea
commit 95227a7
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Add query endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
templates/types/streaming/fastapi/app/api/routers/query.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import logging | ||
|
||
from fastapi import APIRouter | ||
from app.engine.index import IndexConfig, get_index | ||
from llama_index.core.base.base_query_engine import BaseQueryEngine | ||
|
||
|
||
query_router = r = APIRouter() | ||
|
||
logger = logging.getLogger("uvicorn") | ||
|
||
|
||
def get_query_engine() -> BaseQueryEngine: | ||
index_config = IndexConfig(**{}) | ||
index = get_index(index_config) | ||
return index.as_query_engine() | ||
|
||
|
||
@r.get("/") | ||
async def query_request( | ||
query: str, | ||
) -> str: | ||
query_engine = get_query_engine() | ||
response = await query_engine.aquery(query) | ||
return response.response |