Skip to content

Commit

Permalink
feat: Add SelectModel command to DSL
Browse files Browse the repository at this point in the history
Add the SelectModel command to the DSL, allowing the selection of a specific model. This command takes a model name as input and sets the AI to use that model. It returns a success message with a status code of 200 if the selection is successful.
  • Loading branch information
trheyi committed May 25, 2024
1 parent 1a1ffab commit 1f4e9e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
43 changes: 41 additions & 2 deletions neo/neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ func (neo *DSL) API(router *gin.Engine, path string) error {
}

switch cmd {

case "ModelList":
c.JSON(200, gin.H{"data": neo.Models, "code": 200})
c.Done()

case "SelectModel":
model, ok := payload["model"].(string)
if !ok {
c.JSON(400, gin.H{"message": "model is required", "code": 400})
c.Done()
return
}

err := neo.Select(model)
if err != nil {
c.JSON(500, gin.H{"message": err.Error(), "code": 500})
c.Done()
return
}

c.JSON(200, gin.H{"message": "success", "code": 200})
c.Done()

case "ExitCommandMode":
err := command.Exit(sid)
if err != nil {
Expand Down Expand Up @@ -524,11 +547,17 @@ func (neo *DSL) getGuardHandlers() ([]gin.HandlerFunc, error) {
// NewAI create a new AI
func (neo *DSL) newAI() error {

if neo.Connector == "" {
ai, err := openai.NewMoapi("gpt-3.5-turbo")
if neo.Connector == "" || strings.HasPrefix(neo.Connector, "moapi") {
model := "gpt-3.5-turbo"
if neo.Connector != "" {
model = strings.TrimPrefix(neo.Connector, "moapi:")
}

ai, err := openai.NewMoapi(model)
if err != nil {
return err
}

neo.AI = ai
return nil
}
Expand All @@ -550,6 +579,16 @@ func (neo *DSL) newAI() error {
return fmt.Errorf("%s connector %s not support, should be a openai", neo.ID, neo.Connector)
}

// Select select the model
func (neo *DSL) Select(model string) error {
ai, err := openai.NewMoapi(model)
if err != nil {
return err
}
neo.AI = ai
return nil
}

// newConversation create a new conversation
func (neo *DSL) newConversation() error {

Expand Down
1 change: 1 addition & 0 deletions neo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type DSL struct {
Prompts []aigc.Prompt `json:"prompts,omitempty"`
Allows []string `json:"allows,omitempty"`
Command Command `json:"command,omitempty"`
Models []string `json:"models,omitempty"`
AI aigc.AI `json:"-" yaml:"-"`
Conversation conversation.Conversation `json:"-" yaml:"-"`
GuardHandlers []gin.HandlerFunc `json:"-" yaml:"-"`
Expand Down

0 comments on commit 1f4e9e5

Please sign in to comment.