fix(#8): Hello-World 示例 — 统一为 script_id + $params.xxx 格式
This commit is contained in:
@@ -1,61 +1,65 @@
|
||||
# Hello World 套件
|
||||
# Hello, World! 套件示例
|
||||
|
||||
## 完整代码
|
||||
一个最简单的套件,演示 workflow.yaml 和脚本结构。
|
||||
|
||||
最小的可工作套件,接收一个文本参数并输出。
|
||||
## 文件结构
|
||||
|
||||
### workflow.yaml
|
||||
```
|
||||
hello-world/
|
||||
├── workflow.yaml
|
||||
└── scripts/
|
||||
└── run.py
|
||||
```
|
||||
|
||||
## workflow.yaml
|
||||
|
||||
```yaml
|
||||
name: hello-world
|
||||
description: 输出用户输入的文本
|
||||
name: Hello World
|
||||
description: 首个 AgentGIS 套件,接收一条消息并在容器中打印
|
||||
version: 1.0.0
|
||||
category: utility
|
||||
author: SuiteForge
|
||||
tags: [示例, 入门]
|
||||
|
||||
params:
|
||||
type: object
|
||||
required:
|
||||
- message
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
description: 要输出的文本
|
||||
message:
|
||||
type: string
|
||||
required: true
|
||||
desc: 要打印的消息
|
||||
|
||||
base_image: gis-base:latest
|
||||
|
||||
steps:
|
||||
- id: say-hello
|
||||
name: 输出信息
|
||||
script: run
|
||||
- id: hello
|
||||
name: 打印消息
|
||||
script_id: run
|
||||
params:
|
||||
message: $params.message
|
||||
```
|
||||
|
||||
### scripts/run.py
|
||||
## scripts/run.py
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import json, os
|
||||
import sys, json
|
||||
|
||||
params_file = os.environ.get("PARAMS_FILE", "/tmp/params.json")
|
||||
with open(params_file) as f:
|
||||
params = json.load(f)
|
||||
def run(params):
|
||||
message = params.get("message", "Hello, AgentGIS!")
|
||||
print(f"📢 {message}")
|
||||
return {
|
||||
"status": "completed",
|
||||
"message": message,
|
||||
}
|
||||
|
||||
message = params.get("message", "Hello!")
|
||||
|
||||
result = {
|
||||
"output": message,
|
||||
"length": len(message)
|
||||
}
|
||||
print(json.dumps(result))
|
||||
if __name__ == "__main__":
|
||||
params = json.loads(sys.argv[1]) if len(sys.argv) > 1 else {}
|
||||
result = run(params)
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
```
|
||||
|
||||
## 测试
|
||||
## 执行
|
||||
|
||||
```bash
|
||||
# 打包
|
||||
tar czf hello-world.tgz workflow.yaml scripts/
|
||||
|
||||
# 通过 API 发布后执行
|
||||
agc run /tmp/output --suite-id <suite-id> --input message="Hello, AgentGIS!"
|
||||
agc run /tmp/hello-output \
|
||||
--suite-id <your-suite-id> \
|
||||
--input message="你好,AgentGIS!"
|
||||
```
|
||||
|
||||
完整代码参考:`SuiteHub/hello-world-suite`
|
||||
|
||||
Reference in New Issue
Block a user