agent-builder-gateway-sdk 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of agent-builder-gateway-sdk might be problematic. Click here for more details.
- agent_builder_gateway_sdk-0.2.0/.github/workflows/publish.yml +52 -0
- agent_builder_gateway_sdk-0.2.0/.github/workflows/test.yml +48 -0
- agent_builder_gateway_sdk-0.2.0/.gitignore +55 -0
- agent_builder_gateway_sdk-0.2.0/LICENSE +22 -0
- agent_builder_gateway_sdk-0.2.0/PKG-INFO +288 -0
- agent_builder_gateway_sdk-0.2.0/README.md +268 -0
- agent_builder_gateway_sdk-0.2.0/RELEASE_GUIDE.md +197 -0
- agent_builder_gateway_sdk-0.2.0/examples/basic_usage.py +170 -0
- agent_builder_gateway_sdk-0.2.0/examples/streaming.py +193 -0
- agent_builder_gateway_sdk-0.2.0/pyproject.toml +52 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/__init__.py +32 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/auth.py +49 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/client.py +236 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/exceptions.py +72 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/models.py +114 -0
- agent_builder_gateway_sdk-0.2.0/src/gateway_sdk/streaming.py +41 -0
- agent_builder_gateway_sdk-0.2.0/tests/__init__.py +2 -0
- agent_builder_gateway_sdk-0.2.0/tests/test_models.py +50 -0
- agent_builder_gateway_sdk-0.2.0/uv.lock +632 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build-and-publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.11'
|
|
23
|
+
|
|
24
|
+
- name: Install uv
|
|
25
|
+
run: |
|
|
26
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
27
|
+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: |
|
|
31
|
+
uv sync --dev
|
|
32
|
+
|
|
33
|
+
- name: Build package
|
|
34
|
+
run: |
|
|
35
|
+
uv build
|
|
36
|
+
|
|
37
|
+
- name: Publish to PyPI
|
|
38
|
+
env:
|
|
39
|
+
TWINE_USERNAME: __token__
|
|
40
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
|
41
|
+
run: |
|
|
42
|
+
uv pip install twine
|
|
43
|
+
uv run twine upload dist/*
|
|
44
|
+
|
|
45
|
+
- name: Create GitHub Release
|
|
46
|
+
uses: softprops/action-gh-release@v1
|
|
47
|
+
with:
|
|
48
|
+
files: dist/*
|
|
49
|
+
generate_release_notes: true
|
|
50
|
+
env:
|
|
51
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
52
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ['3.11', '3.12']
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout code
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install uv
|
|
26
|
+
run: |
|
|
27
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
28
|
+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: |
|
|
32
|
+
uv sync --dev
|
|
33
|
+
|
|
34
|
+
- name: Run linters
|
|
35
|
+
run: |
|
|
36
|
+
uv run ruff check src/
|
|
37
|
+
uv run mypy src/
|
|
38
|
+
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: |
|
|
41
|
+
uv run pytest tests/ -v --cov=gateway_sdk --cov-report=xml
|
|
42
|
+
|
|
43
|
+
- name: Upload coverage
|
|
44
|
+
uses: codecov/codecov-action@v3
|
|
45
|
+
with:
|
|
46
|
+
file: ./coverage.xml
|
|
47
|
+
fail_ci_if_error: false
|
|
48
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
MANIFEST
|
|
23
|
+
|
|
24
|
+
# Virtual Environment
|
|
25
|
+
venv/
|
|
26
|
+
ENV/
|
|
27
|
+
env/
|
|
28
|
+
.venv
|
|
29
|
+
|
|
30
|
+
# IDEs
|
|
31
|
+
.vscode/
|
|
32
|
+
.idea/
|
|
33
|
+
*.swp
|
|
34
|
+
*.swo
|
|
35
|
+
*~
|
|
36
|
+
.DS_Store
|
|
37
|
+
|
|
38
|
+
# Testing
|
|
39
|
+
.pytest_cache/
|
|
40
|
+
.coverage
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
|
|
44
|
+
# Type checking
|
|
45
|
+
.mypy_cache/
|
|
46
|
+
.dmypy.json
|
|
47
|
+
dmypy.json
|
|
48
|
+
|
|
49
|
+
# uv
|
|
50
|
+
.uv/
|
|
51
|
+
|
|
52
|
+
# Distribution
|
|
53
|
+
*.whl
|
|
54
|
+
*.tar.gz
|
|
55
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Agent Builder Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-builder-gateway-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python SDK for Agent Builder Gateway - 用于 AI 构建的程序调用预制件
|
|
5
|
+
Author: Agent Builder Team
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: httpx>=0.27.0
|
|
10
|
+
Requires-Dist: pydantic>=2.0.0
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: black>=24.0.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Gateway SDK
|
|
22
|
+
|
|
23
|
+
Python SDK for Gateway - 用于调用预制件
|
|
24
|
+
|
|
25
|
+
## 概述
|
|
26
|
+
|
|
27
|
+
Gateway SDK 是一个用于调用预制件的 Python SDK。
|
|
28
|
+
|
|
29
|
+
### 核心特性
|
|
30
|
+
|
|
31
|
+
- ✅ 简洁的 API
|
|
32
|
+
- ✅ 支持 JWT Token 和 API Key 认证
|
|
33
|
+
- ✅ 流式响应支持(SSE)
|
|
34
|
+
- ✅ 完整的类型提示
|
|
35
|
+
- ✅ 完善的错误处理
|
|
36
|
+
|
|
37
|
+
## 安装
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install agent-builder-gateway-sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 快速开始
|
|
44
|
+
|
|
45
|
+
### 初始化客户端
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from gateway_sdk import GatewayClient
|
|
49
|
+
|
|
50
|
+
# 使用 JWT Token
|
|
51
|
+
client = GatewayClient(jwt_token="your-jwt-token")
|
|
52
|
+
|
|
53
|
+
# 或使用 API Key
|
|
54
|
+
client = GatewayClient(api_key="sk-xxx")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 调用预制件
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
result = client.run(
|
|
61
|
+
prefab_id="llm-client",
|
|
62
|
+
version="1.0.0",
|
|
63
|
+
function_name="chat",
|
|
64
|
+
parameters={"messages": [{"role": "user", "content": "Hello"}]}
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
if result.is_success():
|
|
68
|
+
print(result.get_result())
|
|
69
|
+
else:
|
|
70
|
+
print(f"Error: {result.error}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 链式调用
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
llm = client.prefab("llm-client", "1.0.0")
|
|
77
|
+
result = llm.call("chat", messages=[...], model="gpt-4")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 流式响应
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
for event in client.run(..., stream=True):
|
|
84
|
+
if event.type == "content":
|
|
85
|
+
print(event.data, end="", flush=True)
|
|
86
|
+
elif event.type == "done":
|
|
87
|
+
print("\n完成")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 批量调用
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from gateway_sdk import PrefabCall
|
|
94
|
+
|
|
95
|
+
calls = [
|
|
96
|
+
PrefabCall(
|
|
97
|
+
prefab_id="translator",
|
|
98
|
+
version="1.0.0",
|
|
99
|
+
function_name="translate",
|
|
100
|
+
parameters={"text": "Hello", "target": "zh"}
|
|
101
|
+
),
|
|
102
|
+
PrefabCall(
|
|
103
|
+
prefab_id="translator",
|
|
104
|
+
version="1.0.0",
|
|
105
|
+
function_name="translate",
|
|
106
|
+
parameters={"text": "World", "target": "zh"}
|
|
107
|
+
)
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
result = client.run_batch(calls)
|
|
111
|
+
for r in result.results:
|
|
112
|
+
if r.is_success():
|
|
113
|
+
print(r.get_result())
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 文件处理
|
|
117
|
+
|
|
118
|
+
**重要**: SDK 只接收 S3 URL,不负责文件上传/下载。
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
# 传递 S3 URL 作为文件输入
|
|
122
|
+
result = client.run(
|
|
123
|
+
prefab_id="video-processor",
|
|
124
|
+
version="1.0.0",
|
|
125
|
+
function_name="extract_audio",
|
|
126
|
+
parameters={"format": "mp3"},
|
|
127
|
+
files={"video": ["s3://bucket/input.mp4"]}
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# 输出文件也是 S3 URL
|
|
131
|
+
output_files = result.get_files()
|
|
132
|
+
# {"audio": ["s3://bucket/output.mp3"]}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**文件处理流程**:
|
|
136
|
+
1. 📤 使用 S3 客户端上传文件,获取 S3 URL
|
|
137
|
+
2. 📝 将 S3 URL 传递给 SDK
|
|
138
|
+
3. 📥 从返回的 S3 URL 下载结果文件
|
|
139
|
+
|
|
140
|
+
## API 参考
|
|
141
|
+
|
|
142
|
+
### GatewayClient
|
|
143
|
+
|
|
144
|
+
#### 初始化
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
GatewayClient(
|
|
148
|
+
base_url: str = "http://nodeport.sensedeal.vip:30566",
|
|
149
|
+
api_key: Optional[str] = None,
|
|
150
|
+
jwt_token: Optional[str] = None,
|
|
151
|
+
timeout: int = 60
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**参数**:
|
|
156
|
+
- `api_key`: API Key
|
|
157
|
+
- `jwt_token`: JWT Token
|
|
158
|
+
- `timeout`: 请求超时时间(秒)
|
|
159
|
+
|
|
160
|
+
**注意**:必须提供 `api_key` 或 `jwt_token` 之一。
|
|
161
|
+
|
|
162
|
+
#### 方法
|
|
163
|
+
|
|
164
|
+
**run()** - 执行单个预制件
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
run(
|
|
168
|
+
prefab_id: str,
|
|
169
|
+
version: str,
|
|
170
|
+
function_name: str,
|
|
171
|
+
parameters: Dict[str, Any],
|
|
172
|
+
files: Optional[Dict[str, List[str]]] = None, # 仅接受 S3 URL
|
|
173
|
+
stream: bool = False
|
|
174
|
+
) -> Union[PrefabResult, Iterator[StreamEvent]]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
参数:
|
|
178
|
+
- `files`: 文件输入,格式为 `{"参数名": ["s3://url1", "s3://url2"]}`,**仅接受 S3 URL**
|
|
179
|
+
|
|
180
|
+
**run_batch()** - 批量执行
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
run_batch(calls: List[PrefabCall]) -> BatchResult
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**prefab()** - 获取预制件对象
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
prefab(prefab_id: str, version: str) -> Prefab
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**list_prefabs()** - 列出预制件
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
list_prefabs(status: Optional[str] = None) -> List[PrefabInfo]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**get_prefab_spec()** - 获取预制件规格
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
get_prefab_spec(prefab_id: str, version: Optional[str] = None) -> Dict[str, Any]
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### PrefabResult
|
|
205
|
+
|
|
206
|
+
预制件执行结果。
|
|
207
|
+
|
|
208
|
+
**属性**:
|
|
209
|
+
- `status`: 调用状态(SUCCESS / FAILED)
|
|
210
|
+
- `output`: 输出数据
|
|
211
|
+
- `error`: 错误信息
|
|
212
|
+
- `job_id`: 任务 ID
|
|
213
|
+
|
|
214
|
+
**方法**:
|
|
215
|
+
- `is_success()`: 判断是否成功
|
|
216
|
+
- `get(key, default)`: 获取输出字段
|
|
217
|
+
- `get_result()`: 获取业务结果
|
|
218
|
+
- `get_files()`: 获取输出文件
|
|
219
|
+
|
|
220
|
+
### StreamEvent
|
|
221
|
+
|
|
222
|
+
流式事件。
|
|
223
|
+
|
|
224
|
+
**属性**:
|
|
225
|
+
- `type`: 事件类型(start / content / progress / done / error)
|
|
226
|
+
- `data`: 事件数据
|
|
227
|
+
|
|
228
|
+
## 错误处理
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from gateway_sdk.exceptions import (
|
|
232
|
+
GatewayError,
|
|
233
|
+
AuthenticationError,
|
|
234
|
+
PrefabNotFoundError,
|
|
235
|
+
ValidationError,
|
|
236
|
+
QuotaExceededError,
|
|
237
|
+
ServiceUnavailableError,
|
|
238
|
+
MissingSecretError,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
result = client.run(...)
|
|
243
|
+
except AuthenticationError as e:
|
|
244
|
+
print(f"认证失败: {e}")
|
|
245
|
+
except PrefabNotFoundError as e:
|
|
246
|
+
print(f"预制件不存在: {e}")
|
|
247
|
+
except MissingSecretError as e:
|
|
248
|
+
print(f"缺少密钥: {e.secret_name}")
|
|
249
|
+
except QuotaExceededError as e:
|
|
250
|
+
print(f"配额超限: {e.used}/{e.limit}")
|
|
251
|
+
except GatewayError as e:
|
|
252
|
+
print(f"错误: {e}")
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## 示例代码
|
|
256
|
+
|
|
257
|
+
- `examples/basic_usage.py` - 基础用法
|
|
258
|
+
- `examples/streaming.py` - 流式响应
|
|
259
|
+
|
|
260
|
+
## 常见问题
|
|
261
|
+
|
|
262
|
+
**Q: 如何处理超时?**
|
|
263
|
+
|
|
264
|
+
A: 设置 `timeout` 参数:
|
|
265
|
+
```python
|
|
266
|
+
client = GatewayClient(jwt_token="...", timeout=120)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Q: 如何调试?**
|
|
270
|
+
|
|
271
|
+
A: 启用日志:
|
|
272
|
+
```python
|
|
273
|
+
import logging
|
|
274
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Q: 如何停止流式响应?**
|
|
278
|
+
|
|
279
|
+
A: 使用 `break` 跳出循环:
|
|
280
|
+
```python
|
|
281
|
+
for event in client.run(..., stream=True):
|
|
282
|
+
if some_condition:
|
|
283
|
+
break
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## 许可证
|
|
287
|
+
|
|
288
|
+
MIT License
|