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

Return document metadata in API #355

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions ragna/deploy/_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def schema_to_core_chat(
session,
user=user,
id=document.id,
)[1],
).metadata,
)
for document in chat.metadata.documents
],
Expand All @@ -218,10 +218,12 @@ def schema_to_core_chat(
@app.post("/chats")
async def create_chat(
user: UserDependency,
chat_metadata: schemas.ChatMetadata,
chat_creation_data: schemas.ChatCreationData,
) -> schemas.Chat:
with get_session() as session:
chat = schemas.Chat(metadata=chat_metadata)
# get documents from DB
database.get_document()

# Although we don't need the actual ragna.core.Chat object here,
# we use it to validate the documents and metadata.
Expand Down
12 changes: 9 additions & 3 deletions ragna/deploy/_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class Components(BaseModel):
class Document(BaseModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4)
name: str
metadata: dict

@classmethod
def from_core(cls, document: ragna.core.Document) -> Document:
return cls(
id=document.id,
name=document.name,
metadata=document.metadata,
)


Expand Down Expand Up @@ -69,16 +71,20 @@ def from_core(cls, message: ragna.core.Message) -> Message:
)


class ChatMetadata(BaseModel):
class ChatCreationData(BaseModel):
name: str
document_ids: list[uuid.UUID]
source_storage: str
assistant: str
params: dict
documents: list[Document]


class Chat(BaseModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4)
metadata: ChatMetadata
name: str
documents: list[Document]
source_storage: str
assistant: str
params: dict
messages: list[Message] = Field(default_factory=list)
prepared: bool = False
Loading