2023-12-15 13:43:41 +03:00
|
|
|
from typing import List, Optional
|
2023-12-04 20:38:54 +03:00
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
class GetChatHistoryOutput(BaseModel):
|
|
|
|
chat_id: UUID
|
2023-12-15 13:43:41 +03:00
|
|
|
message_id: Optional[UUID] | str
|
2023-12-04 20:38:54 +03:00
|
|
|
user_message: str
|
|
|
|
assistant: str
|
2023-12-15 13:43:41 +03:00
|
|
|
message_time: Optional[str]
|
2023-12-04 20:38:54 +03:00
|
|
|
prompt_title: Optional[str] | None
|
|
|
|
brain_name: Optional[str] | None
|
2024-01-26 02:56:46 +03:00
|
|
|
brain_id: Optional[str] | None # string because UUID is not JSON serializable
|
2024-01-20 07:34:30 +03:00
|
|
|
metadata: Optional[dict] | None
|
2023-12-04 20:38:54 +03:00
|
|
|
|
|
|
|
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
|
2023-12-15 13:43:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
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
|