ai302 0.1.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.
- ai302-0.1.0/.gitignore +63 -0
- ai302-0.1.0/AGENTS.md +65 -0
- ai302-0.1.0/CLAUDE.md +1 -0
- ai302-0.1.0/PKG-INFO +260 -0
- ai302-0.1.0/README.md +250 -0
- ai302-0.1.0/ai302/__init__.py +3 -0
- ai302-0.1.0/ai302/__main__.py +5 -0
- ai302-0.1.0/ai302/api/__init__.py +0 -0
- ai302-0.1.0/ai302/api/http_client.py +74 -0
- ai302-0.1.0/ai302/api/image.py +117 -0
- ai302-0.1.0/ai302/api/record.py +16 -0
- ai302-0.1.0/ai302/api/tts.py +82 -0
- ai302-0.1.0/ai302/api/video.py +68 -0
- ai302-0.1.0/ai302/cli/__init__.py +0 -0
- ai302-0.1.0/ai302/cli/app.py +35 -0
- ai302-0.1.0/ai302/cli/common.py +33 -0
- ai302-0.1.0/ai302/cli/history.py +47 -0
- ai302-0.1.0/ai302/cli/image.py +359 -0
- ai302-0.1.0/ai302/cli/model.py +45 -0
- ai302-0.1.0/ai302/cli/task.py +58 -0
- ai302-0.1.0/ai302/cli/tts.py +254 -0
- ai302-0.1.0/ai302/cli/video.py +246 -0
- ai302-0.1.0/ai302/core/__init__.py +0 -0
- ai302-0.1.0/ai302/core/config.py +48 -0
- ai302-0.1.0/ai302/core/errors.py +13 -0
- ai302-0.1.0/ai302/core/history.py +85 -0
- ai302-0.1.0/ai302/core/models.py +20 -0
- ai302-0.1.0/ai302/core/redact.py +21 -0
- ai302-0.1.0/ai302/core/task_store.py +49 -0
- ai302-0.1.0/ai302/core/tts_cache.py +86 -0
- ai302-0.1.0/ai302/core/yaml_edit.py +268 -0
- ai302-0.1.0/doc/api.md +562 -0
- ai302-0.1.0/main.py +5 -0
- ai302-0.1.0/pyproject.toml +21 -0
ai302-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# --- Secrets / local config ---
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
*.env
|
|
5
|
+
*.key
|
|
6
|
+
*.pem
|
|
7
|
+
*.p12
|
|
8
|
+
*.pfx
|
|
9
|
+
*.crt
|
|
10
|
+
*.cer
|
|
11
|
+
*.der
|
|
12
|
+
*.jks
|
|
13
|
+
credentials.json
|
|
14
|
+
secrets*.json
|
|
15
|
+
*secret*
|
|
16
|
+
*token*
|
|
17
|
+
|
|
18
|
+
# Local user config produced by this CLI (default: ~/.ai302)
|
|
19
|
+
# Kept here in case user overrides AI302_CONFIG_DIR into the repo
|
|
20
|
+
.ai302/
|
|
21
|
+
**/.ai302/
|
|
22
|
+
**/history.jsonl
|
|
23
|
+
**/tasks/
|
|
24
|
+
**/config.json
|
|
25
|
+
|
|
26
|
+
# --- Python ---
|
|
27
|
+
__pycache__/
|
|
28
|
+
*.py[cod]
|
|
29
|
+
*$py.class
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
.coverage
|
|
32
|
+
.coverage.*
|
|
33
|
+
htmlcov/
|
|
34
|
+
.mypy_cache/
|
|
35
|
+
.pytype/
|
|
36
|
+
.ruff_cache/
|
|
37
|
+
.pyre/
|
|
38
|
+
|
|
39
|
+
# Virtual environments
|
|
40
|
+
.venv/
|
|
41
|
+
venv/
|
|
42
|
+
ENV/
|
|
43
|
+
|
|
44
|
+
# Build / packaging
|
|
45
|
+
build/
|
|
46
|
+
dist/
|
|
47
|
+
*.egg-info/
|
|
48
|
+
.eggs/
|
|
49
|
+
|
|
50
|
+
# Jupyter
|
|
51
|
+
.ipynb_checkpoints/
|
|
52
|
+
|
|
53
|
+
# IDEs / editors
|
|
54
|
+
.vscode/
|
|
55
|
+
.idea/
|
|
56
|
+
*.iml
|
|
57
|
+
|
|
58
|
+
# OS files
|
|
59
|
+
.DS_Store
|
|
60
|
+
Thumbs.db
|
|
61
|
+
|
|
62
|
+
# Claude Code / local tooling
|
|
63
|
+
.claude/
|
ai302-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
|
|
2
|
+
|
|
3
|
+
**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
|
|
4
|
+
|
|
5
|
+
## 1. Think Before Coding
|
|
6
|
+
|
|
7
|
+
**Don't assume. Don't hide confusion. Surface tradeoffs.**
|
|
8
|
+
|
|
9
|
+
Before implementing:
|
|
10
|
+
- State your assumptions explicitly. If uncertain, ask.
|
|
11
|
+
- If multiple interpretations exist, present them - don't pick silently.
|
|
12
|
+
- If a simpler approach exists, say so. Push back when warranted.
|
|
13
|
+
- If something is unclear, stop. Name what's confusing. Ask.
|
|
14
|
+
|
|
15
|
+
## 2. Simplicity First
|
|
16
|
+
|
|
17
|
+
**Minimum code that solves the problem. Nothing speculative.**
|
|
18
|
+
|
|
19
|
+
- No features beyond what was asked.
|
|
20
|
+
- No abstractions for single-use code.
|
|
21
|
+
- No "flexibility" or "configurability" that wasn't requested.
|
|
22
|
+
- No error handling for impossible scenarios.
|
|
23
|
+
- If you write 200 lines and it could be 50, rewrite it.
|
|
24
|
+
|
|
25
|
+
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
|
|
26
|
+
|
|
27
|
+
## 3. Surgical Changes
|
|
28
|
+
|
|
29
|
+
**Touch only what you must. Clean up only your own mess.**
|
|
30
|
+
|
|
31
|
+
When editing existing code:
|
|
32
|
+
- Don't "improve" adjacent code, comments, or formatting.
|
|
33
|
+
- Don't refactor things that aren't broken.
|
|
34
|
+
- Match existing style, even if you'd do it differently.
|
|
35
|
+
- If you notice unrelated dead code, mention it - don't delete it.
|
|
36
|
+
|
|
37
|
+
When your changes create orphans:
|
|
38
|
+
- Remove imports/variables/functions that YOUR changes made unused.
|
|
39
|
+
- Don't remove pre-existing dead code unless asked.
|
|
40
|
+
|
|
41
|
+
The test: Every changed line should trace directly to the user's request.
|
|
42
|
+
|
|
43
|
+
## 4. Goal-Driven Execution
|
|
44
|
+
|
|
45
|
+
**Define success criteria. Loop until verified.**
|
|
46
|
+
|
|
47
|
+
Transform tasks into verifiable goals:
|
|
48
|
+
- "Add validation" → "Write tests for invalid inputs, then make them pass"
|
|
49
|
+
- "Fix the bug" → "Write a test that reproduces it, then make it pass"
|
|
50
|
+
- "Refactor X" → "Ensure tests pass before and after"
|
|
51
|
+
|
|
52
|
+
For multi-step tasks, state a brief plan:
|
|
53
|
+
```
|
|
54
|
+
1. [Step] → verify: [check]
|
|
55
|
+
2. [Step] → verify: [check]
|
|
56
|
+
3. [Step] → verify: [check]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
|
|
60
|
+
|
|
61
|
+
## Project-Specific Guidelines
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
|
ai302-0.1.0/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
ai302-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai302
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 302.ai unified CLI
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: httpx>=0.27
|
|
7
|
+
Requires-Dist: ruamel-yaml>=0.18
|
|
8
|
+
Requires-Dist: typer>=0.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# ai302 CLI
|
|
12
|
+
|
|
13
|
+
302.ai 统一命令行工具(输出均为单行 JSON,方便脚本处理)。
|
|
14
|
+
|
|
15
|
+
## Project architecture
|
|
16
|
+
|
|
17
|
+
代码按职责拆分为三层:
|
|
18
|
+
|
|
19
|
+
- `ai302/cli/`:Typer CLI 命令层(参数解析、统一 JSON 输出、写 history/快照)
|
|
20
|
+
- `ai302/cli/app.py`:CLI 根入口(挂载 model/video/image/tts/history 子命令)
|
|
21
|
+
- `ai302/cli/common.py`:公共工具(`resolve_api_key` / `print_json` / `parse_extra`)
|
|
22
|
+
- `ai302/cli/model.py`:默认模型配置(set/list)
|
|
23
|
+
- `ai302/cli/video.py`:视频异步任务(create/fetch)
|
|
24
|
+
- `ai302/cli/image.py`:图片同步生成(generate)
|
|
25
|
+
- `ai302/cli/tts.py`:TTS(refresh/providers/voices/create/fetch)
|
|
26
|
+
- `ai302/cli/history.py`:本地 history 查询(path/list)
|
|
27
|
+
|
|
28
|
+
- `ai302/api/`:HTTP API 封装层(只负责请求/返回 JSON,不做 CLI 交互)
|
|
29
|
+
- `ai302/api/http_client.py`:httpx 客户端、重试、统一错误 `AI302ApiError`、Base URL(`AI302_BASE_URL`)
|
|
30
|
+
- `ai302/api/video.py`:视频 create/fetch 请求封装
|
|
31
|
+
- `ai302/api/image.py`:图片 generate 请求封装
|
|
32
|
+
- `ai302/api/tts.py`:TTS provider/create/fetch 请求封装
|
|
33
|
+
|
|
34
|
+
- `ai302/core/`:本地能力层(配置/模型表/history/快照/缓存)
|
|
35
|
+
- `ai302/core/config.py`:本地配置读写(`$AI302_CONFIG_DIR/config.json`,默认模型等)
|
|
36
|
+
- `ai302/core/models.py`:内置 `SUPPORTED_MODELS` 静态表
|
|
37
|
+
- `ai302/core/history.py`:`history.jsonl` 追加与查询
|
|
38
|
+
- `ai302/core/task_store.py`:任务快照 `tasks/<taskid>.json` 写入/更新
|
|
39
|
+
- `ai302/core/tts_cache.py`:TTS providers 缓存读写与 voices 扁平化
|
|
40
|
+
|
|
41
|
+
入口文件:
|
|
42
|
+
- `ai302/__main__.py`:支持 `python -m ai302 ...`
|
|
43
|
+
- `pyproject.toml`:安装后命令 `ai302 ...` 的脚本入口
|
|
44
|
+
|
|
45
|
+
## Install (dev)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python -m pip install -U pip
|
|
49
|
+
python -m pip install -e .
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Run (no install)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python -m ai302 -h
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Environment
|
|
59
|
+
|
|
60
|
+
- API Key:`AI302_KEY`(也可以每次传 `--api_key`)
|
|
61
|
+
- Base URL:`AI302_BASE_URL`(默认 `https://api.302.ai`)
|
|
62
|
+
- Config dir:`AI302_CONFIG_DIR`(默认 `~/.ai302`)
|
|
63
|
+
|
|
64
|
+
PowerShell:
|
|
65
|
+
|
|
66
|
+
```powershell
|
|
67
|
+
$env:AI302_KEY="YOUR_KEY"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Models
|
|
71
|
+
|
|
72
|
+
模型按任务类型分组:
|
|
73
|
+
- 视频:`t2v` / `i2v`
|
|
74
|
+
- 图片:`t2i` / `i2i`
|
|
75
|
+
|
|
76
|
+
查看当前内置支持模型:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
python -m ai302 model list t2v
|
|
80
|
+
python -m ai302 model get t2v --random
|
|
81
|
+
python -m ai302 model list t2i
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
设置默认模型(写入本地配置):
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ai302 model set t2v minimaxi-t2v-01
|
|
88
|
+
ai302 model set i2v minimaxi-hailuo-2.3-fast
|
|
89
|
+
ai302 model set t2i flux-kontext-max-t2i
|
|
90
|
+
ai302 model set i2i wan2.6-image
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## CLI status enums
|
|
94
|
+
|
|
95
|
+
异步任务(video / tts)状态枚举固定为:
|
|
96
|
+
- `pending`:准备/排队中
|
|
97
|
+
- `processing`:处理中
|
|
98
|
+
- `completed`:完成
|
|
99
|
+
- `failed`:失败
|
|
100
|
+
|
|
101
|
+
同步接口(image)只会返回:
|
|
102
|
+
- `completed`:完成
|
|
103
|
+
- `failed`:失败
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Video
|
|
107
|
+
|
|
108
|
+
视频模块提供 **异步视频生成任务**(text-to-video / image-to-video),支持创建任务与查询任务结果。
|
|
109
|
+
|
|
110
|
+
创建任务:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
ai302 video create --prompt "a cat run" --model minimaxi-t2v-01 --api_key "sk-..."
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
117
|
+
|
|
118
|
+
查询任务:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
ai302 video fetch <taskid> --api_key "sk-..."
|
|
122
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
123
|
+
ai302 video fetch <taskid> --short
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## TTS
|
|
127
|
+
|
|
128
|
+
首次使用建议先刷新 provider/model/voice 信息到本地缓存(会写入 `$AI302_CONFIG_DIR/tts/providers.json`):
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
ai302 tts refresh --api_key "sk-..."
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
查看可用 provider:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
ai302 tts providers
|
|
138
|
+
ai302 tts providers-get --random
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
查看可用 voices(建议用 `--provider` 过滤):
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
ai302 tts voices --provider openai
|
|
145
|
+
ai302 tts voices-get openai --random
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
创建 TTS 任务(异步):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
ai302 tts create --text "生活就像海洋,只有意志坚强的人才能到达彼岸" --provider openai --voice alloy --api_key "sk-..."
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
155
|
+
|
|
156
|
+
查询任务结果:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
ai302 tts fetch <taskid> --api_key "sk-..."
|
|
160
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
161
|
+
ai302 tts fetch <taskid> --short
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Image (sync)
|
|
165
|
+
|
|
166
|
+
同步生图:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
ai302 image generate --prompt "sky city" --model flux-kontext-max-t2i --api_key "sk-..."
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
173
|
+
|
|
174
|
+
## Image (async)
|
|
175
|
+
|
|
176
|
+
异步生图(创建任务):
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
ai302 image create --prompt "sky city" --model flux-kontext-max-t2i --api_key "sk-..."
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
查询任务结果:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
ai302 image fetch <taskid> --api_key "sk-..."
|
|
186
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
187
|
+
ai302 image fetch <taskid> --short
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
图生图(可重复传 `--image`):
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
ai302 image generate --prompt "添加墨镜" --image "https://..." --api_key "sk-..."
|
|
194
|
+
## Task (YAML editor)
|
|
195
|
+
|
|
196
|
+
默认目录:`ai302/templates/workspace/tasks`(文件名按时间倒序取最新的 `*.yaml`)。
|
|
197
|
+
|
|
198
|
+
支持字段编辑、数组元素添加与移除,以及通过 `--path` 指定特定文件:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# 修改默认最新文件的字段
|
|
202
|
+
ai302 task edit --set "workflow.steps[step=2].parameters.prompt=生成一只更可爱的小猫"
|
|
203
|
+
|
|
204
|
+
# 指定特定文件进行编辑
|
|
205
|
+
ai302 task edit --path "./tasks/my_task.yaml" --set "a=b"
|
|
206
|
+
|
|
207
|
+
# 添加数组元素
|
|
208
|
+
ai302 task edit --add "workflow.running_steps=Node_C"
|
|
209
|
+
...
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
参数说明:
|
|
213
|
+
- `--set`:设置值,支持 `+=`, `-=` 语法
|
|
214
|
+
- `--add`:追加元素到数组
|
|
215
|
+
- `--remove`:从数组移除元素
|
|
216
|
+
- `--path`:指定要编辑的 YAML 文件路径(如果不提供,则自动寻找默认目录下最新的文件)
|
|
217
|
+
|
|
218
|
+
# 或者使用 += 语法
|
|
219
|
+
ai302 task edit --set "workflow.running_steps+=Node_C"
|
|
220
|
+
|
|
221
|
+
# 移除数组元素 (支持精确值匹配)
|
|
222
|
+
ai302 task edit --remove "workflow.pending_steps=Node_C"
|
|
223
|
+
# 或者使用 -= 语法
|
|
224
|
+
ai302 task edit --set "workflow.pending_steps-=Node_C"
|
|
225
|
+
|
|
226
|
+
# 移除数组元素 (支持对象字段匹配)
|
|
227
|
+
ai302 task edit --remove "workflow.steps=step=1"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`@json=` 用法:当值是数组/对象时,用 `@json` 让 CLI 把值按 JSON 解析,并写回为 YAML 的 **flow style**(数组 `[...]` / 对象 `{...}`)。
|
|
231
|
+
|
|
232
|
+
- list:`depends_on@json=[1,3]` → `depends_on: [1, 3]`
|
|
233
|
+
- object:`parameters.extra@json={"a":1,"b":[2,3]}` → `extra: {a: 1, b: [2, 3]}`
|
|
234
|
+
|
|
235
|
+
路径语法:
|
|
236
|
+
- dotted:`a.b.c=...`
|
|
237
|
+
- 列表下标:`steps[0].parameters.prompt=...`
|
|
238
|
+
- 列表筛选(按字段匹配):`steps[step=2].parameters.prompt=...`
|
|
239
|
+
|
|
240
|
+
运算符说明:
|
|
241
|
+
- `=`:设置值(默认)
|
|
242
|
+
- `+=`:向数组追加元素
|
|
243
|
+
- `-=`:从数组中移除匹配的元素(值匹配或字段筛选匹配)
|
|
244
|
+
|
|
245
|
+
## History / Local files
|
|
246
|
+
|
|
247
|
+
- History(JSONL):`$AI302_CONFIG_DIR/history.jsonl`
|
|
248
|
+
- Video task snapshots:`$AI302_CONFIG_DIR/tasks/<taskid>.json`
|
|
249
|
+
|
|
250
|
+
查看 history 路径:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
ai302 history path
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
按条件查询(输出匹配的 jsonl 行):
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
ai302 history list --kind video --op fetch --limit 20
|
|
260
|
+
```
|
ai302-0.1.0/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# ai302 CLI
|
|
2
|
+
|
|
3
|
+
302.ai 统一命令行工具(输出均为单行 JSON,方便脚本处理)。
|
|
4
|
+
|
|
5
|
+
## Project architecture
|
|
6
|
+
|
|
7
|
+
代码按职责拆分为三层:
|
|
8
|
+
|
|
9
|
+
- `ai302/cli/`:Typer CLI 命令层(参数解析、统一 JSON 输出、写 history/快照)
|
|
10
|
+
- `ai302/cli/app.py`:CLI 根入口(挂载 model/video/image/tts/history 子命令)
|
|
11
|
+
- `ai302/cli/common.py`:公共工具(`resolve_api_key` / `print_json` / `parse_extra`)
|
|
12
|
+
- `ai302/cli/model.py`:默认模型配置(set/list)
|
|
13
|
+
- `ai302/cli/video.py`:视频异步任务(create/fetch)
|
|
14
|
+
- `ai302/cli/image.py`:图片同步生成(generate)
|
|
15
|
+
- `ai302/cli/tts.py`:TTS(refresh/providers/voices/create/fetch)
|
|
16
|
+
- `ai302/cli/history.py`:本地 history 查询(path/list)
|
|
17
|
+
|
|
18
|
+
- `ai302/api/`:HTTP API 封装层(只负责请求/返回 JSON,不做 CLI 交互)
|
|
19
|
+
- `ai302/api/http_client.py`:httpx 客户端、重试、统一错误 `AI302ApiError`、Base URL(`AI302_BASE_URL`)
|
|
20
|
+
- `ai302/api/video.py`:视频 create/fetch 请求封装
|
|
21
|
+
- `ai302/api/image.py`:图片 generate 请求封装
|
|
22
|
+
- `ai302/api/tts.py`:TTS provider/create/fetch 请求封装
|
|
23
|
+
|
|
24
|
+
- `ai302/core/`:本地能力层(配置/模型表/history/快照/缓存)
|
|
25
|
+
- `ai302/core/config.py`:本地配置读写(`$AI302_CONFIG_DIR/config.json`,默认模型等)
|
|
26
|
+
- `ai302/core/models.py`:内置 `SUPPORTED_MODELS` 静态表
|
|
27
|
+
- `ai302/core/history.py`:`history.jsonl` 追加与查询
|
|
28
|
+
- `ai302/core/task_store.py`:任务快照 `tasks/<taskid>.json` 写入/更新
|
|
29
|
+
- `ai302/core/tts_cache.py`:TTS providers 缓存读写与 voices 扁平化
|
|
30
|
+
|
|
31
|
+
入口文件:
|
|
32
|
+
- `ai302/__main__.py`:支持 `python -m ai302 ...`
|
|
33
|
+
- `pyproject.toml`:安装后命令 `ai302 ...` 的脚本入口
|
|
34
|
+
|
|
35
|
+
## Install (dev)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
python -m pip install -U pip
|
|
39
|
+
python -m pip install -e .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Run (no install)
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m ai302 -h
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Environment
|
|
49
|
+
|
|
50
|
+
- API Key:`AI302_KEY`(也可以每次传 `--api_key`)
|
|
51
|
+
- Base URL:`AI302_BASE_URL`(默认 `https://api.302.ai`)
|
|
52
|
+
- Config dir:`AI302_CONFIG_DIR`(默认 `~/.ai302`)
|
|
53
|
+
|
|
54
|
+
PowerShell:
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
$env:AI302_KEY="YOUR_KEY"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Models
|
|
61
|
+
|
|
62
|
+
模型按任务类型分组:
|
|
63
|
+
- 视频:`t2v` / `i2v`
|
|
64
|
+
- 图片:`t2i` / `i2i`
|
|
65
|
+
|
|
66
|
+
查看当前内置支持模型:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m ai302 model list t2v
|
|
70
|
+
python -m ai302 model get t2v --random
|
|
71
|
+
python -m ai302 model list t2i
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
设置默认模型(写入本地配置):
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
ai302 model set t2v minimaxi-t2v-01
|
|
78
|
+
ai302 model set i2v minimaxi-hailuo-2.3-fast
|
|
79
|
+
ai302 model set t2i flux-kontext-max-t2i
|
|
80
|
+
ai302 model set i2i wan2.6-image
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## CLI status enums
|
|
84
|
+
|
|
85
|
+
异步任务(video / tts)状态枚举固定为:
|
|
86
|
+
- `pending`:准备/排队中
|
|
87
|
+
- `processing`:处理中
|
|
88
|
+
- `completed`:完成
|
|
89
|
+
- `failed`:失败
|
|
90
|
+
|
|
91
|
+
同步接口(image)只会返回:
|
|
92
|
+
- `completed`:完成
|
|
93
|
+
- `failed`:失败
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Video
|
|
97
|
+
|
|
98
|
+
视频模块提供 **异步视频生成任务**(text-to-video / image-to-video),支持创建任务与查询任务结果。
|
|
99
|
+
|
|
100
|
+
创建任务:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
ai302 video create --prompt "a cat run" --model minimaxi-t2v-01 --api_key "sk-..."
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
107
|
+
|
|
108
|
+
查询任务:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
ai302 video fetch <taskid> --api_key "sk-..."
|
|
112
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
113
|
+
ai302 video fetch <taskid> --short
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## TTS
|
|
117
|
+
|
|
118
|
+
首次使用建议先刷新 provider/model/voice 信息到本地缓存(会写入 `$AI302_CONFIG_DIR/tts/providers.json`):
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
ai302 tts refresh --api_key "sk-..."
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
查看可用 provider:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
ai302 tts providers
|
|
128
|
+
ai302 tts providers-get --random
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
查看可用 voices(建议用 `--provider` 过滤):
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
ai302 tts voices --provider openai
|
|
135
|
+
ai302 tts voices-get openai --random
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
创建 TTS 任务(异步):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
ai302 tts create --text "生活就像海洋,只有意志坚强的人才能到达彼岸" --provider openai --voice alloy --api_key "sk-..."
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
145
|
+
|
|
146
|
+
查询任务结果:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
ai302 tts fetch <taskid> --api_key "sk-..."
|
|
150
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
151
|
+
ai302 tts fetch <taskid> --short
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Image (sync)
|
|
155
|
+
|
|
156
|
+
同步生图:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
ai302 image generate --prompt "sky city" --model flux-kontext-max-t2i --api_key "sk-..."
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
返回字段补充:`request` 会包含本次请求的 method/url/headers(仅脱敏 Authorization)/params/body。
|
|
163
|
+
|
|
164
|
+
## Image (async)
|
|
165
|
+
|
|
166
|
+
异步生图(创建任务):
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
ai302 image create --prompt "sky city" --model flux-kontext-max-t2i --api_key "sk-..."
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
查询任务结果:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
ai302 image fetch <taskid> --api_key "sk-..."
|
|
176
|
+
# 使用 --short 仅返回关键状态和结果 URL
|
|
177
|
+
ai302 image fetch <taskid> --short
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
图生图(可重复传 `--image`):
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
ai302 image generate --prompt "添加墨镜" --image "https://..." --api_key "sk-..."
|
|
184
|
+
## Task (YAML editor)
|
|
185
|
+
|
|
186
|
+
默认目录:`ai302/templates/workspace/tasks`(文件名按时间倒序取最新的 `*.yaml`)。
|
|
187
|
+
|
|
188
|
+
支持字段编辑、数组元素添加与移除,以及通过 `--path` 指定特定文件:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# 修改默认最新文件的字段
|
|
192
|
+
ai302 task edit --set "workflow.steps[step=2].parameters.prompt=生成一只更可爱的小猫"
|
|
193
|
+
|
|
194
|
+
# 指定特定文件进行编辑
|
|
195
|
+
ai302 task edit --path "./tasks/my_task.yaml" --set "a=b"
|
|
196
|
+
|
|
197
|
+
# 添加数组元素
|
|
198
|
+
ai302 task edit --add "workflow.running_steps=Node_C"
|
|
199
|
+
...
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
参数说明:
|
|
203
|
+
- `--set`:设置值,支持 `+=`, `-=` 语法
|
|
204
|
+
- `--add`:追加元素到数组
|
|
205
|
+
- `--remove`:从数组移除元素
|
|
206
|
+
- `--path`:指定要编辑的 YAML 文件路径(如果不提供,则自动寻找默认目录下最新的文件)
|
|
207
|
+
|
|
208
|
+
# 或者使用 += 语法
|
|
209
|
+
ai302 task edit --set "workflow.running_steps+=Node_C"
|
|
210
|
+
|
|
211
|
+
# 移除数组元素 (支持精确值匹配)
|
|
212
|
+
ai302 task edit --remove "workflow.pending_steps=Node_C"
|
|
213
|
+
# 或者使用 -= 语法
|
|
214
|
+
ai302 task edit --set "workflow.pending_steps-=Node_C"
|
|
215
|
+
|
|
216
|
+
# 移除数组元素 (支持对象字段匹配)
|
|
217
|
+
ai302 task edit --remove "workflow.steps=step=1"
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`@json=` 用法:当值是数组/对象时,用 `@json` 让 CLI 把值按 JSON 解析,并写回为 YAML 的 **flow style**(数组 `[...]` / 对象 `{...}`)。
|
|
221
|
+
|
|
222
|
+
- list:`depends_on@json=[1,3]` → `depends_on: [1, 3]`
|
|
223
|
+
- object:`parameters.extra@json={"a":1,"b":[2,3]}` → `extra: {a: 1, b: [2, 3]}`
|
|
224
|
+
|
|
225
|
+
路径语法:
|
|
226
|
+
- dotted:`a.b.c=...`
|
|
227
|
+
- 列表下标:`steps[0].parameters.prompt=...`
|
|
228
|
+
- 列表筛选(按字段匹配):`steps[step=2].parameters.prompt=...`
|
|
229
|
+
|
|
230
|
+
运算符说明:
|
|
231
|
+
- `=`:设置值(默认)
|
|
232
|
+
- `+=`:向数组追加元素
|
|
233
|
+
- `-=`:从数组中移除匹配的元素(值匹配或字段筛选匹配)
|
|
234
|
+
|
|
235
|
+
## History / Local files
|
|
236
|
+
|
|
237
|
+
- History(JSONL):`$AI302_CONFIG_DIR/history.jsonl`
|
|
238
|
+
- Video task snapshots:`$AI302_CONFIG_DIR/tasks/<taskid>.json`
|
|
239
|
+
|
|
240
|
+
查看 history 路径:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
ai302 history path
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
按条件查询(输出匹配的 jsonl 行):
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
ai302 history list --kind video --op fetch --limit 20
|
|
250
|
+
```
|
|
File without changes
|