From 3d11a14fd82831169f2ba7ee15d97da9be286a9d Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 19 Mar 2025 16:46:52 +0800 Subject: [PATCH] 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. --- core/models/models/chat_conversation.go | 19 +++++++++++++++++++ core/models/models/chat_message.go | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 core/models/models/chat_conversation.go create mode 100644 core/models/models/chat_message.go diff --git a/core/models/models/chat_conversation.go b/core/models/models/chat_conversation.go new file mode 100644 index 00000000..bc6b296d --- /dev/null +++ b/core/models/models/chat_conversation.go @@ -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)"` +} diff --git a/core/models/models/chat_message.go b/core/models/models/chat_message.go new file mode 100644 index 00000000..155d2369 --- /dev/null +++ b/core/models/models/chat_message.go @@ -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"` +}