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

Function demonstrateParameters

examples/recipe/main.go:198–275  ·  view source on GitHub ↗

演示参数化

(tmpDir string)

Source from the content-addressed store, hash-verified

196
197// 演示参数化
198func demonstrateParameters(tmpDir string) {
199 fmt.Println("\n📋 参数化 Recipe")
200 fmt.Println(repeatStr("-", 50))
201
202 yamlContent := `
203version: "1.0"
204title: Project Generator
205description: 生成项目模板的 AI 助手
206
207parameters:
208 - key: project_name
209 input_type: string
210 requirement: required
211 description: 项目名称
212 default: my-project
213
214 - key: language
215 input_type: select
216 requirement: required
217 description: 编程语言
218 default: go
219 options:
220 - go
221 - python
222 - typescript
223 - rust
224
225 - key: with_tests
226 input_type: boolean
227 requirement: optional
228 description: 是否包含测试模板
229 default: "true"
230
231 - key: license
232 input_type: select
233 requirement: optional
234 description: 开源许可证
235 options:
236 - MIT
237 - Apache-2.0
238 - GPL-3.0
239
240prompt: |
241 请为我创建一个名为 {{project_name}} 的 {{language}} 项目。
242 {{#if with_tests}}包含测试模板。{{/if}}
243 {{#if license}}使用 {{license}} 许可证。{{/if}}
244
245tools:
246 - Write
247 - Bash
248`
249
250 yamlPath := filepath.Join(tmpDir, "project-generator.yaml")
251 if err := os.WriteFile(yamlPath, []byte(yamlContent), 0644); err != nil {
252 log.Fatalf("写入 YAML 失败: %v", err)
253 }
254
255 r, err := recipe.LoadFromFile(yamlPath)

Callers 1

mainFunction · 0.85

Calls 4

LoadFromFileFunction · 0.92
PrintfMethod · 0.80
repeatStrFunction · 0.70
JoinMethod · 0.45

Tested by

no test coverage detected