Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chat-identifiers endpoint #338

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions ragna/deploy/_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ async def create_chat(
database.add_chat(session, user=user, chat=chat)
return chat

@app.get("/chat-identifiers")
async def get_chat_identifiers(
user: UserDependency
) -> list[schemas.ChatIdentifier]:
with get_session() as session:
return database.get_chat_identifiers(session, user=user)

@app.get("/chats")
async def get_chats(user: UserDependency) -> list[schemas.Chat]:
with get_session() as session:
Expand Down
17 changes: 17 additions & 0 deletions ragna/deploy/_api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ def add_chat(session: Session, *, user: str, chat: schemas.Chat) -> None:
session.commit()


def _orm_to_schema_identifier(chat: orm.Chat) -> schemas.ChatIdentifier:
return schemas.ChatIdentifier(id=chat.id, name=chat.name)


def get_chat_identifiers(
session: Session, *, user: str
) -> list[schemas.ChatIdentifier]:
return [
_orm_to_schema_identifier(chat)
for chat in session.execute(
select(orm.Chat).where(orm.Chat.user_id == _get_user_id(session, user))
)
.scalars()
.all()
]


def _orm_to_schema_chat(chat: orm.Chat) -> schemas.Chat:
documents = [
schemas.Document(id=document.id, name=document.name)
Expand Down
5 changes: 5 additions & 0 deletions ragna/deploy/_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ class Chat(BaseModel):
metadata: ChatMetadata
messages: list[Message] = Field(default_factory=list)
prepared: bool = False


class ChatIdentifier(BaseModel):
id: uuid.UUID
name: str
Loading