- Implemented DeleteChat and DeleteAllChats methods in Mongo, Redis, Weaviate, and Xun conversation handlers to allow users to delete specific chats and all chats associated with their account. - Updated the Conversation interface in types.go to include the new deletion methods, ensuring consistent API across different storage backends. - Added unit tests for DeleteChat and DeleteAllChats methods in xun_test.go to verify functionality and ensure proper deletion of chat histories. - Enhanced error handling in deletion methods to provide robust feedback during chat removal operations.
52 lines
2 KiB
Go
52 lines
2 KiB
Go
package conversation
|
||
|
||
// Setting the conversation config
|
||
type Setting struct {
|
||
Connector string `json:"connector,omitempty"`
|
||
UserField string `json:"user_field,omitempty"` // the user id field name, default is user_id
|
||
Table string `json:"table,omitempty"`
|
||
MaxSize int `json:"max_size,omitempty" yaml:"max_size,omitempty"`
|
||
TTL int `json:"ttl,omitempty" yaml:"ttl,omitempty"`
|
||
}
|
||
|
||
// ChatInfo represents the chat information and its history
|
||
type ChatInfo struct {
|
||
Chat map[string]interface{} `json:"chat"`
|
||
History []map[string]interface{} `json:"history"`
|
||
}
|
||
|
||
// ChatFilter represents the filter parameters for GetChats
|
||
type ChatFilter struct {
|
||
Keywords string `json:"keywords,omitempty"`
|
||
Page int `json:"page,omitempty"` // 页码,从1开始
|
||
PageSize int `json:"pagesize,omitempty"` // 每页数量
|
||
Order string `json:"order,omitempty"` // desc/asc
|
||
}
|
||
|
||
// ChatGroup represents a group of chats by date
|
||
type ChatGroup struct {
|
||
Label string `json:"label"`
|
||
Chats []map[string]interface{} `json:"chats"`
|
||
}
|
||
|
||
// ChatGroupResponse represents paginated chat groups
|
||
type ChatGroupResponse struct {
|
||
Groups []ChatGroup `json:"groups"`
|
||
Page int `json:"page"` // 当前页码
|
||
PageSize int `json:"pagesize"` // 每页数量
|
||
Total int64 `json:"total"` // 总记录数
|
||
LastPage int `json:"last_page"` // 最后一页页码
|
||
}
|
||
|
||
// Conversation the store interface
|
||
type Conversation interface {
|
||
GetChats(sid string, filter ChatFilter) (*ChatGroupResponse, error)
|
||
GetChat(sid string, cid string) (*ChatInfo, error)
|
||
GetHistory(sid string, cid string) ([]map[string]interface{}, error)
|
||
SaveHistory(sid string, messages []map[string]interface{}, cid string) error
|
||
GetRequest(sid string, rid string) ([]map[string]interface{}, error)
|
||
SaveRequest(sid string, rid string, cid string, messages []map[string]interface{}) error
|
||
DeleteChat(sid string, cid string) error
|
||
DeleteAllChats(sid string) error
|
||
UpdateChatTitle(sid string, cid string, title string) error
|
||
}
|