yao/neo/load.go
Max e530ccc1cd Refactor conversation management and migrate to store-based architecture in Neo API
- Replaced the conversation handling logic with a new store-based approach, enhancing data management and retrieval capabilities.
- Updated all relevant methods to utilize the new store interface, including GetChats, GetChat, GetHistory, and SaveAssistant, ensuring consistent functionality across the API.
- Removed deprecated conversation-related files and structures, streamlining the codebase and improving maintainability.
- Enhanced the AssistantFilter and AssistantResponse types to support the new store architecture, improving filtering and pagination capabilities.
- Updated tests to cover the new store-based methods and ensure robust functionality across different storage backends.
2025-01-01 10:43:05 +08:00

82 lines
1.5 KiB
Go

package neo
import (
"context"
"fmt"
"path/filepath"
"time"
"github.com/yaoapp/gou/application"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/neo/assistant"
"github.com/yaoapp/yao/neo/store"
)
// Neo the neo AI assistant
var Neo *DSL
// Load load AIGC
func Load(cfg config.Config) error {
setting := DSL{
ID: "neo",
Prompts: []assistant.Prompt{},
Option: map[string]interface{}{},
Allows: []string{},
StoreSetting: store.Setting{
Table: "yao_neo_conversation",
Connector: "default",
},
}
bytes, err := application.App.Read(filepath.Join("neo", "neo.yml"))
if err != nil {
return err
}
err = application.Parse("neo.yml", bytes, &setting)
if err != nil {
return err
}
if setting.StoreSetting.MaxSize == 0 {
setting.StoreSetting.MaxSize = 100
}
Neo = &setting
// Store Setting
err = Neo.createStore()
if err != nil {
return err
}
// Query Assistant List
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
listDone := make(chan error, 1)
go func() {
list, err := Neo.HookAssistants(ctx, assistant.QueryParam{Limit: 100})
Neo.updateAssistantList(list)
listDone <- err
}()
select {
case err := <-listDone:
if err != nil {
return fmt.Errorf("Neo assistant list failed: %w", err)
}
// Create Default Assistant
Neo.Assistant, err = Neo.createDefaultAssistant()
if err != nil {
return err
}
return nil
case <-ctx.Done():
return fmt.Errorf("Neo assistant list timeout: %w", ctx.Err())
}
}