feat: allow selecting chat models in ASR and weather examples
Parse --model in main with mini-chat as the default, and pass the selected model to the OpenAI chat model configuration. Keep argument parsing out of init so entrypoint tests can initialize their own flags. Co-authored-by: TRAE CLI <traecli@bytedance.com>
This commit is contained in:
1 parent
1512f0516f
commit
587f61bc03
4 files changed
+24
-6
No files matched your search
@@ -8,11 +8,11 @@ import (
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
)
|
||||
|
||||
func MustNewChatModel(ctx context.Context) *openai.ChatModel {
|
||||
func MustNewChatModel(ctx context.Context, model string) *openai.ChatModel {
|
||||
chat, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
|
||||
APIKey: os.Getenv("AI_KEY"),
|
||||
BaseURL: "https://ai.loveuer.com/v1",
|
||||
Model: "mini-chat",
|
||||
Model: model,
|
||||
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
+10
-1
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -13,7 +14,15 @@ import (
|
||||
"example.com/ueino/steps/asr/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
modelName string
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&modelName, "model", "mini-chat", "聊天模型名称")
|
||||
flag.Parse()
|
||||
|
||||
log.Printf("[D] use model = %s", modelName)
|
||||
asr := &provider.ASR{
|
||||
BaseURL: "ws://127.0.0.1:8000/v1", // TODO:填写 WebSocket 服务前缀,如 wss://example.com/v1。
|
||||
Model: "moss-asr",
|
||||
@@ -32,7 +41,7 @@ func main() {
|
||||
}
|
||||
|
||||
func run(ctx context.Context, asr *provider.ASR) error {
|
||||
chain, err := internal.NewChain(ctx, asr, internal.MustNewChatModel(ctx), func(event internal.Transcript) {
|
||||
chain, err := internal.NewChain(ctx, asr, internal.MustNewChatModel(ctx, modelName), func(event internal.Transcript) {
|
||||
switch event.Kind {
|
||||
case internal.Final:
|
||||
fmt.Printf("\n转写结果:%s\n\n助手> ", event.Text)
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
)
|
||||
|
||||
func MustNewChatModel(ctx context.Context) *openai.ChatModel {
|
||||
func MustNewChatModel(ctx context.Context, model string) *openai.ChatModel {
|
||||
chat, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
|
||||
APIKey: os.Getenv("AI_KEY"),
|
||||
BaseURL: "https://ai.loveuer.com/v1",
|
||||
Model: "mini-chat",
|
||||
Model: model,
|
||||
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
+10
-1
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -20,7 +21,15 @@ import (
|
||||
"github.com/cloudwego/eino/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
modelName string
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&modelName, "model", "mini-chat", "聊天模型名称")
|
||||
flag.Parse()
|
||||
|
||||
log.Printf("[D] use model = %s", modelName)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
signals := make(chan os.Signal, 1)
|
||||
@@ -40,7 +49,7 @@ func main() {
|
||||
assistant, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
|
||||
Name: "terminal_chat",
|
||||
Instruction: opt.SYSTEM_PROMPT,
|
||||
Model: internal.MustNewChatModel(ctx),
|
||||
Model: internal.MustNewChatModel(ctx, modelName),
|
||||
MaxIterations: 10,
|
||||
ToolsConfig: adk.ToolsConfig{
|
||||
ToolsNodeConfig: compose.ToolsNodeConfig{
|
||||
|
||||
Reference in new issue
Block a user