diff --git a/neo/assistant/base/chat.go b/neo/assistant/local/chat.go similarity index 65% rename from neo/assistant/base/chat.go rename to neo/assistant/local/chat.go index 7df5c58a..8c2518cb 100644 --- a/neo/assistant/base/chat.go +++ b/neo/assistant/local/chat.go @@ -1,4 +1,4 @@ -package base +package local import ( "context" @@ -6,7 +6,7 @@ import ( ) // Chat the chat -func (ast *Base) Chat(ctx context.Context, messages []map[string]interface{}, option map[string]interface{}, cb func(data []byte) int) error { +func (ast *Local) Chat(ctx context.Context, messages []map[string]interface{}, option map[string]interface{}, cb func(data []byte) int) error { if ast.openai == nil { return fmt.Errorf("api is not initialized") diff --git a/neo/assistant/base/file.go b/neo/assistant/local/file.go similarity index 89% rename from neo/assistant/base/file.go rename to neo/assistant/local/file.go index fd4f3029..79d40b6f 100644 --- a/neo/assistant/base/file.go +++ b/neo/assistant/local/file.go @@ -1,4 +1,4 @@ -package base +package local import ( "context" @@ -31,7 +31,7 @@ var AllowedFileTypes = map[string]string{ var MaxSize int64 = 20 * 1024 * 1024 // Upload the file -func (ast *Base) Upload(ctx context.Context, file *multipart.FileHeader, reader io.Reader, option map[string]interface{}) (*assistant.File, error) { +func (ast *Local) Upload(ctx context.Context, file *multipart.FileHeader, reader io.Reader, option map[string]interface{}) (*assistant.File, error) { // check file size if file.Size > MaxSize { @@ -69,13 +69,13 @@ func (ast *Base) Upload(ctx context.Context, file *multipart.FileHeader, reader }, nil } -func (ast *Base) id(temp string, ext string) (string, error) { +func (ast *Local) id(temp string, ext string) (string, error) { date := time.Now().Format("20060102") hash := fmt.Sprintf("%x", sha256.Sum256([]byte(temp)))[:8] return fmt.Sprintf("/__assistants/%s/%s/%s%s", ast.ID, date, hash, ext), nil } -func (ast *Base) allowed(contentType string) bool { +func (ast *Local) allowed(contentType string) bool { if _, ok := AllowedFileTypes[contentType]; ok { return true } @@ -87,7 +87,7 @@ func (ast *Base) allowed(contentType string) bool { } // Download downloads a file -func (ast *Base) Download(ctx context.Context, fileID string) (*assistant.FileResponse, error) { +func (ast *Local) Download(ctx context.Context, fileID string) (*assistant.FileResponse, error) { // Get the data filesystem data, err := fs.Get("data") diff --git a/neo/assistant/base/base.go b/neo/assistant/local/local.go similarity index 63% rename from neo/assistant/base/base.go rename to neo/assistant/local/local.go index bd608fe1..7a1386ff 100644 --- a/neo/assistant/base/base.go +++ b/neo/assistant/local/local.go @@ -1,4 +1,4 @@ -package base +package local import ( "context" @@ -8,16 +8,16 @@ import ( "github.com/yaoapp/yao/openai" ) -// Base the base assistant -type Base struct { +// Local the local assistant +type Local struct { ID string `json:"assistant_id"` Prompts []assistant.Prompt `json:"prompts,omitempty"` Connector connector.Connector `json:"-" yaml:"-"` openai *openai.OpenAI } -// New create a new base assistant -func New(connector connector.Connector, prompts []assistant.Prompt, id string) (*Base, error) { +// New create a new local assistant +func New(connector connector.Connector, prompts []assistant.Prompt, id string) (*Local, error) { setting := connector.Setting() api, err := openai.NewOpenAI(setting) @@ -25,10 +25,10 @@ func New(connector connector.Connector, prompts []assistant.Prompt, id string) ( return nil, err } - return &Base{Connector: connector, ID: id, Prompts: prompts, openai: api}, nil + return &Local{Connector: connector, ID: id, Prompts: prompts, openai: api}, nil } // List list all assistants -func (ast *Base) List(ctx context.Context, param assistant.QueryParam) ([]assistant.Assistant, error) { +func (ast *Local) List(ctx context.Context, param assistant.QueryParam) ([]assistant.Assistant, error) { return nil, nil } diff --git a/neo/conversation/xun.go b/neo/conversation/xun.go index 8ab43dc7..5eecf4dc 100644 --- a/neo/conversation/xun.go +++ b/neo/conversation/xun.go @@ -23,19 +23,6 @@ type Xun struct { setting Setting } -type row struct { - Role string `json:"role"` // Message role - Name string `json:"name"` // User name - Content string `json:"content"` // Message content - Sid string `json:"sid"` // Session ID - Cid string `json:"cid"` // Chat ID from chat history - UID string `json:"uid"` // User ID - Context map[string]interface{} `json:"context"` // Message context - CreatedAt time.Time `json:"created_at"` // Created time - UpdatedAt *time.Time `json:"updated_at"` // Updated time - ExpiredAt interface{} `json:"expired_at"` // Expired time -} - // Public interface methods and constructor remain exported: // - NewXun // - UpdateChatTitle @@ -228,6 +215,7 @@ func (conv *Xun) initAssistantTable() error { table.JSON("option").Null() table.JSON("prompts").Null() table.JSON("flows").Null() + table.Boolean("mentionable").SetDefault(true).Index() // Whether this assistant can appear in @ mention list table.TimestampTz("created_at").SetDefaultRaw("NOW()").Index() table.TimestampTz("updated_at").Null().Index() }) @@ -244,7 +232,7 @@ func (conv *Xun) initAssistantTable() error { return err } - fields := []string{"id", "assistant_id", "type", "name", "avatar", "connector", "description", "option", "prompts", "flows", "created_at", "updated_at"} + fields := []string{"id", "assistant_id", "type", "name", "avatar", "connector", "description", "option", "prompts", "flows", "mentionable", "created_at", "updated_at"} for _, field := range fields { if !tab.HasColumn(field) { return fmt.Errorf("%s is required", field) diff --git a/neo/neo.go b/neo/neo.go index 0583c1d9..856082e6 100644 --- a/neo/neo.go +++ b/neo/neo.go @@ -11,7 +11,7 @@ import ( "github.com/yaoapp/gou/connector" "github.com/yaoapp/kun/log" "github.com/yaoapp/yao/neo/assistant" - "github.com/yaoapp/yao/neo/assistant/base" + "github.com/yaoapp/yao/neo/assistant/local" "github.com/yaoapp/yao/neo/assistant/openai" "github.com/yaoapp/yao/neo/conversation" "github.com/yaoapp/yao/neo/message" @@ -417,9 +417,9 @@ func (neo *DSL) newAssistantByConnector(id string) (assistant.API, error) { } // Base on the assistant list hook - api, err := base.New(conn, neo.Prompts, id) + api, err := local.New(conn, neo.Prompts, id) if err != nil { - return nil, fmt.Errorf("Create base assistant error: %s", err.Error()) + return nil, fmt.Errorf("Create local assistant error: %s", err.Error()) } return api, nil }