You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
768 B
27 lines
768 B
package model
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AIChatMessageInsert 插入AI聊天消息
|
|
func AIChatMessageInsert(ctx context.Context, db *gorm.DB, message *AIChatMessage) (int64, error) {
|
|
result := db.WithContext(ctx).Create(message)
|
|
if result.Error != nil {
|
|
return 0, result.Error
|
|
}
|
|
return message.Id, nil
|
|
}
|
|
|
|
// AIChatMessageFindByConversation 根据对话ID查询所有消息(按创建时间升序,不分页)
|
|
func AIChatMessageFindByConversation(ctx context.Context, db *gorm.DB, conversationId int64) ([]AIChatMessage, error) {
|
|
var messages []AIChatMessage
|
|
err := db.WithContext(ctx).Where("conversation_id = ?", conversationId).
|
|
Order("created_at ASC").Find(&messages).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return messages, nil
|
|
}
|
|
|