Make Conversation a pointer refernece on Message
Instead of a value, which lead some odd handling of conversation references. Also fixed some formatting and removed an unnecessary (and probably broken) setting of ConversationID in a call to `cmdutil.HandleConversationReply`
This commit is contained in:
@@ -16,17 +16,17 @@ const (
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
ConversationID uint `gorm:"index"`
|
||||
Conversation Conversation `gorm:"foreignKey:ConversationID"`
|
||||
ID uint `gorm:"primaryKey"`
|
||||
ConversationID *uint `gorm:"index"`
|
||||
Conversation *Conversation `gorm:"foreignKey:ConversationID"`
|
||||
Content string
|
||||
Role MessageRole
|
||||
CreatedAt time.Time
|
||||
ToolCalls ToolCalls // a json array of tool calls (from the model)
|
||||
ToolResults ToolResults // a json array of tool results
|
||||
ParentID *uint
|
||||
Parent *Message `gorm:"foreignKey:ParentID"`
|
||||
Replies []Message `gorm:"foreignKey:ParentID"`
|
||||
Parent *Message `gorm:"foreignKey:ParentID"`
|
||||
Replies []Message `gorm:"foreignKey:ParentID"`
|
||||
|
||||
SelectedReplyID *uint
|
||||
SelectedReply *Message `gorm:"foreignKey:SelectedReplyID"`
|
||||
@@ -37,7 +37,7 @@ type Conversation struct {
|
||||
ShortName sql.NullString
|
||||
Title string
|
||||
SelectedRootID *uint
|
||||
SelectedRoot *Message `gorm:"foreignKey:SelectedRootID"`
|
||||
SelectedRoot *Message `gorm:"foreignKey:SelectedRootID"`
|
||||
}
|
||||
|
||||
type RequestParameters struct {
|
||||
|
||||
@@ -159,7 +159,7 @@ func (s *SQLStore) StartConversation(messages ...model.Message) (*model.Conversa
|
||||
}
|
||||
|
||||
// Create first message
|
||||
messages[0].Conversation = *conversation
|
||||
messages[0].Conversation = conversation
|
||||
err = s.db.Create(&messages[0]).Error
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -201,7 +201,7 @@ func (s *SQLStore) CloneConversation(toClone model.Conversation) (*model.Convers
|
||||
for _, root := range rootMessages {
|
||||
messageCnt++
|
||||
newRoot := root
|
||||
newRoot.ConversationID = clone.ID
|
||||
newRoot.ConversationID = &clone.ID
|
||||
|
||||
cloned, count, err := s.CloneBranch(newRoot)
|
||||
if err != nil {
|
||||
@@ -232,9 +232,10 @@ func (s *SQLStore) Reply(to *model.Message, messages ...model.Message) ([]model.
|
||||
err := s.db.Transaction(func(tx *gorm.DB) error {
|
||||
currentParent := to
|
||||
for i := range messages {
|
||||
parent := currentParent
|
||||
message := messages[i]
|
||||
message.Parent = currentParent
|
||||
message.Conversation = currentParent.Conversation
|
||||
message.Parent = parent
|
||||
message.Conversation = parent.Conversation
|
||||
message.ID = 0
|
||||
message.CreatedAt = time.Time{}
|
||||
|
||||
@@ -243,9 +244,9 @@ func (s *SQLStore) Reply(to *model.Message, messages ...model.Message) ([]model.
|
||||
}
|
||||
|
||||
// update parent selected reply
|
||||
currentParent.Replies = append(currentParent.Replies, message)
|
||||
currentParent.SelectedReply = &message
|
||||
if err := tx.Model(currentParent).Update("selected_reply_id", message.ID).Error; err != nil {
|
||||
parent.Replies = append(parent.Replies, message)
|
||||
parent.SelectedReply = &message
|
||||
if err := tx.Model(parent).Update("selected_reply_id", message.ID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user