Skip to content

Commit

Permalink
feat: add simple query endpoint (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser authored Dec 6, 2024
1 parent 71f29ea commit 95227a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-goats-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Add query endpoint
2 changes: 2 additions & 0 deletions templates/types/streaming/fastapi/app/api/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from .chat import chat_router # noqa: F401
from .chat_config import config_router # noqa: F401
from .upload import file_upload_router # noqa: F401
from .query import query_router # noqa: F401

api_router = APIRouter()
api_router.include_router(chat_router, prefix="/chat")
api_router.include_router(config_router, prefix="/chat/config")
api_router.include_router(file_upload_router, prefix="/chat/upload")
api_router.include_router(query_router, prefix="/query")

# Dynamically adding additional routers if they exist
try:
Expand Down
25 changes: 25 additions & 0 deletions templates/types/streaming/fastapi/app/api/routers/query.py
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

0 comments on commit 95227a7

Please sign in to comment.