Skip to content

Commit

Permalink
Support setup chat window for each robot. v1.0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 10, 2023
1 parent 40056fc commit 6e5db20
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Optionally, additional robots can be incorporated into various environments:
* `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`.
* `AIT_ROBOT_0_CHAT_WINDOW`: (Optional) The AI chat window for extra robot `#0`, default to `AIT_CHAT_WINDOW`.

Less frequently used optional environment variables:

Expand Down Expand Up @@ -164,5 +165,6 @@ The changelog:
* 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
* Support setup chat window for each robot. v1.0.25

Winlin, 2023.12
40 changes: 30 additions & 10 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Robot struct {
replyLimit int
// AI Chat model.
chatModel string
// AI Chat message window.
chatWindow int
}

// Get the robot by uuid.
Expand All @@ -76,8 +78,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,model=%v,prompt:%v",
v.voice, v.replyLimit, v.chatModel, v.prompt))
sb.WriteString(fmt.Sprintf(",voice=%v,limit=%v,model=%v,window=%v,prompt:%v",
v.voice, v.replyLimit, v.chatModel, v.chatWindow, v.prompt))
return sb.String()
}

Expand Down Expand Up @@ -1227,10 +1229,17 @@ func doConfig(ctx context.Context) error {
return errors.Wrapf(err, "parse AIT_REPLY_LIMIT %v", os.Getenv("AIT_REPLY_LIMIT"))
}

globalChatWindow, err := strconv.ParseInt(os.Getenv("AIT_CHAT_WINDOW"), 10, 64)
if err != nil {
return errors.Wrapf(err, "parse AIT_CHAT_WINDOW %v", os.Getenv("AIT_CHAT_WINDOW"))
}

if os.Getenv("AIT_DEFAULT_ROBOT") == "true" {
robots = append(robots, &Robot{
uuid: "default", label: "Default", asrLanguage: os.Getenv("AIT_ASR_LANGUAGE"),
replyLimit: int(globalReplylimit), prompt: os.Getenv("AIT_SYSTEM_PROMPT"), voice: "hello-english.aac",
uuid: "default", label: "Default", prompt: os.Getenv("AIT_SYSTEM_PROMPT"),
asrLanguage: os.Getenv("AIT_ASR_LANGUAGE"), prefix: os.Getenv("AIT_REPLY_PREFIX"),
voice: "hello-english.aac", replyLimit: int(globalReplylimit),
chatModel: os.Getenv("AIT_CHAT_MODEL"), chatWindow: int(globalChatWindow),
})
}

Expand Down Expand Up @@ -1259,13 +1268,24 @@ func doConfig(ctx context.Context) error {
chatModel = os.Getenv("AIT_CHAT_MODEL")
}

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

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))
prefix := os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_PREFIX", i))
asrLanguage := os.Getenv(fmt.Sprintf("AIT_ROBOT_%v_ASR_LANGUAGE", i))

robots = append(robots, &Robot{
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)),
uuid: uuid, label: label, prompt: prompt, asrLanguage: asrLanguage, prefix: prefix,
voice: voice, replyLimit: replyLimit, chatModel: chatModel, chatWindow: chatWindow,
})
}
}
Expand Down

0 comments on commit 6e5db20

Please sign in to comment.