@henjicc/ai-sdk 0.3.0 → 0.4.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/CHANGELOG.md +12 -1
- package/README.md +20 -3
- package/dist/catalog/kie/gpt-image-2.5.model.js +1 -1
- package/dist/catalog/kie/gpt-image-2.model.js +0 -1
- package/dist/llm/discovery.d.ts +2 -0
- package/dist/llm/discovery.js +16 -5
- package/dist/llm/modelCatalogEntries.js +16 -0
- package/dist/llm/providerPresets.d.ts +3 -1
- package/dist/llm/providerPresets.js +4 -1
- package/dist/llm/providerReasoningRequest.js +14 -1
- package/dist/llm/siliconflow/index.d.ts +21 -0
- package/dist/llm/siliconflow/index.js +32 -0
- package/dist/llm/siliconflow/preset.d.ts +6 -0
- package/dist/llm/siliconflow/preset.js +33 -0
- package/docs/consumers.md +14 -6
- package/docs/llm-adaptation/README.md +3 -1
- package/docs/model-adaptation//344/276/233/345/272/224/345/225/206//347/241/205/345/237/272/346/265/201/345/212/250.md +45 -2
- package/examples/form-renderer/README.md +1 -1
- package/examples/form-renderer/package.json +1 -1
- package/examples/llm-chat/README.md +1 -1
- package/examples/llm-chat/package.json +1 -1
- package/examples/minimal-node/README.md +1 -1
- package/examples/minimal-node/package.json +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
# Changelog
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.1 - 2026-09-11
|
|
4
|
+
|
|
5
|
+
- 修复 KIE GPT Image 2 / 2.5 误带参考生视频标签;保留图片生成、编辑、多图输入与原有请求契约。
|
|
6
|
+
- 增加全目录输出模态与视频能力标签一致性回归检查,防止图片模型再次显示视频功能。
|
|
7
|
+
|
|
8
|
+
## 0.4.0 - 2026-09-11
|
|
9
|
+
|
|
10
|
+
- 新增硅基流动 LLM 按需入口与四个常用模型预设,支持流式正文、思考和工具调用,复用聊天与模型步骤运行时。
|
|
11
|
+
- 硅基流动模型发现支持服务端 chat / embedding / reranker 分类,保留新模型;无效响应不再伪装为空列表。
|
|
12
|
+
- DeepSeek 官方默认仍为 V4.1 Flash;硅基流动托管模型使用独立协议与能力标注。
|
|
2
13
|
|
|
3
14
|
## 0.3.0 - 2026-09-11
|
|
4
15
|
|
package/README.md
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
# @henjicc/ai-sdk
|
|
2
2
|
|
|
3
3
|
痕迹AI 的多供应商模型 SDK:内含 8 个生成供应商、109 个图片/视频/音频模型,以及
|
|
4
|
-
|
|
4
|
+
10 个 LLM 供应商预设和 15 个按需 ASR 模型。另有 12 个 FAL 图片工具使用独立按需入口,不进入默认 109 模型目录。预制 LLM 会按供应商与具体模型自动选择 Responses API 或 Chat Completions,宿主不需要暴露逐模型协议设置。SDK 负责目录、请求构建、媒体预处理、
|
|
5
5
|
供应商调用、轮询、SSE 与错误归一化;宿主只需注入网络、凭据、媒体读取和日志。
|
|
6
6
|
|
|
7
7
|
## 5 分钟快速开始
|
|
8
8
|
|
|
9
|
+
### 硅基流动聊天与实时模型列表
|
|
10
|
+
|
|
11
|
+
`llm/siliconflow` 提供四个推荐预设(DeepSeek V4 Flash、GLM-5.3、Kimi K2.7 Code、Qwen3.8-27B),并通过官方 `GET /v1/models` 获取账号当前可用模型,不受预设名单限制。
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { discoverSiliconflowModels, runSiliconflowChatStream } from '@henjicc/ai-sdk/llm/siliconflow'
|
|
15
|
+
|
|
16
|
+
const models = await discoverSiliconflowModels(runtime, { modelType: 'chat' })
|
|
17
|
+
// modelType 也支持 embedding / reranker;分别读取 llm / embedding / rerank 凭据。
|
|
18
|
+
const result = await runSiliconflowChatStream({
|
|
19
|
+
modelId: 'deepseek-ai/DeepSeek-V4-Flash',
|
|
20
|
+
messages: [{ role: 'user', content: '你好' }],
|
|
21
|
+
}, 'chat-1', event => console.log(event), runtime)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
动态列表不提供完整能力或价格,缺失的上下文与输出限制保持 `null`。新模型可直接传入 `modelId`;宿主按官方资料提供能力配置。硅基流动的 V4 Flash 与 DeepSeek 官方默认 `deepseek-flash`(V4.1)不同,全局默认不变。详见[硅基流动适配资料](docs/model-adaptation/供应商/硅基流动.md)。
|
|
25
|
+
|
|
9
26
|
### 文本向量与重排序
|
|
10
27
|
|
|
11
28
|
通过 `capabilities/embedding/<provider>` 和 `capabilities/rerank/<provider>` 按需导入。硅基流动、百炼、派欧云和智谱支持两类能力;火山目前支持单条文本向量。模型清单与限制见 [检索适配资料](docs/model-adaptation/README.md#文本-embedding--rerank2026-09-11)。输入仅支持文本;不自动切块、重试或合并多次付费请求。
|
|
@@ -31,10 +48,10 @@ try {
|
|
|
31
48
|
|
|
32
49
|
百炼工厂必须传 `baseUrl` 为实际地域/工作空间的 API 根地址,不包含端点路径。其他供应商可以覆盖根地址与 `credentialId`;SDK 不自动切换地域或账号。不同模型的向量不能混用;切换模型通常需要重建向量索引。Rerank 分数仅在本次请求内比较。
|
|
33
50
|
|
|
34
|
-
SDK `0.
|
|
51
|
+
SDK `0.4.1` 的正式分发渠道为公共 npm,无需配置 registry 或访问令牌:
|
|
35
52
|
|
|
36
53
|
```bash
|
|
37
|
-
npm install @henjicc/ai-sdk@0.
|
|
54
|
+
npm install @henjicc/ai-sdk@0.4.1
|
|
38
55
|
```
|
|
39
56
|
|
|
40
57
|
然后提供 4 个宿主能力(`Transport` / `CredentialStore` / `MediaReader` / `Logger`),创建客户端:
|
|
@@ -5,7 +5,7 @@ export const kieGptImage25Model = defineModel({
|
|
|
5
5
|
meta: {
|
|
6
6
|
id: 'kie-gpt-image-2.5', canonicalModelId: 'gpt-image-2.5', seriesId: 'gpt-image', seriesRank: 2.5,
|
|
7
7
|
provider: 'kie', type: 'image',
|
|
8
|
-
tags: ['text-to-image', 'image-to-image', 'supports-image-editing', 'supports-multi-image', '
|
|
8
|
+
tags: ['text-to-image', 'image-to-image', 'supports-image-editing', 'supports-multi-image', 'supports-4k', 'provider-kie'],
|
|
9
9
|
},
|
|
10
10
|
inputLimits: { images: { max: 16 }, videos: { max: 0 } },
|
|
11
11
|
params: [
|
package/dist/llm/discovery.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ interface RawDiscoveredModel {
|
|
|
28
28
|
active?: unknown;
|
|
29
29
|
}
|
|
30
30
|
export interface DiscoverModelsOptions {
|
|
31
|
+
/** 硅基流动的服务端模型分类;其他供应商不接受此选项。 */
|
|
32
|
+
modelType?: 'chat' | 'embedding' | 'reranker';
|
|
31
33
|
providerFamilyId?: string;
|
|
32
34
|
endpointProfile?: string;
|
|
33
35
|
credentialId?: string;
|
package/dist/llm/discovery.js
CHANGED
|
@@ -14,6 +14,8 @@ function optionalPositiveInteger(...values) {
|
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
export function parseDiscoveredModel(item) {
|
|
17
|
+
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
18
|
+
return null;
|
|
17
19
|
const modelId = optionalText(item.id);
|
|
18
20
|
if (!modelId)
|
|
19
21
|
return null;
|
|
@@ -32,11 +34,18 @@ export async function discoverModels(providerId, baseUrl, runtime, options = {})
|
|
|
32
34
|
credentialId: options.credentialId,
|
|
33
35
|
baseUrl,
|
|
34
36
|
});
|
|
35
|
-
const
|
|
36
|
-
if (options.
|
|
37
|
+
const siliconflow = identity.providerFamilyId === 'siliconflow';
|
|
38
|
+
if (options.modelType !== undefined && (!siliconflow || !['chat', 'embedding', 'reranker'].includes(options.modelType))) {
|
|
39
|
+
throw new Error('modelType 仅支持硅基流动 chat / embedding / reranker');
|
|
40
|
+
}
|
|
41
|
+
const modelType = options.modelType ?? 'chat';
|
|
42
|
+
const scope = siliconflow && modelType !== 'chat' ? (modelType === 'reranker' ? 'rerank' : 'embedding') : 'llm';
|
|
43
|
+
const apiKey = await runtime.credentials.get(scope, identity.credentialId);
|
|
44
|
+
if ((options.requireCredential || siliconflow) && !apiKey) {
|
|
37
45
|
throw new Error(`[api_key_missing] LLM provider "${providerId}" API key is not configured.`);
|
|
38
46
|
}
|
|
39
|
-
const
|
|
47
|
+
const endpoint = resolveModelsEndpoint(identity.baseUrl ?? baseUrl);
|
|
48
|
+
const url = siliconflow ? `${endpoint}?sub_type=${modelType}` : endpoint;
|
|
40
49
|
const headers = { Accept: 'application/json' };
|
|
41
50
|
if (apiKey) {
|
|
42
51
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
@@ -52,8 +61,10 @@ export async function discoverModels(providerId, baseUrl, runtime, options = {})
|
|
|
52
61
|
if (!response.ok)
|
|
53
62
|
throw new Error(`获取模型列表失败: ${response.status}`);
|
|
54
63
|
const data = await response.json();
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
if (!data || !Array.isArray(data.data))
|
|
65
|
+
throw new Error('获取模型列表失败: 无效的 data 数组');
|
|
66
|
+
return data.data
|
|
67
|
+
.filter(item => !options.activeOnly || item?.active !== false)
|
|
57
68
|
.map(parseDiscoveredModel)
|
|
58
69
|
.filter((item) => item !== null);
|
|
59
70
|
}
|
|
@@ -12,6 +12,22 @@
|
|
|
12
12
|
* 否则用户会得到"勾了但发过去没反应"的静默失效。
|
|
13
13
|
*/
|
|
14
14
|
export const LLM_MODEL_CATALOG_ENTRIES = [
|
|
15
|
+
// 硅基流动模型页与 Chat VLM 契约;未确认的视频字段和输出上限不猜测。
|
|
16
|
+
...[
|
|
17
|
+
{ id: 'kimi-k2.7-code', displayName: 'Kimi K2.7 Code', vendor: 'Moonshot' },
|
|
18
|
+
{ id: 'qwen3.8-27b', displayName: 'Qwen3.8-27B', vendor: 'Qwen' },
|
|
19
|
+
].map(model => ({
|
|
20
|
+
...model,
|
|
21
|
+
input: { image: true, video: false, audio: false },
|
|
22
|
+
toolCall: true,
|
|
23
|
+
parallelTools: false,
|
|
24
|
+
structuredOutputMode: 'json',
|
|
25
|
+
reasoning: true,
|
|
26
|
+
sampling: true,
|
|
27
|
+
contextWindow: 262_144,
|
|
28
|
+
maxOutputTokens: null,
|
|
29
|
+
docs: 'docs/model-adaptation/供应商/硅基流动.md',
|
|
30
|
+
})),
|
|
15
31
|
// ---------------- OpenAI GPT-OSS(Groq 托管) ----------------
|
|
16
32
|
{
|
|
17
33
|
id: 'gpt-oss-20b',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LlmApiProtocol } from './providerProtocol.js';
|
|
2
|
-
import type { LlmModelConfig, LlmProviderConfig, LlmReasoningEffort } from './types.js';
|
|
2
|
+
import type { LlmCapabilities, LlmModelConfig, LlmProviderConfig, LlmReasoningEffort } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* 内置供应商预设。
|
|
5
5
|
*
|
|
@@ -25,6 +25,8 @@ export interface LlmProviderPreset {
|
|
|
25
25
|
reasoningConfigurable: boolean;
|
|
26
26
|
/** 添加该供应商时一并建好的推荐模型,能力按内置目录自动标注 */
|
|
27
27
|
modelIds: readonly string[];
|
|
28
|
+
/** 托管供应商已核验的能力覆盖;不能把原厂能力无条件套给聚合接口。 */
|
|
29
|
+
modelCapabilities?: Readonly<Record<string, Partial<LlmCapabilities>>>;
|
|
28
30
|
/** 这家供应商已确认可走 Responses 的具体模型;未列出的模型继续走 Chat Completions。 */
|
|
29
31
|
responsesModelIds?: readonly string[];
|
|
30
32
|
websiteUrl: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_DEEPSEEK_BASE_URL, DEFAULT_DEEPSEEK_PROVIDER_ID, DEFAULT_PPIO_BASE_URL, DEFAULT_PPIO_PROVIDER_ID, createLlmCapabilitiesForModel, } from './defaults.js';
|
|
2
2
|
import { findLlmModelCatalogEntry, modelSupportsLlmApiProtocol } from './modelCatalog.js';
|
|
3
3
|
import { GROQ_PROVIDER_PRESET } from './groq/preset.js';
|
|
4
|
+
import { SILICONFLOW_PROVIDER_PRESET } from './siliconflow/preset.js';
|
|
4
5
|
import { createBigmodelProvider } from './bigmodel/preset.js';
|
|
5
6
|
import { BIGMODEL_ENDPOINT_PROFILE_FAMILY } from './bigmodel/profiles.js';
|
|
6
7
|
import { findProviderMetadata } from '../providers/metadata.js';
|
|
@@ -12,6 +13,7 @@ function providerMetadata(providerId) {
|
|
|
12
13
|
}
|
|
13
14
|
export const LLM_PROVIDER_PRESETS = [
|
|
14
15
|
GROQ_PROVIDER_PRESET,
|
|
16
|
+
SILICONFLOW_PROVIDER_PRESET,
|
|
15
17
|
{
|
|
16
18
|
providerId: DEFAULT_PPIO_PROVIDER_ID,
|
|
17
19
|
displayName: '派欧云',
|
|
@@ -165,6 +167,7 @@ export function createProviderFromPreset(preset, options = {}) {
|
|
|
165
167
|
}
|
|
166
168
|
return {
|
|
167
169
|
providerId: options.providerId ?? preset.providerId,
|
|
170
|
+
...(preset.providerId === 'siliconflow' ? { providerFamilyId: preset.providerId } : {}),
|
|
168
171
|
credentialId: options.providerId ?? preset.providerId,
|
|
169
172
|
setup: {
|
|
170
173
|
kind: 'preset',
|
|
@@ -200,7 +203,7 @@ export function createModelsFromPreset(preset, provider) {
|
|
|
200
203
|
adapter: provider.adapter,
|
|
201
204
|
apiProtocol: resolvePresetModelApiProtocol(preset, modelId, provider.endpointProfile),
|
|
202
205
|
baseUrl: provider.baseUrl,
|
|
203
|
-
capabilities: createLlmCapabilitiesForModel(modelId),
|
|
206
|
+
capabilities: { ...createLlmCapabilitiesForModel(modelId), ...preset.modelCapabilities?.[modelId] },
|
|
204
207
|
catalogId: entry?.id,
|
|
205
208
|
enabled: true,
|
|
206
209
|
};
|
|
@@ -32,6 +32,15 @@ function pickEffort(effort, supported) {
|
|
|
32
32
|
return picked;
|
|
33
33
|
}
|
|
34
34
|
const PROVIDER_REASONING_BODY = {
|
|
35
|
+
// 硅基流动的思考开关与原厂不同;强度字段只发送给端点文档明确列举的模型。
|
|
36
|
+
siliconflow: (reasoning, body) => ({
|
|
37
|
+
enable_thinking: reasoning.enabled,
|
|
38
|
+
...(reasoning.enabled && typeof body.model === 'string' && [
|
|
39
|
+
'deepseek-ai/deepseek-v4-flash', 'pro/deepseek-ai/deepseek-v4', 'pro/zai-org/glm-5.2',
|
|
40
|
+
].includes(body.model.toLowerCase())
|
|
41
|
+
? { reasoning_effort: reasoning.effort === 'xhigh' || reasoning.effort === 'max' ? 'max' : 'high' }
|
|
42
|
+
: {}),
|
|
43
|
+
}),
|
|
35
44
|
// DeepSeek:官方要求 thinking 与 reasoning_effort 同时传;文档没有列举离散档位,
|
|
36
45
|
// 沿用此前 SDK 路径已有的 high / max 两档映射。
|
|
37
46
|
deepseek: reasoning => (reasoning.enabled
|
|
@@ -97,5 +106,9 @@ export function applyProviderReasoningRequestBody(providerId, adapter, body, rea
|
|
|
97
106
|
return body;
|
|
98
107
|
const key = resolveReasoningKey(providerId, adapter);
|
|
99
108
|
const build = key ? PROVIDER_REASONING_BODY[key] : defaultReasoningBody;
|
|
100
|
-
|
|
109
|
+
if (key === 'siliconflow') {
|
|
110
|
+
const { thinking: _thinking, reasoning_effort: _effort, ...clean } = body;
|
|
111
|
+
return { ...clean, ...build(reasoning, clean) };
|
|
112
|
+
}
|
|
113
|
+
return { ...body, ...build(reasoning, body) };
|
|
101
114
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RuntimeContext } from '../../runtime/RuntimeContext.js';
|
|
2
|
+
import { type LlmChatExecutionOptions, type LlmChatStreamHooks } from '../chat.js';
|
|
3
|
+
import type { LlmChatRequestDto, LlmStreamEmitter } from '../chatTypes.js';
|
|
4
|
+
import { type DiscoverModelsOptions } from '../discovery.js';
|
|
5
|
+
export * from './preset.js';
|
|
6
|
+
export type SiliconflowChatRequest = Omit<LlmChatRequestDto, 'providerId' | 'providerFamilyId' | 'modelId' | 'adapter' | 'baseUrl'> & {
|
|
7
|
+
providerId?: string;
|
|
8
|
+
modelId?: string;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
};
|
|
11
|
+
/** 未知动态模型仍可调用;能力不按名字猜测,可由宿主显式提供。 */
|
|
12
|
+
export declare function createSiliconflowChatRequest(request: SiliconflowChatRequest): LlmChatRequestDto;
|
|
13
|
+
export declare function runSiliconflowChatStream(request: SiliconflowChatRequest, taskId: string, emit: LlmStreamEmitter, runtime: RuntimeContext, options?: LlmChatExecutionOptions & {
|
|
14
|
+
hooks?: LlmChatStreamHooks;
|
|
15
|
+
}): Promise<import("../index.js").LlmChatStreamOutcome>;
|
|
16
|
+
/** 分类在服务器端完成;保留不在内置预设中的新模型,不自动注册或发起推理。 */
|
|
17
|
+
export declare function discoverSiliconflowModels(runtime: RuntimeContext, options?: Omit<DiscoverModelsOptions, 'providerFamilyId' | 'endpointProfile' | 'requireCredential'> & {
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
providerId?: string;
|
|
20
|
+
}): Promise<import("../index.js").DiscoveredModelItem[]>;
|
|
21
|
+
export type { RuntimeContext, LlmStreamEmitter, LlmChatExecutionOptions, LlmChatStreamHooks };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createLlmCapabilitiesForModel } from '../defaults.js';
|
|
2
|
+
import { runLlmChatStream } from '../chat.js';
|
|
3
|
+
import { discoverModels } from '../discovery.js';
|
|
4
|
+
import { SILICONFLOW_BASE_URL, SILICONFLOW_DEFAULT_MODEL_ID, SILICONFLOW_PROVIDER_PRESET } from './preset.js';
|
|
5
|
+
export * from './preset.js';
|
|
6
|
+
/** 未知动态模型仍可调用;能力不按名字猜测,可由宿主显式提供。 */
|
|
7
|
+
export function createSiliconflowChatRequest(request) {
|
|
8
|
+
const modelId = request.modelId?.trim() || SILICONFLOW_DEFAULT_MODEL_ID;
|
|
9
|
+
const known = SILICONFLOW_PROVIDER_PRESET.modelIds.includes(modelId);
|
|
10
|
+
return {
|
|
11
|
+
...request,
|
|
12
|
+
providerId: request.providerId ?? 'siliconflow',
|
|
13
|
+
providerFamilyId: 'siliconflow',
|
|
14
|
+
modelId,
|
|
15
|
+
adapter: 'openai',
|
|
16
|
+
baseUrl: request.baseUrl?.trim() || SILICONFLOW_BASE_URL,
|
|
17
|
+
capabilities: request.capabilities ?? (known ? {
|
|
18
|
+
...createLlmCapabilitiesForModel(modelId),
|
|
19
|
+
...SILICONFLOW_PROVIDER_PRESET.modelCapabilities?.[modelId],
|
|
20
|
+
} : undefined),
|
|
21
|
+
reasoning: request.reasoning ?? (known ? { ...SILICONFLOW_PROVIDER_PRESET.reasoning } : undefined),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export async function runSiliconflowChatStream(request, taskId, emit, runtime, options = {}) {
|
|
25
|
+
const { hooks = {}, ...execution } = options;
|
|
26
|
+
return runLlmChatStream(createSiliconflowChatRequest(request), taskId, emit, runtime, hooks, execution);
|
|
27
|
+
}
|
|
28
|
+
/** 分类在服务器端完成;保留不在内置预设中的新模型,不自动注册或发起推理。 */
|
|
29
|
+
export async function discoverSiliconflowModels(runtime, options = {}) {
|
|
30
|
+
const { baseUrl = SILICONFLOW_BASE_URL, providerId = 'siliconflow', ...discovery } = options;
|
|
31
|
+
return discoverModels(providerId, baseUrl, runtime, { ...discovery, providerFamilyId: 'siliconflow', requireCredential: true });
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LlmProviderPreset } from '../providerPresets.js';
|
|
2
|
+
export declare const SILICONFLOW_PROVIDER_ID = "siliconflow";
|
|
3
|
+
export declare const SILICONFLOW_BASE_URL = "https://api.siliconflow.cn/v1";
|
|
4
|
+
export declare const SILICONFLOW_DEFAULT_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash";
|
|
5
|
+
/** 国内托管能力以硅基流动为准,不继承原厂专属协议与未确认的输出上限。 */
|
|
6
|
+
export declare const SILICONFLOW_PROVIDER_PRESET: LlmProviderPreset;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { findProviderMetadata } from '../../providers/metadata.js';
|
|
2
|
+
export const SILICONFLOW_PROVIDER_ID = 'siliconflow';
|
|
3
|
+
export const SILICONFLOW_BASE_URL = 'https://api.siliconflow.cn/v1';
|
|
4
|
+
export const SILICONFLOW_DEFAULT_MODEL_ID = 'deepseek-ai/DeepSeek-V4-Flash';
|
|
5
|
+
const metadata = findProviderMetadata(SILICONFLOW_PROVIDER_ID);
|
|
6
|
+
if (!metadata)
|
|
7
|
+
throw new Error('[provider_metadata_missing] siliconflow');
|
|
8
|
+
/** 国内托管能力以硅基流动为准,不继承原厂专属协议与未确认的输出上限。 */
|
|
9
|
+
export const SILICONFLOW_PROVIDER_PRESET = {
|
|
10
|
+
providerId: SILICONFLOW_PROVIDER_ID,
|
|
11
|
+
displayName: '硅基流动',
|
|
12
|
+
adapter: 'openai',
|
|
13
|
+
apiProtocol: 'openai-compatible',
|
|
14
|
+
baseUrl: SILICONFLOW_BASE_URL,
|
|
15
|
+
reasoning: { enabled: true, effort: 'high' },
|
|
16
|
+
reasoningConfigurable: true,
|
|
17
|
+
modelIds: [
|
|
18
|
+
SILICONFLOW_DEFAULT_MODEL_ID,
|
|
19
|
+
'zai-org/GLM-5.3',
|
|
20
|
+
'moonshotai/Kimi-K2.7-Code',
|
|
21
|
+
'Qwen/Qwen3.8-27B',
|
|
22
|
+
],
|
|
23
|
+
modelCapabilities: {
|
|
24
|
+
'zai-org/GLM-5.3': {
|
|
25
|
+
image: false, video: false, audio: false, file: false,
|
|
26
|
+
sampling: true, contextWindow: 1_048_576, maxOutputTokens: null,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
websiteUrl: metadata.websiteUrl,
|
|
30
|
+
apiKeyUrl: metadata.apiKeyUrl,
|
|
31
|
+
docs: 'docs/model-adaptation/供应商/硅基流动.md',
|
|
32
|
+
note: '预设只列常用模型;通过模型发现获取账号可用清单。这里的 DeepSeek V4 Flash 与 DeepSeek 官方 V4.1 Flash 是不同模型。',
|
|
33
|
+
};
|
package/docs/consumers.md
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
本清单是 `@henjicc/ai-sdk` 消费方的唯一维护入口,用于 SDK 发布后的跨仓升级协调。
|
|
4
4
|
绝对路径仅描述当前开发机上的仓库位置,不进入 SDK 运行时代码、发布包或用户配置。
|
|
5
5
|
|
|
6
|
-
最后核对日期:2026-09-
|
|
6
|
+
最后核对日期:2026-09-11
|
|
7
7
|
|
|
8
|
-
当前 SDK 版本:`0.
|
|
8
|
+
当前 SDK 版本:`0.4.1`(候选版本,待 CI 与公共 npm 发布)
|
|
9
|
+
|
|
10
|
+
`0.4.1`:修复 KIE GPT Image 2 / 2.5 的视频参考误标签,图片生成、编辑、多图输入及请求契约保持不变。109 个生成模型的跨模态视频标签检查、67 项定向测试、SDK 862 项全量测试、可移植性、类型构建及仓外公开入口/受限宿主回装通过。外部消费者登记版本为 `0.2.8`:say-it 不使用图片模型,不受影响;henji-ai-ps 的 KIE GPT Image 2 标签消费情况需在该项目可访问时核实,尚未升级。
|
|
11
|
+
|
|
12
|
+
`0.4.0`:新增硅基流动聊天预设与分类模型发现,提交 `a678dab6` 已推送,必需 CI `34565921443` 全部通过。SDK 861 项测试、宿主配置 15 项测试、类型构建、49 个公开入口及受限宿主候选包回装通过;未执行真实付费推理。移除服务端分类参数的断牙验证使 4 项测试失败,恢复后全量通过。
|
|
13
|
+
|
|
14
|
+
账号网页二次验证已完成,正式包与候选包校验值一致。已在仓外隔离 npm 配置并移除令牌环境变量,从公共 npm 匿名安装精确版本:Node ESM、严格 TypeScript、Vite 49 个入口及无 TextEncoder/TextDecoder 的受限宿主验证通过,包含硅基流动动态模型发现。仓内 workspace 与三个示例 manifest 已锁定 `0.4.0`;现有外部消费者未新增硅基流动聊天使用,暂不升级。
|
|
9
15
|
|
|
10
|
-
- tarball:`https://registry.npmjs.org/@henjicc/ai-sdk/-/ai-sdk-0.
|
|
11
|
-
- shasum:`
|
|
12
|
-
- integrity:`sha512-
|
|
16
|
+
- tarball:`https://registry.npmjs.org/@henjicc/ai-sdk/-/ai-sdk-0.4.0.tgz`
|
|
17
|
+
- shasum:`29a267d8a9f8375ac08b5af94569939473ab6a17`
|
|
18
|
+
- integrity:`sha512-4D2gHakuo7Fhhh3a987qrObqJd78k8mIhXPL9dgE3A5uywBi4ebHj7U4XVLUcbjv/HO34wH/+8kFlE5JMOGD0g==`
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
`0.3.0` 已发布:新增四家 GPT Image 2.5 pack、五家文本 embedding / 四家 rerank,DeepSeek 官方默认模型更新为 `deepseek-flash`。发布提交 `a2dc5bc4` 的必需 CI 门禁全部通过(运行 `34532267703`),SDK 全量 839 项测试和候选包回装通过。正式包已在隔离 npm 配置、无用户令牌的仓外环境从公共 npm 安装,标准 Vite 48 个入口与受限宿主验证通过;正式包校验值与候选包一致。未运行真实付费模型请求。
|
|
21
|
+
|
|
22
|
+
Henji-AI workspace 与三个仓内示例 manifest 均锁定 `0.4.0`;下表原有示例运行记录仅代表 `0.2.8` 历史证据,本次未完成三个示例的独立全套回装复验。`say-it` 已在 `D:/VibeCode/说吧` 定位,仍锁定公共 npm `0.2.8`,实际按需使用 ASR、translation 与 LLM modules,未使用本次新增硅基流动聊天能力,无需机械升级;未运行其真实宿主验收。`henji-ai-ps` 的下表路径为另一台开发机记录,本机未定位该路径,不声称本次完成外部升级。
|
|
15
23
|
|
|
16
24
|
## 判定口径
|
|
17
25
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
| 项目 | 内容 |
|
|
4
4
|
|---|---|
|
|
5
|
-
| 最后更新 | 2026-
|
|
5
|
+
| 最后更新 | 2026-09-11 |
|
|
6
6
|
| 供应商 | SiliconFlow / SiliconCloud |
|
|
7
7
|
| 建议 `providerId` | `siliconflow` |
|
|
8
8
|
| Base URL | `https://api.siliconflow.cn/v1` |
|
|
@@ -10,7 +10,50 @@
|
|
|
10
10
|
| 已核验 ASR 类型 | 同步文件语音转写 API |
|
|
11
11
|
| 文档/价格可见性 | 公开,无需登录;API Key、实名、用量和账单需登录 |
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## LLM 与动态模型发现(2026-09-11)
|
|
14
|
+
|
|
15
|
+
本节依据国内控制台模型详情、官方 Chat Completions / Models 文档和实时价格页。控制台已登录核验;公开文档与价格页无需登录。模型名字保留大小写与厂商前缀,不把硅基流动的 DeepSeek V4 Flash 冒充 DeepSeek 官方 `deepseek-flash`(V4.1)。
|
|
16
|
+
|
|
17
|
+
| 展示名 / API model ID | 已核验输入 / 工具 | 上下文 | 每百万 tokens 输入 / 输出 / 缓存命中(人民币) |
|
|
18
|
+
|---|---|---|---|
|
|
19
|
+
| DeepSeek V4 Flash / `deepseek-ai/DeepSeek-V4-Flash` | 文本 / 工具调用 | 1,000,000;模型页声明最高输出 384K | 3 / 9 / 0.3;价格页另有 2–8 点 1.5 / 4.5 / 0.15,时段以平台账单为准 |
|
|
20
|
+
| GLM-5.3 / `zai-org/GLM-5.3` | 文本 / 工具调用 / 结构化输出 | 1,048,576;托管输出上限未明确,留空 | 8 / 28 / 2 |
|
|
21
|
+
| Kimi K2.7 Code / `moonshotai/Kimi-K2.7-Code` | 文本、图片 / 工具调用 | 256K;托管输出上限留空 | 6.5 / 27 / 1.3 |
|
|
22
|
+
| Qwen3.8-27B / `Qwen/Qwen3.8-27B` | 文本、图片 / 工具调用 | 256K;托管输出上限留空 | 3 / 12 / 未列出 |
|
|
23
|
+
|
|
24
|
+
控制台价格单元格实际显示 `/K Tokens`(如 Qwen 输入 0.003、输出 0.012),虽然表头按钮写 M Tokens;上表按单元格单位换算,并与公开价格页交叉核对。Kimi/Qwen 模型介绍包含视频能力,但本次不声明视频输入:未取得该托管接口的视频消息字段契约。常用预设不是全部在售清单,动态发现结果不以预设白名单过滤。
|
|
25
|
+
|
|
26
|
+
### 发现接口
|
|
27
|
+
|
|
28
|
+
`GET https://api.siliconflow.cn/v1/models?sub_type=chat`,Bearer 鉴权。`sub_type` 可独立筛选,支持 `chat`、`embedding`、`reranker` 等;本 SDK 检索接口对外 `reranker` 按凭据用途映射为 `rerank`,聊天映射 `llm`。不同时传 `type=text`,避免错误排除支持视觉的聊天模型。
|
|
29
|
+
|
|
30
|
+
成功体 `{object:"list",data:[{id,object:"model",created,owned_by}]}`。官方示例只给基础身份字段,未提供价格、上下文或完整能力;未知模型保留原 ID,不根据名字猜能力。空 `data:[]` 是合法结果;缺失 data、非数组、平台错误体不得伪装为空列表。取消/超时通过宿主 AbortSignal 传递;不自动重试。SDK 不在无凭据时尝试匿名列举。
|
|
31
|
+
|
|
32
|
+
### 聊天接口与事件矩阵
|
|
33
|
+
|
|
34
|
+
`POST https://api.siliconflow.cn/v1/chat/completions`,Bearer、JSON。必填 `model` 与 `messages`;`stream:true` 返回 SSE,以 `data: [DONE]` 结束。消息复用 OpenAI 兼容结构,图片为 `image_url` 内容块;工具为 `tools[].function`,最多 128 个。支持 `max_tokens`、`temperature`、`top_p`、`response_format`。输出上限不得直接等于上下文窗口;官方建议预留输入空间。
|
|
35
|
+
|
|
36
|
+
思考开关使用 `enable_thinking`,不发送 DeepSeek 原厂的 `thinking` 对象。官方字段表明确 `reasoning_effort` 仅支持 high/max,并列举 DeepSeek V4 Flash、Pro/DeepSeek V4、Pro/GLM-5.2;本次四个预设仅给 DeepSeek V4 Flash 发送该字段。关闭思考时只发 `enable_thinking:false`。其他预设发送布尔开关,不根据模型营销介绍猜强度枚举。GLM-5.3 的官方原厂能力配置不能覆盖硅基流动托管限制。
|
|
37
|
+
|
|
38
|
+
| 事件/状态 | 字段与空值语义 | 输出与状态 | 终态 / 资源 |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| HTTP 成功开始 SSE | choices 数组;delta.content 可空串、reasoning_content 可 null、finish_reason 可 null(官方 Streaming 首帧) | 空始帧不输出文本,继续读取 | 未终止;复用当前响应流 |
|
|
41
|
+
| 文本/思考 delta | content / reasoning_content 字符串增量,缺失/null 不追加 | 分别输出正文与思考 | 继续读取 |
|
|
42
|
+
| 工具 delta | delta.tool_calls 的 index、id、function.name/arguments;arguments 增量拼接 | 保留工具身份与参数,交共享解析器 | 继续读取 |
|
|
43
|
+
| finish / usage | finish_reason 标记 stop、length、tool_calls;usage 的 prompt/completion/total 与可选 reasoning/cached tokens | 归一化终态原因和用量;usage 可随首帧出现 | 等待 DONE/结束并释放 reader |
|
|
44
|
+
| `[DONE]` | SSE 数据字面值 | 结束当前响应;空有效输出按共享内核处理 | 释放 reader,不重复 POST |
|
|
45
|
+
| 400/401/403/404/429/503/504 | JSON code/message/data 或纯文本;不得当成输出 | 明确失败 | 释放资源,不自动重试计费请求 |
|
|
46
|
+
| 取消/超时/断流 | 官方未说明断点续传、恢复或取消退费 | 使用宿主取消与共享内核超时/断流契约 | 释放 reader/计时器;不重放 |
|
|
47
|
+
|
|
48
|
+
官方未承诺乱序、重复事件去重或断线恢复,本次沿用同一个 OpenAI SSE 执行内核,不创建硅基流动专属 parser。fixture 区分官方首帧/模型列表字面样例与依据字段构造的后续增量、工具回合及合成负例;不声称真实付费成功。
|
|
49
|
+
|
|
50
|
+
来源:
|
|
51
|
+
- [模型列表 API](https://api-docs.siliconflow.cn/docs/api/models-get):筛选参数、鉴权、基础身份字段和错误,公开。
|
|
52
|
+
- [Chat Completions](https://api-docs.siliconflow.cn/docs/api/chat-completions-post):LLM/VLM Tab、Streaming/Function 示例、请求字段与错误,公开。
|
|
53
|
+
- [实时价格](https://siliconflow.cn/pricing):输入/输出/缓存与时段,公开。
|
|
54
|
+
- [国内模型广场](https://cloud.siliconflow.cn/me/models):逐项查看四个模型的详情、能力、价格;本次使用已登录会话。
|
|
55
|
+
|
|
56
|
+
## 1. ASR 端点与请求
|
|
14
57
|
|
|
15
58
|
```text
|
|
16
59
|
POST https://api.siliconflow.cn/v1/audio/transcriptions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# form-renderer
|
|
2
2
|
|
|
3
|
-
无框架、无 DOM 依赖的 `@henjicc/ai-sdk@0.
|
|
3
|
+
无框架、无 DOM 依赖的 `@henjicc/ai-sdk@0.4.1` 参数表单契约示例。它从 `client.catalog` 读取真实模型,使用
|
|
4
4
|
`evaluateRuntimeCondition()` 处理显隐/禁用,使用 `getRuntimeMediaInputContract()` 生成媒体上传入口。
|
|
5
5
|
示例只使用 `generation`、`catalog` 与 `runtime` 按需入口,保留完整 generation catalog,
|
|
6
6
|
但不会带入 LLM/BigModel。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# llm-chat
|
|
2
2
|
|
|
3
|
-
用 `@henjicc/ai-sdk@0.
|
|
3
|
+
用 `@henjicc/ai-sdk@0.4.1` 的 `llm/streaming` 按需入口走 OpenAI-compatible SSE 流式对话,
|
|
4
4
|
不会把 generation、BigModel preset/models/pricing、Groq 或 LLM modules 打进示例 bundle;
|
|
5
5
|
通用端点身份解析所需的 BigModel profiles 仍会保留。默认目标是
|
|
6
6
|
DeepSeek `deepseek-v4-flash`,提示词要求只回复 `SDK OK`,并限制最多 16 tokens。示例显式传入
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henjicc/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "痕迹AI 多供应商模型适配 SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -83,7 +83,12 @@
|
|
|
83
83
|
"import": "./dist/llm/streaming/index.js",
|
|
84
84
|
"default": "./dist/llm/streaming/index.js"
|
|
85
85
|
},
|
|
86
|
-
"./llm/
|
|
86
|
+
"./llm/siliconflow": {
|
|
87
|
+
"types": "./dist/llm/siliconflow/index.d.ts",
|
|
88
|
+
"import": "./dist/llm/siliconflow/index.js",
|
|
89
|
+
"default": "./dist/llm/siliconflow/index.js"
|
|
90
|
+
},
|
|
91
|
+
"./llm/groq": {
|
|
87
92
|
"types": "./dist/llm/groq/index.d.ts",
|
|
88
93
|
"import": "./dist/llm/groq/index.js",
|
|
89
94
|
"default": "./dist/llm/groq/index.js"
|