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
|
2024-02-15 01:01:35 +03:00
|
|
|
message_time: Optional[str] = None
|
|
|
|
prompt_title: Optional[str] | None = None
|
|
|
|
brain_name: Optional[str] | None = None
|
|
|
|
brain_id: Optional[str] | None = (
|
|
|
|
None # string because UUID is not JSON serializable
|
|
|
|
)
|
|
|
|
metadata: Optional[dict] | None = None
|
2024-03-21 10:11:06 +03:00
|
|
|
thumbs: Optional[bool] | None = 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
|
2024-02-15 01:01:35 +03:00
|
|
|
content: str | None = None
|
|
|
|
tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
|
2023-12-15 13:43:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CompletionResponse(BaseModel):
|
|
|
|
finish_reason: str
|
|
|
|
message: CompletionMessage
|
|
|
|
|
|
|
|
|
|
|
|
class BrainCompletionOutput(BaseModel):
|
|
|
|
messages: List[CompletionMessage]
|
|
|
|
question: str
|
|
|
|
response: CompletionResponse
|