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"
|
"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{
|
chat, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
|
||||||
APIKey: os.Getenv("AI_KEY"),
|
APIKey: os.Getenv("AI_KEY"),
|
||||||
BaseURL: "https://ai.loveuer.com/v1",
|
BaseURL: "https://ai.loveuer.com/v1",
|
||||||
Model: "mini-chat",
|
Model: model,
|
||||||
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+10
-1
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -13,7 +14,15 @@ import (
|
|||||||
"example.com/ueino/steps/asr/internal"
|
"example.com/ueino/steps/asr/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
modelName string
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.StringVar(&modelName, "model", "mini-chat", "聊天模型名称")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
log.Printf("[D] use model = %s", modelName)
|
||||||
asr := &provider.ASR{
|
asr := &provider.ASR{
|
||||||
BaseURL: "ws://127.0.0.1:8000/v1", // TODO:填写 WebSocket 服务前缀,如 wss://example.com/v1。
|
BaseURL: "ws://127.0.0.1:8000/v1", // TODO:填写 WebSocket 服务前缀,如 wss://example.com/v1。
|
||||||
Model: "moss-asr",
|
Model: "moss-asr",
|
||||||
@@ -32,7 +41,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(ctx context.Context, asr *provider.ASR) error {
|
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 {
|
switch event.Kind {
|
||||||
case internal.Final:
|
case internal.Final:
|
||||||
fmt.Printf("\n转写结果:%s\n\n助手> ", event.Text)
|
fmt.Printf("\n转写结果:%s\n\n助手> ", event.Text)
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import (
|
|||||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
"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{
|
chat, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
|
||||||
APIKey: os.Getenv("AI_KEY"),
|
APIKey: os.Getenv("AI_KEY"),
|
||||||
BaseURL: "https://ai.loveuer.com/v1",
|
BaseURL: "https://ai.loveuer.com/v1",
|
||||||
Model: "mini-chat",
|
Model: model,
|
||||||
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
ReasoningEffort: openai.ReasoningEffortLevelLow,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+10
-1
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -20,7 +21,15 @@ import (
|
|||||||
"github.com/cloudwego/eino/schema"
|
"github.com/cloudwego/eino/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
modelName string
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.StringVar(&modelName, "model", "mini-chat", "聊天模型名称")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
log.Printf("[D] use model = %s", modelName)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
signals := make(chan os.Signal, 1)
|
signals := make(chan os.Signal, 1)
|
||||||
@@ -40,7 +49,7 @@ func main() {
|
|||||||
assistant, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
|
assistant, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
|
||||||
Name: "terminal_chat",
|
Name: "terminal_chat",
|
||||||
Instruction: opt.SYSTEM_PROMPT,
|
Instruction: opt.SYSTEM_PROMPT,
|
||||||
Model: internal.MustNewChatModel(ctx),
|
Model: internal.MustNewChatModel(ctx, modelName),
|
||||||
MaxIterations: 10,
|
MaxIterations: 10,
|
||||||
ToolsConfig: adk.ToolsConfig{
|
ToolsConfig: adk.ToolsConfig{
|
||||||
ToolsNodeConfig: compose.ToolsNodeConfig{
|
ToolsNodeConfig: compose.ToolsNodeConfig{
|
||||||
|
|||||||
Reference in new issue
Block a user