quivr/backend/modules/chat/dto/outputs.py
Stan Girard dfdb294c50
feat: 🎸 api (#2078)
adding metadata to api

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2024-01-25 15:56:46 -08:00

53 lines
1.3 KiB
Python

from typing import List, Optional
from uuid import UUID
from pydantic import BaseModel
class GetChatHistoryOutput(BaseModel):
chat_id: UUID
message_id: Optional[UUID] | str
user_message: str
assistant: str
message_time: Optional[str]
prompt_title: Optional[str] | None
brain_name: Optional[str] | None
brain_id: Optional[str] | None # string because UUID is not JSON serializable
metadata: Optional[dict] | None
def dict(self, *args, **kwargs):
chat_history = super().dict(*args, **kwargs)
chat_history["chat_id"] = str(chat_history.get("chat_id"))
chat_history["message_id"] = str(chat_history.get("message_id"))
return chat_history
class FunctionCall(BaseModel):
arguments: str
name: str
class ChatCompletionMessageToolCall(BaseModel):
id: str
function: FunctionCall
type: str = "function"
class CompletionMessage(BaseModel):
# = "assistant" | "user" | "system" | "tool"
role: str
content: str | None
tool_calls: Optional[List[ChatCompletionMessageToolCall]]
class CompletionResponse(BaseModel):
finish_reason: str
message: CompletionMessage
class BrainCompletionOutput(BaseModel):
messages: List[CompletionMessage]
question: str
response: CompletionResponse