mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
fix message pointer error
This commit is contained in:
parent
d41931097e
commit
76e43b1d3e
@ -70,7 +70,7 @@ func ChatAPI(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if instance.HandleMessage(db, message) {
|
if instance.HandleMessage(db, message) {
|
||||||
keyword, segment := ChatWithWeb(instance.GetMessageSegment(12), true)
|
keyword, segment := ChatWithWeb(conversation.CopyMessage(instance.GetMessageSegment(12)), true)
|
||||||
SendSegmentMessage(conn, types.ChatGPTSegmentResponse{Keyword: keyword, End: false})
|
SendSegmentMessage(conn, types.ChatGPTSegmentResponse{Keyword: keyword, End: false})
|
||||||
|
|
||||||
msg := ""
|
msg := ""
|
||||||
|
@ -101,8 +101,7 @@ func CreateConversationTable(db *sql.DB) {
|
|||||||
conversation_id INT UNIQUE,
|
conversation_id INT UNIQUE,
|
||||||
conversation_name VARCHAR(255),
|
conversation_name VARCHAR(255),
|
||||||
data TEXT,
|
data TEXT,
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
FOREIGN KEY (user_id) REFERENCES auth(id)
|
|
||||||
);
|
);
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,6 +63,10 @@ func (c *Conversation) GetMessageSegment(length int) []types.ChatGPTMessage {
|
|||||||
return c.Message[len(c.Message)-length:]
|
return c.Message[len(c.Message)-length:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyMessage(message []types.ChatGPTMessage) []types.ChatGPTMessage {
|
||||||
|
return utils.UnmarshalJson[[]types.ChatGPTMessage](utils.ToJson(message)) // deep copy
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Conversation) GetLastMessage() types.ChatGPTMessage {
|
func (c *Conversation) GetLastMessage() types.ChatGPTMessage {
|
||||||
return c.Message[len(c.Message)-1]
|
return c.Message[len(c.Message)-1]
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func GetSegment[T any](arr []T, length int) []T {
|
|||||||
|
|
||||||
func GetSegmentString(arr string, length int) string {
|
func GetSegmentString(arr string, length int) string {
|
||||||
if length > len(arr) {
|
if length > len(arr) {
|
||||||
return ""
|
return arr
|
||||||
}
|
}
|
||||||
return arr[:length]
|
return arr[:length]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user