docs: suites-help/示例代码/Hello-World.md
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
# Hello World 套件
|
||||
|
||||
## 完整代码
|
||||
|
||||
最小的可工作套件,接收一个文本参数并输出。
|
||||
|
||||
### workflow.yaml
|
||||
|
||||
```yaml
|
||||
name: hello-world
|
||||
description: 输出用户输入的文本
|
||||
version: 1.0.0
|
||||
category: utility
|
||||
|
||||
params:
|
||||
type: object
|
||||
required:
|
||||
- message
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
description: 要输出的文本
|
||||
|
||||
steps:
|
||||
- id: say-hello
|
||||
name: 输出信息
|
||||
script_id: run
|
||||
params:
|
||||
message: "${{inputs.message}}"
|
||||
|
||||
resolved_params:
|
||||
- step_index: 0
|
||||
step_name: 输出信息
|
||||
params:
|
||||
message: "Hello, AgentGIS!"
|
||||
```
|
||||
|
||||
### scripts/run.py
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import json, os
|
||||
|
||||
params_file = os.environ.get("PARAMS_FILE", "/tmp/params.json")
|
||||
with open(params_file) as f:
|
||||
params = json.load(f)
|
||||
|
||||
message = params.get("message", "Hello!")
|
||||
|
||||
result = {
|
||||
"output": message,
|
||||
"length": len(message)
|
||||
}
|
||||
print(json.dumps(result))
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
# 打包
|
||||
tar czf scripts.tar.gz workflow.yaml scripts/
|
||||
|
||||
# 发布后执行
|
||||
agc run <suite-id> --inputs '{"message": "你好,AgentGIS!"}'
|
||||
```
|
||||
|
||||
完整代码参考:`SuiteHub/hello-world-suite`
|
||||
Reference in New Issue
Block a user