seacloud-sdk 0.10.0 → 0.10.1
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.
- package/README.md +969 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,969 @@
|
|
|
1
|
+
# SeaCloud SDK
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
**统一的 AI 服务 SDK for JavaScript/TypeScript**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/seacloud-sdk)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📖 概述
|
|
16
|
+
|
|
17
|
+
**SeaCloud SDK** 是一个全面的 TypeScript/JavaScript SDK,提供对 100+ 种 AI 模型和服务的统一访问,包括:
|
|
18
|
+
|
|
19
|
+
- 🤖 **LLM 聊天补全** - Claude、GPT、Gemini、DeepSeek、Kimi 等 40+ 种模型
|
|
20
|
+
- 🎨 **图像生成** - FLUX、WANx、Seedream、Imagen 等
|
|
21
|
+
- 🎬 **视频生成** - Kling、Vidu、Sora、PixelVerse、Runway
|
|
22
|
+
- 🛡️ **内容安全扫描** - NSFW 检测、暴力、政治内容识别
|
|
23
|
+
- 🤖 **Agent 智能体** - 工具调用、多模态生成、会话管理
|
|
24
|
+
- 🎵 **音频与 3D** - TTS、音乐生成、3D 模型创建
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## ✨ 特性
|
|
29
|
+
|
|
30
|
+
- ✅ **100+ AI 模型** - 通过单一接口访问最新最强的 AI 模型
|
|
31
|
+
- ✅ **类型安全** - 完整的 TypeScript 支持,全面的类型定义
|
|
32
|
+
- ✅ **流式支持** - Server-Sent Events (SSE) 实现实时响应
|
|
33
|
+
- ✅ **智能任务管理** - 自动轮询和状态跟踪
|
|
34
|
+
- ✅ **多环境支持** - 可在 Node.js、浏览器和 iframe 环境中使用
|
|
35
|
+
- ✅ **灵活的 Token 管理** - 多种身份验证方式
|
|
36
|
+
- ✅ **CLI 工具** - 命令行接口快速测试
|
|
37
|
+
- ✅ **零依赖** - 使用原生 fetch API,最小化体积
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 📦 安装
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# npm
|
|
45
|
+
npm install seacloud-sdk
|
|
46
|
+
|
|
47
|
+
# yarn
|
|
48
|
+
yarn add seacloud-sdk
|
|
49
|
+
|
|
50
|
+
# pnpm
|
|
51
|
+
pnpm add seacloud-sdk
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**环境要求**: Node.js 18+ 或支持 fetch API 的现代浏览器
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 🚀 快速开始
|
|
59
|
+
|
|
60
|
+
### 1. 初始化 SDK
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { initSeacloud } from 'seacloud-sdk';
|
|
64
|
+
|
|
65
|
+
// 方式 1: 使用 API Key 简单初始化
|
|
66
|
+
initSeacloud('your-api-key');
|
|
67
|
+
|
|
68
|
+
// 方式 2: 完整配置
|
|
69
|
+
initSeacloud({
|
|
70
|
+
apiKey: 'your-api-key',
|
|
71
|
+
baseUrl: 'https://proxy-rs.seaverse.ai',
|
|
72
|
+
timeout: 30000,
|
|
73
|
+
intervalMs: 3000, // 轮询间隔
|
|
74
|
+
maxAttempts: 100 // 最大轮询次数
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 方式 3: 从环境变量自动检测
|
|
78
|
+
initSeacloud();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 2. LLM 聊天(基础)
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { llmChatCompletions } from 'seacloud-sdk';
|
|
85
|
+
|
|
86
|
+
const response = await llmChatCompletions({
|
|
87
|
+
model: 'deepseek-v3.1',
|
|
88
|
+
messages: [
|
|
89
|
+
{ role: 'user', content: '你好!你怎么样?' }
|
|
90
|
+
],
|
|
91
|
+
max_tokens: 1000
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log(response.choices[0].message.content);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 3. LLM 聊天(流式)
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const stream = await llmChatCompletions({
|
|
101
|
+
model: 'gpt-4o',
|
|
102
|
+
messages: [
|
|
103
|
+
{ role: 'user', content: '写一首关于 AI 的诗' }
|
|
104
|
+
],
|
|
105
|
+
stream: true
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
for await (const chunk of stream) {
|
|
109
|
+
process.stdout.write(chunk.choices[0]?.delta?.content || '');
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 4. 图像生成
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { alibabaWanx21T2iTurbo } from 'seacloud-sdk';
|
|
117
|
+
|
|
118
|
+
const result = await alibabaWanx21T2iTurbo({
|
|
119
|
+
input: {
|
|
120
|
+
prompt: '一幅美丽的山间日落',
|
|
121
|
+
negative_prompt: '模糊,低质量'
|
|
122
|
+
},
|
|
123
|
+
parameters: {
|
|
124
|
+
size: '1024*1024',
|
|
125
|
+
n: 1
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
console.log(result[0].url); // 图像 URL
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 5. 内容安全扫描
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { scan } from 'seacloud-sdk';
|
|
136
|
+
|
|
137
|
+
const result = await scan({
|
|
138
|
+
uri: 'https://example.com/image.jpg',
|
|
139
|
+
risk_types: ['EROTIC', 'VIOLENT'],
|
|
140
|
+
detected_age: 0,
|
|
141
|
+
is_video: 0
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
console.log('风险等级:', result.nsfw_level); // 0-6
|
|
145
|
+
console.log('标签:', result.label_items);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 📚 文档
|
|
151
|
+
|
|
152
|
+
### 配置
|
|
153
|
+
|
|
154
|
+
#### 环境变量
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# .env 文件
|
|
158
|
+
API_SERVICE_TOKEN=your-api-key-here
|
|
159
|
+
SEACLOUD_BASE_URL=https://proxy-rs.seaverse.ai # 可选
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Token 优先级
|
|
163
|
+
|
|
164
|
+
SDK 按以下顺序获取 API Token:
|
|
165
|
+
|
|
166
|
+
1. **提供的 `apiKey`** 参数(在 `initSeacloud()` 中)
|
|
167
|
+
2. **浏览器 `localStorage.auth_token`**(浏览器环境)
|
|
168
|
+
3. **环境变量 `process.env.API_SERVICE_TOKEN`**(Node.js)
|
|
169
|
+
4. **父页面 PostMessage**(iframe 环境)
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### 核心 API
|
|
174
|
+
|
|
175
|
+
#### 🤖 LLM 聊天补全
|
|
176
|
+
|
|
177
|
+
访问 100+ 种 LLM 模型进行聊天和文本生成。
|
|
178
|
+
|
|
179
|
+
**支持的模型:**
|
|
180
|
+
- Claude: `seaart-mix-sonnet-4-5`, `seacloud-claude-opus-4.5`, `seacloud-claude-haiku-4.5`
|
|
181
|
+
- GPT: `gpt-4o`, `gpt-4o-mini`, `gpt-4.1`, `gpt-5`
|
|
182
|
+
- DeepSeek: `deepseek-v3.1`, `deepseek-r1`
|
|
183
|
+
- Gemini: `gemini-2.5-pro`, `gemini-2.5-flash`
|
|
184
|
+
- Kimi: `kimi-k2`, `kimi-k2-thinking`
|
|
185
|
+
- Grok: `grok-4`, `grok-code-fast-1`
|
|
186
|
+
- Qwen: `qwen-plus`, `qwen3-coder-plus`
|
|
187
|
+
- GLM: `glm-4.5-air`, `glm-4.6`
|
|
188
|
+
- 还有 30+ 种模型...
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { llmChatCompletions } from 'seacloud-sdk';
|
|
192
|
+
|
|
193
|
+
// 非流式
|
|
194
|
+
const response = await llmChatCompletions({
|
|
195
|
+
model: 'deepseek-v3.1',
|
|
196
|
+
messages: [
|
|
197
|
+
{ role: 'system', content: '你是一个有用的助手。' },
|
|
198
|
+
{ role: 'user', content: '解释量子计算' }
|
|
199
|
+
],
|
|
200
|
+
temperature: 0.7,
|
|
201
|
+
max_tokens: 2000,
|
|
202
|
+
top_p: 0.9
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// 流式
|
|
206
|
+
const stream = await llmChatCompletions({
|
|
207
|
+
model: 'gpt-4o',
|
|
208
|
+
messages: [{ role: 'user', content: '给我讲个故事' }],
|
|
209
|
+
stream: true
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
for await (const chunk of stream) {
|
|
213
|
+
const content = chunk.choices[0]?.delta?.content;
|
|
214
|
+
if (content) process.stdout.write(content);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
#### 🤖 Agent 聊天补全
|
|
221
|
+
|
|
222
|
+
具有工具调用和多模态能力的智能 Agent。
|
|
223
|
+
|
|
224
|
+
**功能:**
|
|
225
|
+
- 多轮对话和会话管理
|
|
226
|
+
- 工具调用(图像/视频/音乐生成)
|
|
227
|
+
- 流式和非流式响应
|
|
228
|
+
- 多模态输入(文本、图像、视频)
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import {
|
|
232
|
+
agentChatCompletions,
|
|
233
|
+
createTextMessage,
|
|
234
|
+
createImageMessage,
|
|
235
|
+
createTool
|
|
236
|
+
} from 'seacloud-sdk';
|
|
237
|
+
|
|
238
|
+
// 简单文本聊天
|
|
239
|
+
const response = await agentChatCompletions({
|
|
240
|
+
agent_id: 'seaverse_agent',
|
|
241
|
+
messages: [
|
|
242
|
+
createTextMessage('user', '生成一张美丽的风景图片')
|
|
243
|
+
],
|
|
244
|
+
model: 'gpt-4o',
|
|
245
|
+
seq: 0
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (response.artifacts) {
|
|
249
|
+
console.log('已生成:', response.artifacts[0].url);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 多轮对话
|
|
253
|
+
const response1 = await agentChatCompletions({
|
|
254
|
+
agent_id: 'seaverse_agent',
|
|
255
|
+
messages: [createTextMessage('user', '什么是 AI?')],
|
|
256
|
+
model: 'gpt-4o',
|
|
257
|
+
seq: 0
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const sessionId = response1.session_id;
|
|
261
|
+
|
|
262
|
+
const response2 = await agentChatCompletions({
|
|
263
|
+
agent_id: 'seaverse_agent',
|
|
264
|
+
session_id: sessionId,
|
|
265
|
+
messages: [
|
|
266
|
+
createTextMessage('user', '什么是 AI?'),
|
|
267
|
+
{ role: 'assistant', content: [{ type: 'text', text: response1.choices[0].message.content }] },
|
|
268
|
+
createTextMessage('user', '给我举个例子')
|
|
269
|
+
],
|
|
270
|
+
model: 'gpt-4o',
|
|
271
|
+
seq: 1
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// 图像分析
|
|
275
|
+
const response3 = await agentChatCompletions({
|
|
276
|
+
agent_id: 'seaverse_agent',
|
|
277
|
+
messages: [
|
|
278
|
+
createImageMessage('user', '这张图片里有什么?', 'https://example.com/image.jpg')
|
|
279
|
+
],
|
|
280
|
+
model: 'gpt-4o',
|
|
281
|
+
seq: 0
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// 自定义工具
|
|
285
|
+
const imageTool = createTool('seacloud_fast_text_to_image');
|
|
286
|
+
const videoTool = createTool('seacloud_fast_text_to_video');
|
|
287
|
+
|
|
288
|
+
const response4 = await agentChatCompletions({
|
|
289
|
+
agent_id: 'seaverse_agent',
|
|
290
|
+
messages: [createTextMessage('user', '创建一个日落视频')],
|
|
291
|
+
tools: [videoTool],
|
|
292
|
+
model: 'gpt-4o',
|
|
293
|
+
seq: 0
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**可用工具:**
|
|
298
|
+
- `seacloud_fast_text_to_image` - 快速图像生成
|
|
299
|
+
- `seacloud_fast_text_to_video` - 快速视频生成
|
|
300
|
+
- `seacloud_music_generation` - 音乐生成
|
|
301
|
+
- `seacloud_image_edit_google` - 图像编辑
|
|
302
|
+
- `seacloud_flux_pro_edit` - FLUX 图像编辑
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
#### 🛡️ 内容安全扫描
|
|
307
|
+
|
|
308
|
+
检测图像和视频中的不安全内容。
|
|
309
|
+
|
|
310
|
+
**风险类型:**
|
|
311
|
+
- `POLITY` - 政治内容
|
|
312
|
+
- `EROTIC` - 成人/NSFW 内容
|
|
313
|
+
- `VIOLENT` - 暴力和血腥
|
|
314
|
+
- `CHILD` - 儿童安全问题
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { scan } from 'seacloud-sdk';
|
|
318
|
+
|
|
319
|
+
// 图像扫描
|
|
320
|
+
const imageResult = await scan({
|
|
321
|
+
uri: 'https://example.com/image.jpg',
|
|
322
|
+
risk_types: ['EROTIC', 'VIOLENT'],
|
|
323
|
+
detected_age: 0, // 0=不检测年龄, 1=检测年龄
|
|
324
|
+
is_video: 0 // 0=图像, 1=视频
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
console.log('风险等级:', imageResult.nsfw_level); // 0-6 (0=安全, 6=最高风险)
|
|
328
|
+
console.log('标签:', imageResult.label_items); // ['person', 'outdoor', ...]
|
|
329
|
+
console.log('风险:', imageResult.risk_types); // ['EROTIC']
|
|
330
|
+
|
|
331
|
+
// 视频扫描(逐帧)
|
|
332
|
+
const videoResult = await scan({
|
|
333
|
+
uri: 'https://example.com/video.mp4',
|
|
334
|
+
risk_types: ['EROTIC', 'VIOLENT'],
|
|
335
|
+
detected_age: 1,
|
|
336
|
+
is_video: 1
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
console.log('时长:', videoResult.video_duration);
|
|
340
|
+
console.log('帧数:', videoResult.frame_count);
|
|
341
|
+
console.log('帧结果:', videoResult.frame_results);
|
|
342
|
+
// [
|
|
343
|
+
// { frame_no: 0, nsfw_level: 0, label_items: [...] },
|
|
344
|
+
// { frame_no: 1, nsfw_level: 1, label_items: [...] },
|
|
345
|
+
// ...
|
|
346
|
+
// ]
|
|
347
|
+
|
|
348
|
+
// Base64 图像扫描
|
|
349
|
+
const base64Result = await scan({
|
|
350
|
+
img_base64: 'data:image/jpeg;base64,/9j/4AAQ...',
|
|
351
|
+
risk_types: ['EROTIC'],
|
|
352
|
+
detected_age: 0,
|
|
353
|
+
is_video: 0
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
#### 🎨 图像生成模型
|
|
360
|
+
|
|
361
|
+
访问来自各种提供商的 50+ 种图像生成模型。
|
|
362
|
+
|
|
363
|
+
##### 阿里巴巴 WANx 系列
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
import {
|
|
367
|
+
alibabaWanx21T2iTurbo,
|
|
368
|
+
alibabaWanx25T2i,
|
|
369
|
+
alibabaWanx26T2i,
|
|
370
|
+
alibabaWanx21I2i
|
|
371
|
+
} from 'seacloud-sdk';
|
|
372
|
+
|
|
373
|
+
// 文本到图像
|
|
374
|
+
const result = await alibabaWanx26T2i({
|
|
375
|
+
input: {
|
|
376
|
+
prompt: '一只可爱的柯基犬在花园里玩耍',
|
|
377
|
+
negative_prompt: '模糊,低质量,扭曲'
|
|
378
|
+
},
|
|
379
|
+
parameters: {
|
|
380
|
+
size: '1024*1024', // 或 '768*1024', '1024*768'
|
|
381
|
+
n: 1,
|
|
382
|
+
seed: 42, // 可选:用于可重现性
|
|
383
|
+
ref_mode: 'repaint' // 可选:参考模式
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
console.log(result[0].url);
|
|
388
|
+
|
|
389
|
+
// 图像到图像
|
|
390
|
+
const i2iResult = await alibabaWanx21I2i({
|
|
391
|
+
input: {
|
|
392
|
+
prompt: '转换为水彩画',
|
|
393
|
+
image_url: 'https://example.com/input.jpg'
|
|
394
|
+
},
|
|
395
|
+
parameters: {
|
|
396
|
+
size: '1024*1024',
|
|
397
|
+
n: 1
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
##### Black Forest Labs FLUX 系列
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
import {
|
|
406
|
+
blackforestlabsFlux2Pro,
|
|
407
|
+
blackforestlabsFlux11Pro,
|
|
408
|
+
blackforestlabsFluxFlex,
|
|
409
|
+
blackforestlabsFluxProEdit
|
|
410
|
+
} from 'seacloud-sdk';
|
|
411
|
+
|
|
412
|
+
// FLUX Pro(最高质量)
|
|
413
|
+
const fluxResult = await blackforestlabsFlux2Pro({
|
|
414
|
+
prompt: '一位女性的逼真肖像',
|
|
415
|
+
width: 1024,
|
|
416
|
+
height: 1024,
|
|
417
|
+
prompt_upsampling: false,
|
|
418
|
+
seed: 12345,
|
|
419
|
+
safety_tolerance: 2
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// FLUX 图像编辑
|
|
423
|
+
const editResult = await blackforestlabsFluxProEdit({
|
|
424
|
+
prompt: '给人物添加墨镜',
|
|
425
|
+
image_url: 'https://example.com/portrait.jpg',
|
|
426
|
+
width: 1024,
|
|
427
|
+
height: 1024
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
##### Volces Seedream 系列
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
import {
|
|
435
|
+
volcesSeedream45,
|
|
436
|
+
volcesSeededit3,
|
|
437
|
+
volcesSeedance
|
|
438
|
+
} from 'seacloud-sdk';
|
|
439
|
+
|
|
440
|
+
// 图像生成
|
|
441
|
+
const seedreamResult = await volcesSeedream45({
|
|
442
|
+
prompt: '云中的幻想城堡',
|
|
443
|
+
negative_prompt: '模糊',
|
|
444
|
+
width: 1024,
|
|
445
|
+
height: 1024,
|
|
446
|
+
seed: 123,
|
|
447
|
+
scale: 7.5
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// 图像编辑
|
|
451
|
+
const editResult = await volcesSeededit3({
|
|
452
|
+
prompt: '将天空改为日落',
|
|
453
|
+
image_url: 'https://example.com/landscape.jpg'
|
|
454
|
+
});
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
##### Google 系列
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import {
|
|
461
|
+
googleGemini2Image,
|
|
462
|
+
googleImagen4Generate,
|
|
463
|
+
googleVeo2
|
|
464
|
+
} from 'seacloud-sdk';
|
|
465
|
+
|
|
466
|
+
// Gemini 图像生成
|
|
467
|
+
const geminiResult = await googleGemini2Image({
|
|
468
|
+
prompt: '科技创业公司的极简 logo 设计',
|
|
469
|
+
number_of_images: 4,
|
|
470
|
+
aspect_ratio: '1:1', // '1:1', '3:4', '4:3', '9:16', '16:9'
|
|
471
|
+
negative_prompt: 'text, watermark'
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Imagen 4(最高质量)
|
|
475
|
+
const imagenResult = await googleImagen4Generate({
|
|
476
|
+
prompt: '超逼真的美食摄影',
|
|
477
|
+
number_of_images: 1,
|
|
478
|
+
aspect_ratio: '16:9'
|
|
479
|
+
});
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
#### 🎬 视频生成模型
|
|
485
|
+
|
|
486
|
+
使用 40+ 种视频模型从文本或图像生成视频。
|
|
487
|
+
|
|
488
|
+
##### Kling 系列(字节跳动)
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
import {
|
|
492
|
+
klingV26,
|
|
493
|
+
klingV25Turbo,
|
|
494
|
+
klingV21Master,
|
|
495
|
+
klingOmni,
|
|
496
|
+
klingAvatar,
|
|
497
|
+
klingLipsync
|
|
498
|
+
} from 'seacloud-sdk';
|
|
499
|
+
|
|
500
|
+
// 文本到视频
|
|
501
|
+
const videoResult = await klingV26({
|
|
502
|
+
prompt: '一只猫在玩毛线球',
|
|
503
|
+
negative_prompt: '模糊,抖动',
|
|
504
|
+
cfg_scale: 0.5,
|
|
505
|
+
mode: 'pro', // 'std' 或 'pro'
|
|
506
|
+
duration: '10', // '5' 或 '10' 秒
|
|
507
|
+
aspect_ratio: '16:9'
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
console.log(videoResult[0].url);
|
|
511
|
+
console.log('时长:', videoResult[0].duration);
|
|
512
|
+
|
|
513
|
+
// 图像到视频
|
|
514
|
+
const i2vResult = await klingV26({
|
|
515
|
+
image_url: 'https://example.com/static-image.jpg',
|
|
516
|
+
prompt: '添加轻微的镜头平移',
|
|
517
|
+
mode: 'pro',
|
|
518
|
+
duration: '5',
|
|
519
|
+
aspect_ratio: '16:9'
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// 虚拟人生成
|
|
523
|
+
const avatarResult = await klingAvatar({
|
|
524
|
+
driver_video: 'https://example.com/talking.mp4',
|
|
525
|
+
image_url: 'https://example.com/portrait.jpg'
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// 唇形同步
|
|
529
|
+
const lipsyncResult = await klingLipsync({
|
|
530
|
+
audio_url: 'https://example.com/speech.mp3',
|
|
531
|
+
image_url: 'https://example.com/face.jpg'
|
|
532
|
+
});
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
##### Vidu 系列
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
import { viduQ2, viduQ1, vidu15 } from 'seacloud-sdk';
|
|
539
|
+
|
|
540
|
+
const viduResult = await viduQ2({
|
|
541
|
+
prompt: '海滨城市日落的无人机镜头',
|
|
542
|
+
enhance_prompt: true,
|
|
543
|
+
duration: 8, // 4 或 8 秒
|
|
544
|
+
aspect_ratio: '16:9'
|
|
545
|
+
});
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
##### PixelVerse 系列
|
|
549
|
+
|
|
550
|
+
```typescript
|
|
551
|
+
import { pixverseV55, pixverseV45 } from 'seacloud-sdk';
|
|
552
|
+
|
|
553
|
+
const pixResult = await pixverseV55({
|
|
554
|
+
prompt: '花朵绽放的延时摄影',
|
|
555
|
+
negative_prompt: '静止',
|
|
556
|
+
seed: 789,
|
|
557
|
+
aspect_ratio: '16:9'
|
|
558
|
+
});
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
##### 微软 Sora
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
import { microsoftSora2 } from 'seacloud-sdk';
|
|
565
|
+
|
|
566
|
+
const soraResult = await microsoftSora2({
|
|
567
|
+
prompt: '未来主义的城市景观与飞行汽车',
|
|
568
|
+
duration: 10,
|
|
569
|
+
resolution: '1080p' // '720p', '1080p', '4k'
|
|
570
|
+
});
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
#### 🎵 音频和 3D 生成
|
|
576
|
+
|
|
577
|
+
```typescript
|
|
578
|
+
// 文本转语音(ElevenLabs)
|
|
579
|
+
import { elevenlabsTtsGenerator } from 'seacloud-sdk';
|
|
580
|
+
|
|
581
|
+
const ttsResult = await elevenlabsTtsGenerator({
|
|
582
|
+
text: '你好,这是文本转语音的测试。',
|
|
583
|
+
voice_id: 'default',
|
|
584
|
+
model_id: 'eleven_multilingual_v2'
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
console.log('音频 URL:', ttsResult[0].url);
|
|
588
|
+
|
|
589
|
+
// 3D 模型生成(腾讯)
|
|
590
|
+
import { tencentHunyuan3d } from 'seacloud-sdk';
|
|
591
|
+
|
|
592
|
+
const model3d = await tencentHunyuan3d({
|
|
593
|
+
image_url: 'https://example.com/object.jpg',
|
|
594
|
+
format: 'obj' // 'obj', 'glb', 'fbx'
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
console.log('3D 模型 URL:', model3d[0].url);
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
---
|
|
601
|
+
|
|
602
|
+
#### 📱 App 快应用生成
|
|
603
|
+
|
|
604
|
+
从模板创建快应用。
|
|
605
|
+
|
|
606
|
+
```typescript
|
|
607
|
+
import { appGeneration, appSearch } from 'seacloud-sdk';
|
|
608
|
+
|
|
609
|
+
// 搜索模板
|
|
610
|
+
const templates = await appSearch({
|
|
611
|
+
template_id: 'comfyui-template-001',
|
|
612
|
+
type: 'comfyui'
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// 生成应用
|
|
616
|
+
const app = await appGeneration({
|
|
617
|
+
template_id: 'comfyui-template-001',
|
|
618
|
+
params: [
|
|
619
|
+
{ name: 'prompt', value: '美丽的日落' },
|
|
620
|
+
{ name: 'steps', value: '30' }
|
|
621
|
+
]
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
console.log('应用 URL:', app.url);
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
---
|
|
628
|
+
|
|
629
|
+
### 任务管理
|
|
630
|
+
|
|
631
|
+
所有生成 API 都会返回任务,并自动轮询直到完成。
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
import {
|
|
635
|
+
createAndWaitTask,
|
|
636
|
+
pollTaskUntilComplete,
|
|
637
|
+
getTaskStatus,
|
|
638
|
+
getClient
|
|
639
|
+
} from 'seacloud-sdk';
|
|
640
|
+
|
|
641
|
+
// 手动创建和轮询任务
|
|
642
|
+
const client = getClient();
|
|
643
|
+
|
|
644
|
+
const task = await client.createTask('/v1/image/generation', {
|
|
645
|
+
model: 'flux-pro',
|
|
646
|
+
input: [{ params: { prompt: '日落' } }]
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
console.log('任务 ID:', task.id);
|
|
650
|
+
|
|
651
|
+
// 手动轮询
|
|
652
|
+
const result = await pollTaskUntilComplete(client, task.id, {
|
|
653
|
+
intervalMs: 3000,
|
|
654
|
+
maxAttempts: 100,
|
|
655
|
+
onProgress: (attempt, status) => {
|
|
656
|
+
console.log(`尝试 ${attempt}: ${status}`);
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
// 直接检查任务状态
|
|
661
|
+
const status = await getTaskStatus(task.id);
|
|
662
|
+
console.log('状态:', status.status);
|
|
663
|
+
console.log('输出:', status.output);
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
---
|
|
667
|
+
|
|
668
|
+
### 错误处理
|
|
669
|
+
|
|
670
|
+
```typescript
|
|
671
|
+
import { SeacloudError } from 'seacloud-sdk';
|
|
672
|
+
|
|
673
|
+
try {
|
|
674
|
+
const result = await llmChatCompletions({
|
|
675
|
+
model: 'invalid-model',
|
|
676
|
+
messages: [{ role: 'user', content: 'Hello' }]
|
|
677
|
+
});
|
|
678
|
+
} catch (error) {
|
|
679
|
+
if (error instanceof SeacloudError) {
|
|
680
|
+
console.error('SeaCloud 错误:', error.message);
|
|
681
|
+
console.error('状态码:', error.statusCode);
|
|
682
|
+
console.error('详情:', error.details);
|
|
683
|
+
} else {
|
|
684
|
+
console.error('未知错误:', error);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
## 🖥️ CLI 使用
|
|
692
|
+
|
|
693
|
+
SDK 包含用于快速测试的命令行工具。
|
|
694
|
+
|
|
695
|
+
```bash
|
|
696
|
+
# LLM 聊天
|
|
697
|
+
seacloud llm "你好,最近怎么样?" --model gpt-4o --stream
|
|
698
|
+
|
|
699
|
+
# Agent 聊天(带图像生成)
|
|
700
|
+
seacloud agent "生成一张可爱小狗的图片" --stream
|
|
701
|
+
|
|
702
|
+
# 内容扫描
|
|
703
|
+
seacloud scan "https://example.com/image.jpg" --risk-types EROTIC,VIOLENT
|
|
704
|
+
|
|
705
|
+
# 检查任务状态
|
|
706
|
+
seacloud status task-123abc
|
|
707
|
+
|
|
708
|
+
# App 生成
|
|
709
|
+
seacloud app search "template-id" --type comfyui
|
|
710
|
+
seacloud app generation --template-id "xxx" --params '[{"name":"prompt","value":"test"}]'
|
|
711
|
+
|
|
712
|
+
# 图像生成
|
|
713
|
+
seacloud flux_2_pro --params '{"prompt":"美丽的日落","width":1024,"height":1024}'
|
|
714
|
+
|
|
715
|
+
# 视频生成
|
|
716
|
+
seacloud kling_v2_6 --params '{"prompt":"一只猫在玩耍","mode":"pro","duration":"5"}'
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
---
|
|
720
|
+
|
|
721
|
+
## 🌍 支持的模型
|
|
722
|
+
|
|
723
|
+
### LLM 模型(40+)
|
|
724
|
+
|
|
725
|
+
| 提供商 | 模型 |
|
|
726
|
+
|----------|--------|
|
|
727
|
+
| **Anthropic Claude** | seaart-mix-sonnet-4-5, seacloud-claude-opus-4.5, seacloud-claude-haiku-4.5, shaseng-claude-4.5 |
|
|
728
|
+
| **OpenAI** | gpt-4o, gpt-4o-mini, gpt-4.1, gpt-5, o1, o1-mini, o3-mini |
|
|
729
|
+
| **DeepSeek** | deepseek-v3.1, deepseek-r1, deepseek-chat, deepseek-coder |
|
|
730
|
+
| **Google** | gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-thinking, gemini-1.5-pro |
|
|
731
|
+
| **Kimi** | kimi-k2, kimi-k2-thinking, kimi-k1.5, kimi-k1 |
|
|
732
|
+
| **Grok** | grok-4, grok-code-fast-1, grok-2, grok-2-vision |
|
|
733
|
+
| **阿里巴巴** | qwen-plus, qwen-turbo, qwen3-coder-plus, qwen-max |
|
|
734
|
+
| **智谱 AI** | glm-4.5-air, glm-4.6, glm-4-plus, glm-zero |
|
|
735
|
+
| **更多...** | Doubao、Hunyuan、Yi、Mistral、Llama 等 |
|
|
736
|
+
|
|
737
|
+
### 图像生成模型(50+)
|
|
738
|
+
|
|
739
|
+
| 提供商 | 系列 | 数量 |
|
|
740
|
+
|----------|--------|-------|
|
|
741
|
+
| 阿里巴巴 | WANx 2.1/2.5/2.6 | 23 个模型 |
|
|
742
|
+
| Black Forest Labs | FLUX Pro/Flex/Edit | 8 个模型 |
|
|
743
|
+
| Volces | Seedream/Seededit | 21 个模型 |
|
|
744
|
+
| Google | Gemini/Imagen 4 | 11 个模型 |
|
|
745
|
+
| 其他 | 各种提供商 | 20+ 个模型 |
|
|
746
|
+
|
|
747
|
+
### 视频生成模型(40+)
|
|
748
|
+
|
|
749
|
+
| 提供商 | 系列 | 数量 |
|
|
750
|
+
|----------|--------|-------|
|
|
751
|
+
| Kling(字节跳动) | V2.6/V2.5/V2.1/Omni | 27 个模型 |
|
|
752
|
+
| PixelVerse | V3.5/V4.5/V5.5 | 16 个模型 |
|
|
753
|
+
| Vidu | Q1/Q2/1.5 | 8 个模型 |
|
|
754
|
+
| MiniMax | HaiLuo T2V/I2V | 12 个模型 |
|
|
755
|
+
| 其他 | Sora、Runway 等 | 10+ 个模型 |
|
|
756
|
+
|
|
757
|
+
---
|
|
758
|
+
|
|
759
|
+
## 🔧 高级用法
|
|
760
|
+
|
|
761
|
+
### 自定义轮询选项
|
|
762
|
+
|
|
763
|
+
```typescript
|
|
764
|
+
import { initSeacloud, setDefaultPollingOptions } from 'seacloud-sdk';
|
|
765
|
+
|
|
766
|
+
// 设置全局默认值
|
|
767
|
+
setDefaultPollingOptions({
|
|
768
|
+
intervalMs: 5000, // 每 5 秒轮询一次
|
|
769
|
+
maxAttempts: 200 // 最多 200 次尝试(16+ 分钟)
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
// 或者按请求设置
|
|
773
|
+
import { createAndWaitTask, getClient } from 'seacloud-sdk';
|
|
774
|
+
|
|
775
|
+
const client = getClient();
|
|
776
|
+
const result = await createAndWaitTask(
|
|
777
|
+
client,
|
|
778
|
+
'/v1/image/generation',
|
|
779
|
+
{ model: 'flux-pro', input: [{ params: { prompt: 'test' } }] },
|
|
780
|
+
{
|
|
781
|
+
intervalMs: 2000,
|
|
782
|
+
maxAttempts: 50,
|
|
783
|
+
onProgress: (attempt, status) => {
|
|
784
|
+
console.log(`轮询尝试 ${attempt},状态: ${status}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
### 浏览器使用
|
|
791
|
+
|
|
792
|
+
```html
|
|
793
|
+
<!DOCTYPE html>
|
|
794
|
+
<html>
|
|
795
|
+
<head>
|
|
796
|
+
<script type="module">
|
|
797
|
+
import { initSeacloud, llmChatCompletions } from 'https://esm.sh/seacloud-sdk';
|
|
798
|
+
|
|
799
|
+
// 从 localStorage 获取 Token
|
|
800
|
+
localStorage.setItem('auth_token', 'your-api-key');
|
|
801
|
+
initSeacloud();
|
|
802
|
+
|
|
803
|
+
const response = await llmChatCompletions({
|
|
804
|
+
model: 'gpt-4o',
|
|
805
|
+
messages: [{ role: 'user', content: '来自浏览器的你好!' }]
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
console.log(response.choices[0].message.content);
|
|
809
|
+
</script>
|
|
810
|
+
</head>
|
|
811
|
+
<body>
|
|
812
|
+
<h1>SeaCloud SDK 浏览器示例</h1>
|
|
813
|
+
</body>
|
|
814
|
+
</html>
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### Iframe 集成
|
|
818
|
+
|
|
819
|
+
```typescript
|
|
820
|
+
// 在父页面中
|
|
821
|
+
window.addEventListener('message', (event) => {
|
|
822
|
+
if (event.data.type === 'seaverse:get_token') {
|
|
823
|
+
event.source.postMessage({
|
|
824
|
+
type: 'seaverse:token',
|
|
825
|
+
token: 'your-api-key'
|
|
826
|
+
}, '*');
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// 在 iframe 中
|
|
831
|
+
import { initSeacloud, llmChatCompletions } from 'seacloud-sdk';
|
|
832
|
+
|
|
833
|
+
initSeacloud(); // 将自动从父页面请求 token
|
|
834
|
+
|
|
835
|
+
const response = await llmChatCompletions({
|
|
836
|
+
model: 'gpt-4o',
|
|
837
|
+
messages: [{ role: 'user', content: '来自 iframe 的你好!' }]
|
|
838
|
+
});
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
---
|
|
842
|
+
|
|
843
|
+
## 📖 类型定义
|
|
844
|
+
|
|
845
|
+
SDK 完全类型化。以下是关键接口:
|
|
846
|
+
|
|
847
|
+
```typescript
|
|
848
|
+
// 配置
|
|
849
|
+
interface SeacloudConfig {
|
|
850
|
+
apiKey?: string;
|
|
851
|
+
baseUrl?: string;
|
|
852
|
+
fetch?: typeof fetch;
|
|
853
|
+
timeout?: number;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// 任务
|
|
857
|
+
interface TaskResult {
|
|
858
|
+
id: string;
|
|
859
|
+
created_at: number;
|
|
860
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
861
|
+
error?: { code: string; message: string } | null;
|
|
862
|
+
model: string;
|
|
863
|
+
output?: Array<{
|
|
864
|
+
content?: Array<{
|
|
865
|
+
type?: string;
|
|
866
|
+
url?: string;
|
|
867
|
+
size?: { width: number; height: number };
|
|
868
|
+
duration?: number;
|
|
869
|
+
}>;
|
|
870
|
+
}>;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// LLM 消息
|
|
874
|
+
interface ChatMessage {
|
|
875
|
+
role: 'system' | 'user' | 'assistant';
|
|
876
|
+
content: string;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
interface ChatCompletionResponse {
|
|
880
|
+
id: string;
|
|
881
|
+
choices: Array<{
|
|
882
|
+
index: number;
|
|
883
|
+
message: { role: string; content: string };
|
|
884
|
+
finish_reason: string;
|
|
885
|
+
}>;
|
|
886
|
+
usage?: {
|
|
887
|
+
prompt_tokens: number;
|
|
888
|
+
completion_tokens: number;
|
|
889
|
+
total_tokens: number;
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// Agent 消息
|
|
894
|
+
interface AgentMessage {
|
|
895
|
+
role: 'developer' | 'user' | 'assistant' | 'tool';
|
|
896
|
+
content: Array<
|
|
897
|
+
| { type: 'text'; text: string }
|
|
898
|
+
| { type: 'image_url'; image_url: { url: string } }
|
|
899
|
+
| { type: 'video_url'; video_url: { url: string } }
|
|
900
|
+
>;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// 扫描
|
|
904
|
+
interface ScanParams {
|
|
905
|
+
uri?: string;
|
|
906
|
+
img_base64?: string;
|
|
907
|
+
risk_types: ('POLITY' | 'EROTIC' | 'VIOLENT' | 'CHILD')[];
|
|
908
|
+
detected_age: 0 | 1;
|
|
909
|
+
is_video: 0 | 1;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
interface ScanResponse {
|
|
913
|
+
nsfw_level: number; // 0-6
|
|
914
|
+
label_items: string[];
|
|
915
|
+
risk_types: string[];
|
|
916
|
+
frame_results?: Array<{
|
|
917
|
+
frame_no: number;
|
|
918
|
+
nsfw_level: number;
|
|
919
|
+
label_items: string[];
|
|
920
|
+
}>;
|
|
921
|
+
}
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
---
|
|
925
|
+
|
|
926
|
+
## 🤝 贡献
|
|
927
|
+
|
|
928
|
+
欢迎贡献!请随时提交 Pull Request。
|
|
929
|
+
|
|
930
|
+
1. Fork 仓库
|
|
931
|
+
2. 创建您的特性分支 (`git checkout -b feature/amazing-feature`)
|
|
932
|
+
3. 提交您的更改 (`git commit -m '添加某个很棒的功能'`)
|
|
933
|
+
4. 推送到分支 (`git push origin feature/amazing-feature`)
|
|
934
|
+
5. 打开 Pull Request
|
|
935
|
+
|
|
936
|
+
---
|
|
937
|
+
|
|
938
|
+
## 📄 许可证
|
|
939
|
+
|
|
940
|
+
本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件。
|
|
941
|
+
|
|
942
|
+
---
|
|
943
|
+
|
|
944
|
+
## 🔗 链接
|
|
945
|
+
|
|
946
|
+
- **GitHub**: [https://github.com/SeaVerseAI/seacloud-sdk](https://github.com/SeaVerseAI/seacloud-sdk)
|
|
947
|
+
- **npm**: [https://www.npmjs.com/package/seacloud-sdk](https://www.npmjs.com/package/seacloud-sdk)
|
|
948
|
+
- **Issues**: [https://github.com/SeaVerseAI/seacloud-sdk/issues](https://github.com/SeaVerseAI/seacloud-sdk/issues)
|
|
949
|
+
- **文档**: [即将推出]
|
|
950
|
+
|
|
951
|
+
---
|
|
952
|
+
|
|
953
|
+
## 📞 支持
|
|
954
|
+
|
|
955
|
+
如果您有任何问题或需要帮助:
|
|
956
|
+
|
|
957
|
+
- 在 [GitHub Issues](https://github.com/SeaVerseAI/seacloud-sdk/issues) 上提出问题
|
|
958
|
+
- 查看 [examples](./examples_agent.ts) 文件夹
|
|
959
|
+
- 阅读 [API 文档](./seacloud-api.json)
|
|
960
|
+
|
|
961
|
+
---
|
|
962
|
+
|
|
963
|
+
<div align="center">
|
|
964
|
+
|
|
965
|
+
**由 SeaVerse AI 用 ❤️ 构建**
|
|
966
|
+
|
|
967
|
+
[⬆ 回到顶部](#seacloud-sdk)
|
|
968
|
+
|
|
969
|
+
</div>
|