Skip to content

Commit

Permalink
Support setup chat AI model for each robot. v1.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 10, 2023
1 parent d943151 commit 40056fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Optionally, additional robots can be incorporated into various environments:
* `AIT_ROBOT_0_ASR_LANGUAGE`: The language for extra robot `#0`, see `AIT_ASR_LANGUAGE`, default to `en`.
* `AIT_ROBOT_0_PREFIX`: (Optional) The prefix for the first sentence for extra robot `#0`, see `AIT_REPLY_PREFIX`.
* `AIT_ROBOT_0_REPLY_LIMIT`: (Optional) The limit words for extra robot `#0`, default to `AIT_REPLY_LIMIT`.
* `AIT_ROBOT_0_CHAT_MODEL`: (Optional) The AI chat model for extra robot `#0`, default to `AIT_CHAT_MODEL`.

Less frequently used optional environment variables:

Expand Down Expand Up @@ -162,5 +163,6 @@ The changelog:
* Refine the data loss before and after record. v1.0.21
* Add text tips label to use microphone. v1.0.22
* Refine the startup waiting UI. [v1.0.23](https://github.com/ossrs/ai-talk/releases/tag/v1.0.23)
* Support setup chat AI model for each robot. v1.0.24

Winlin, 2023.12
23 changes: 15 additions & 8 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Robot struct {
voice string
// Reply words limit.
replyLimit int
// AI Chat model.
chatModel string
}

// Get the robot by uuid.
Expand All @@ -74,7 +76,8 @@ func (v Robot) String() string {
if v.prefix != "" {
sb.WriteString(fmt.Sprintf(",prefix:%v", v.prefix))
}
sb.WriteString(fmt.Sprintf(",voice=%v,limit=%v,prompt:%v", v.voice, v.replyLimit, v.prompt))
sb.WriteString(fmt.Sprintf(",voice=%v,limit=%v,model=%v,prompt:%v",
v.voice, v.replyLimit, v.chatModel, v.prompt))
return sb.String()
}

Expand Down Expand Up @@ -698,7 +701,7 @@ func handleUploadQuestionAudio(ctx context.Context, w http.ResponseWriter, r *ht
Content: stage.previousAsrText,
})

model := os.Getenv("AIT_CHAT_MODEL")
model := robot.chatModel
var maxTokens int
if v, err := strconv.ParseInt(os.Getenv("AIT_MAX_TOKENS"), 10, 64); err != nil {
return errors.Wrapf(err, "parse AIT_MAX_TOKENS %v", os.Getenv("AIT_MAX_TOKENS"))
Expand Down Expand Up @@ -1242,20 +1245,24 @@ func doConfig(ctx context.Context) error {
voice = "hello-chinese.aac"
}

replyLimit := globalReplylimit
replyLimit := int(globalReplylimit)
if os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_REPLY_LIMIT", i)) != "" {
if iv, err := strconv.ParseInt(os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_REPLY_LIMIT", i)), 10, 64); err != nil {
return errors.Wrapf(err, "parse AIT_REPLY_LIMIT %v", os.Getenv("AIT_REPLY_LIMIT"))
} else {
replyLimit = iv
replyLimit = int(iv)
}
}

chatModel := os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_CHAT_MODEL", i))
if chatModel == "" {
chatModel = os.Getenv("AIT_CHAT_MODEL")
}

robots = append(robots, &Robot{
voice: voice, replyLimit: int(replyLimit),
uuid: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_ID", i)),
label: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_LABEL", i)),
prompt: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_PROMPT", i)),
voice: voice, uuid: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_ID", i)),
replyLimit: replyLimit, label: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_LABEL", i)),
chatModel: chatModel, prompt: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_PROMPT", i)),
prefix: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_PREFIX", i)),
// The ASR language for whisper.
asrLanguage: os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_ASR_LANGUAGE", i)),
Expand Down

0 comments on commit 40056fc

Please sign in to comment.