Refactor conversation table handling and update settings structure in Neo API

- Changed the 'Table' field to 'Prefix' in the Setting struct to better represent its purpose as a table name prefix.
- Updated all relevant instances in the codebase to use the new 'Prefix' field, ensuring consistency across the application.
- Adjusted logging and table retrieval methods to reflect the new naming convention, enhancing clarity and maintainability.
This commit is contained in:
Max 2025-01-02 16:22:10 +08:00
parent fdf71f4cfd
commit 6288e25a8a
4 changed files with 16 additions and 16 deletions

View file

@ -38,7 +38,7 @@ func Load(cfg config.Config) error {
Option: map[string]interface{}{},
Allows: []string{},
StoreSetting: store.Setting{
Table: "yao_neo_conversation",
Prefix: "yao_neo_",
Connector: "default",
},
}

View file

@ -5,7 +5,7 @@ package store
type Setting struct {
Connector string `json:"connector,omitempty"` // Name of the connector used to specify data storage method
UserField string `json:"user_field,omitempty"` // User ID field name, defaults to "user_id"
Table string `json:"table,omitempty"` // Database table name
Prefix string `json:"prefix,omitempty"` // Database table name prefix
MaxSize int `json:"max_size,omitempty" yaml:"max_size,omitempty"` // Maximum storage size limit
TTL int `json:"ttl,omitempty" yaml:"ttl,omitempty"` // Time To Live in seconds
}

View file

@ -99,7 +99,7 @@ func (conv *Xun) clean() {
}
if nums > 0 {
log.Trace("Clean the conversation table: %s %d", conv.setting.Table, nums)
log.Trace("Clean the conversation table: %s %d", conv.setting.Prefix, nums)
}
}
@ -283,15 +283,15 @@ func (conv *Xun) getUserID(sid string) (string, error) {
}
func (conv *Xun) getHistoryTable() string {
return conv.setting.Table + "_history"
return conv.setting.Prefix + "history"
}
func (conv *Xun) getChatTable() string {
return conv.setting.Table + "_chat"
return conv.setting.Prefix + "chat"
}
func (conv *Xun) getAssistantTable() string {
return conv.setting.Table + "_assistant"
return conv.setting.Prefix + "assistant"
}
// UpdateChatTitle update the chat title

View file

@ -40,7 +40,7 @@ func TestNewXunDefault(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
@ -139,7 +139,7 @@ func TestNewXunConnector(t *testing.T) {
store, err := NewXun(Setting{
Connector: "mysql",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
@ -201,7 +201,7 @@ func TestXunSaveAndGetHistory(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
TTL: 3600,
})
@ -239,7 +239,7 @@ func TestXunSaveAndGetHistoryWithCID(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
TTL: 3600,
})
@ -308,7 +308,7 @@ func TestXunGetChats(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)
@ -364,7 +364,7 @@ func TestXunDeleteChat(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)
@ -404,7 +404,7 @@ func TestXunDeleteAllChats(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)
@ -455,7 +455,7 @@ func TestXunAssistantCRUD(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)
@ -926,7 +926,7 @@ func TestXunAssistantPagination(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)
@ -1250,7 +1250,7 @@ func TestGetAssistantTags(t *testing.T) {
store, err := NewXun(Setting{
Connector: "default",
Table: "__unit_test_conversation",
Prefix: "__unit_test_conversation_",
})
if err != nil {
t.Fatal(err)