Users can now attach images in the web chat for Simba to analyze using Ollama's gemma3 vision model. Images are stored in Garage (S3-compatible) and displayed in chat history. Also fixes aerich migration config by extracting TORTOISE_CONFIG into a standalone config/db.py module, removing the stale aerich_config.py, and adding missing MODELS_STATE to migration 3. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
import enum
|
|
from dataclasses import dataclass
|
|
|
|
from tortoise import fields
|
|
from tortoise.contrib.pydantic import (
|
|
pydantic_model_creator,
|
|
pydantic_queryset_creator,
|
|
)
|
|
from tortoise.models import Model
|
|
|
|
|
|
@dataclass
|
|
class RenameConversationOutputSchema:
|
|
title: str
|
|
justification: str
|
|
|
|
|
|
class Speaker(enum.Enum):
|
|
USER = "user"
|
|
SIMBA = "simba"
|
|
|
|
|
|
class Conversation(Model):
|
|
id = fields.UUIDField(primary_key=True)
|
|
name = fields.CharField(max_length=255)
|
|
created_at = fields.DatetimeField(auto_now_add=True)
|
|
updated_at = fields.DatetimeField(auto_now=True)
|
|
user: fields.ForeignKeyRelation = fields.ForeignKeyField(
|
|
"models.User", related_name="conversations", null=True
|
|
)
|
|
|
|
class Meta:
|
|
table = "conversations"
|
|
|
|
|
|
class ConversationMessage(Model):
|
|
id = fields.UUIDField(primary_key=True)
|
|
text = fields.TextField()
|
|
conversation = fields.ForeignKeyField(
|
|
"models.Conversation", related_name="messages"
|
|
)
|
|
created_at = fields.DatetimeField(auto_now_add=True)
|
|
speaker = fields.CharEnumField(enum_type=Speaker, max_length=10)
|
|
image_key = fields.CharField(max_length=512, null=True, default=None)
|
|
|
|
class Meta:
|
|
table = "conversation_messages"
|
|
|
|
|
|
PydConversationMessage = pydantic_model_creator(ConversationMessage)
|
|
PydConversation = pydantic_model_creator(
|
|
Conversation, name="Conversation", allow_cycles=True, exclude=("user",)
|
|
)
|
|
PydConversationWithMessages = pydantic_model_creator(
|
|
Conversation,
|
|
name="ConversationWithMessages",
|
|
allow_cycles=True,
|
|
exclude=("user",),
|
|
include=("messages",),
|
|
)
|
|
PydListConversation = pydantic_queryset_creator(Conversation)
|
|
PydListConversationMessage = pydantic_queryset_creator(ConversationMessage)
|