Skip to content

Commit

Permalink
add model field
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 24, 2023
1 parent dc96278 commit 205cdc1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions connection/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func CreateConversationTable(db *sql.DB) {
conversation_id INT,
conversation_name VARCHAR(255),
data TEXT,
model VARCHAR(255) NOT NULL DEFAULT 'gpt-3.5-turbo',
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY (user_id, conversation_id)
);
Expand Down
12 changes: 9 additions & 3 deletions manager/conversation/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func (c *Conversation) SaveConversation(db *sql.DB) bool {
}

data := utils.ToJson(c.GetMessage())
query := `INSERT INTO conversation (user_id, conversation_id, conversation_name, data) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE conversation_name = VALUES(conversation_name), data = VALUES(data)`
query := `
INSERT INTO conversation (user_id, conversation_id, conversation_name, data, model) VALUES (?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE conversation_name = VALUES(conversation_name), data = VALUES(data)
`

stmt, err := db.Prepare(query)
if err != nil {
Expand All @@ -28,7 +31,7 @@ func (c *Conversation) SaveConversation(db *sql.DB) bool {
}
}(stmt)

_, err = stmt.Exec(c.UserID, c.Id, c.Name, data)
_, err = stmt.Exec(c.UserID, c.Id, c.Name, data, c.Model)
if err != nil {
return false
}
Expand All @@ -50,7 +53,10 @@ func LoadConversation(db *sql.DB, userId int64, conversationId int64) *Conversat
}

var data string
err := db.QueryRow("SELECT conversation_name, data FROM conversation WHERE user_id = ? AND conversation_id = ?", userId, conversationId).Scan(&conversation.Name, &data)
err := db.QueryRow(`
SELECT conversation_name, model, data FROM conversation
WHERE user_id = ? AND conversation_id = ?
`, userId, conversationId).Scan(&conversation.Name, &data, &conversation.Model)
if err != nil {
return nil
}
Expand Down

0 comments on commit 205cdc1

Please sign in to comment.