Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/app/endpoints/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import logging
from typing import Any

from llama_stack_client import LlamaStackClient

from fastapi import APIRouter, Request

from configuration import configuration
from models.responses import QueryResponse

logger = logging.getLogger(__name__)
Expand All @@ -19,6 +22,28 @@
}


@router.get("/query", responses=query_response)
def info_endpoint_handler(request: Request) -> QueryResponse:
return QueryResponse(query="foo", response="bar")
@router.post("/query", responses=query_response)
def info_endpoint_handler(request: Request, query: str) -> QueryResponse:
llama_stack_config = configuration.llama_stack_configuration
logger.info("LLama stack config: %s", llama_stack_config)
client = LlamaStackClient(
base_url=llama_stack_config.url, api_key=llama_stack_config.api_key
)

# retrieve list of available models
models = client.models.list()

# select the first LLM
llm = next(m for m in models if m.model_type == "llm")
model_id = llm.identifier

logger.info("Model: %s", model_id)

response = client.inference.chat_completion(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should really be using a llama-stack Agent to handle this.

Agents in llama-stack can handle all of steps in a LLM call:

  • Safety Shields on incoming message ("Question validity")
  • Inference
  • MCP (etc) Tool calling
  • Safety Shields on outgoing responses ("Answer redaction")

You are currently only using llama-stack's inference provider.

Happy to help guide you more.. this is why it's important we sync up.

model_id=model_id,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": query},
],
)
return QueryResponse(query=query, response=str(response.completion_message.content))