Merge pull request #623 from trheyi/main

refactor: Update AI connector handling and add support for Moapi models
This commit is contained in:
Max 2024-06-15 15:58:42 +08:00 committed by GitHub
commit 078c38bf06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package aigc
import (
"fmt"
"strings"
jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou/connector"
@ -96,8 +97,17 @@ func (ai *DSL) Call(content string, user string, option map[string]interface{})
// NewAI create a new AI
func (ai *DSL) newAI() (AI, error) {
if ai.Connector == "" {
return nil, fmt.Errorf("%s connector is required", ai.ID)
if ai.Connector == "" || strings.HasPrefix(ai.Connector, "moapi") {
model := "gpt-3.5-turbo"
if ai.Connector != "" {
model = strings.TrimPrefix(ai.Connector, "moapi:")
}
mo, err := openai.NewMoapi(model)
if err != nil {
return nil, err
}
return mo, nil
}
conn, err := connector.Select(ai.Connector)

View file

@ -10,7 +10,7 @@ import (
type DSL struct {
ID string `json:"-" yaml:"-"`
Name string `json:"name,omitempty"`
Connector string `json:"connector"`
Connector string `json:"connector,omitempty"`
Process string `json:"process,omitempty"`
Prompts []Prompt `json:"prompts"`
Optional Optional `json:"optional,omitempty"`