feat: add ChatConversation and ChatMessage models

- Introduced ChatConversation and ChatMessage structs to represent conversation and message data in the application.
- Included relevant fields with JSON and BSON annotations for proper serialization and database integration.
- Enhanced model definitions with descriptions for better understanding of their purpose and usage.
- Ensured alignment with existing coding standards and practices for maintainability.
This commit is contained in:
Marvin Zhang
2025-03-19 16:46:52 +08:00
parent 931a36c8bf
commit 3d11a14fd8
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package models
import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ChatConversation struct {
any `collection:"chat_conversations"`
BaseModel `bson:",inline"`
Title string `json:"title" bson:"title" description:"Conversation title"`
Description string `json:"description,omitempty" bson:"description,omitempty" description:"Conversation description"`
UserId primitive.ObjectID `json:"user_id" bson:"user_id" description:"User ID who owns this conversation"`
Model string `json:"model" bson:"model" description:"Default AI model for this conversation"`
Status string `json:"status" bson:"status" description:"Conversation status (active/archived/deleted)"`
LastMessageAt primitive.DateTime `json:"last_message_at,omitempty" bson:"last_message_at,omitempty" description:"Last message timestamp"`
Settings map[string]any `json:"settings,omitempty" bson:"settings,omitempty" description:"Conversation settings"`
Tags []string `json:"tags,omitempty" bson:"tags,omitempty" description:"Conversation tags"`
Messages []*ChatMessage `json:"messages,omitempty" bson:"-" description:"Messages in this conversation (populated field)"`
}

View File

@@ -0,0 +1,18 @@
package models
import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ChatMessage struct {
any `collection:"chat_messages"`
BaseModel `bson:",inline"`
ConversationId primitive.ObjectID `json:"conversation_id" bson:"conversation_id" description:"Conversation ID"`
Role string `json:"role" bson:"role" description:"Message role (user/assistant/system)"`
Content string `json:"content" bson:"content" description:"Message content"`
Tokens int `json:"tokens" bson:"tokens" description:"Number of tokens in the message"`
Model string `json:"model" bson:"model" description:"AI model used"`
Metadata map[string]any `json:"metadata,omitempty" bson:"metadata,omitempty" description:"Additional metadata"`
Status string `json:"status" bson:"status" description:"Message status (pending/completed/failed)"`
Error string `json:"error,omitempty" bson:"error,omitempty" description:"Error message if failed"`
}