MCPcopy Create free account
hub / github.com/astercloud/aster / run

Function run

examples/openrouter/main.go:56–87  ·  view source on GitHub ↗
(ctx context.Context, cmd *cli.Command)

Source from the content-addressed store, hash-verified

54}
55
56func run(ctx context.Context, cmd *cli.Command) error {
57 // 检查 API Key
58 apiKey := os.Getenv("OPENROUTER_API_KEY")
59 if apiKey == "" {
60 return errors.New("需要设置 OPENROUTER_API_KEY 环境变量")
61 }
62
63 baseURL := os.Getenv("OPENROUTER_BASE_URL")
64 if baseURL == "" {
65 baseURL = "https://openrouter.ai/api/v1"
66 }
67
68 // 获取参数
69 prompt := cmd.String("print")
70 streaming := cmd.Bool("stream")
71 model := cmd.String("model")
72
73 // 创建 Agent
74 ag, err := createAgent(apiKey, baseURL, model, streaming)
75 if err != nil {
76 return fmt.Errorf("创建 Agent 失败: %w", err)
77 }
78 defer func() { _ = ag.Close() }()
79
80 // 非交互模式
81 if prompt != "" {
82 return runOnce(ctx, ag, prompt)
83 }
84
85 // 交互模式
86 return runInteractive(ctx, ag)
87}
88
89// runOnce 非交互模式:执行单次对话并退出
90func runOnce(ctx context.Context, ag *agent.Agent, prompt string) error {

Callers

nothing calls this directly

Calls 5

runOnceFunction · 0.85
runInteractiveFunction · 0.85
createAgentFunction · 0.70
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected