Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ def initialize_database() -> None:

match db_config.db_type:
case "sqlite":
logger.info("Initialize SQLite database")
sqlite_config = db_config.config
logger.debug("Configuration: %s", sqlite_config)
assert isinstance(sqlite_config, SQLiteDatabaseConfiguration)
engine = _create_sqlite_engine(sqlite_config, **create_engine_kwargs)
case "postgres":
logger.info("Initialize PostgreSQL database")
postgres_config = db_config.config
logger.debug("Configuration: %s", postgres_config)
assert isinstance(postgres_config, PostgreSQLDatabaseConfiguration)
engine = _create_postgres_engine(postgres_config, **create_engine_kwargs)

Expand Down
5 changes: 5 additions & 0 deletions src/app/endpoints/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ async def query_endpoint_handler(

user_conversation: UserConversation | None = None
if query_request.conversation_id:
logger.debug(
"Conversation ID specified in query: %s", query_request.conversation_id
)
user_conversation = validate_conversation_ownership(
user_id=user_id,
conversation_id=query_request.conversation_id,
Expand All @@ -205,6 +208,8 @@ async def query_endpoint_handler(
"cause": "You do not have permission to access this conversation",
},
)
else:
logger.debug("Query does not contain conversation ID")

try:
# try to get Llama Stack client
Expand Down
9 changes: 7 additions & 2 deletions src/utils/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Utility functions for endpoint handlers."""

from contextlib import suppress
import logging
from fastapi import HTTPException, status
from llama_stack_client._client import AsyncLlamaStackClient
from llama_stack_client.lib.agents.agent import AsyncAgent
Expand All @@ -16,7 +15,9 @@
from utils.types import GraniteToolParser


logger = logging.getLogger("utils.endpoints")
from log import get_logger

logger = get_logger(__name__)


def delete_conversation(conversation_id: str) -> None:
Expand Down Expand Up @@ -164,6 +165,8 @@ async def get_agent(
await agent.initialize()

if existing_agent_id and conversation_id:
logger.debug("Existing conversation ID: %s", conversation_id)
logger.debug("Existing agent ID: %s", existing_agent_id)
orphan_agent_id = agent.agent_id
agent._agent_id = conversation_id # type: ignore[assignment] # pylint: disable=protected-access
await client.agents.delete(agent_id=orphan_agent_id)
Expand All @@ -182,6 +185,8 @@ async def get_agent(
) from e
else:
conversation_id = agent.agent_id
logger.debug("New conversation ID: %s", conversation_id)
session_id = await agent.create_session(get_suid())
logger.debug("New session ID: %s", session_id)

return agent, conversation_id, session_id
Loading