@open-dy/ai_coding_sdk 1.0.16 → 1.0.17
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.
|
@@ -8,9 +8,22 @@ exports.queryVideoTask = queryVideoTask;
|
|
|
8
8
|
exports.waitVideoTask = waitVideoTask;
|
|
9
9
|
exports.streamGenerate = streamGenerate;
|
|
10
10
|
const core_1 = require("./core");
|
|
11
|
+
const AI_PLATFORM_SOURCE = 4;
|
|
11
12
|
function sleep(ms) {
|
|
12
13
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
13
14
|
}
|
|
15
|
+
function withDefaultGenerateSource(req) {
|
|
16
|
+
return { ...req, Source: AI_PLATFORM_SOURCE };
|
|
17
|
+
}
|
|
18
|
+
function withDefaultStreamSource(req) {
|
|
19
|
+
return { ...req, source: AI_PLATFORM_SOURCE };
|
|
20
|
+
}
|
|
21
|
+
function withDefaultImageSource(req) {
|
|
22
|
+
return { ...req, Source: AI_PLATFORM_SOURCE };
|
|
23
|
+
}
|
|
24
|
+
function withDefaultVideoSource(req) {
|
|
25
|
+
return { ...req, Source: AI_PLATFORM_SOURCE };
|
|
26
|
+
}
|
|
14
27
|
class AIPlatformLLMClient {
|
|
15
28
|
constructor(options = {}) {
|
|
16
29
|
this.appEnv = (0, core_1.getAIPlatformAppEnv)();
|
|
@@ -22,7 +35,7 @@ class AIPlatformLLMClient {
|
|
|
22
35
|
this.gatewayOrigin = options.gatewayOrigin ?? (0, core_1.getAIPlatformGatewayOrigin)(this.appEnv);
|
|
23
36
|
}
|
|
24
37
|
async generate(req) {
|
|
25
|
-
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/generate/', req, {
|
|
38
|
+
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/generate/', withDefaultGenerateSource(req), {
|
|
26
39
|
accessToken: this.accessToken,
|
|
27
40
|
defaultHeaders: this.defaultHeaders,
|
|
28
41
|
appEnv: this.appEnv,
|
|
@@ -30,7 +43,7 @@ class AIPlatformLLMClient {
|
|
|
30
43
|
});
|
|
31
44
|
}
|
|
32
45
|
async generateImage(req) {
|
|
33
|
-
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/image_generate/', req, {
|
|
46
|
+
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/image_generate/', withDefaultImageSource(req), {
|
|
34
47
|
accessToken: this.accessToken,
|
|
35
48
|
defaultHeaders: this.defaultHeaders,
|
|
36
49
|
appEnv: this.appEnv,
|
|
@@ -38,7 +51,7 @@ class AIPlatformLLMClient {
|
|
|
38
51
|
});
|
|
39
52
|
}
|
|
40
53
|
async generateVideo(req) {
|
|
41
|
-
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/video_generate/', req, {
|
|
54
|
+
return (0, core_1.postAIPlatformJSON)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/video_generate/', withDefaultVideoSource(req), {
|
|
42
55
|
accessToken: this.accessToken,
|
|
43
56
|
defaultHeaders: this.defaultHeaders,
|
|
44
57
|
appEnv: this.appEnv,
|
|
@@ -70,7 +83,7 @@ class AIPlatformLLMClient {
|
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
async *streamGenerate(req) {
|
|
73
|
-
for await (const event of (0, core_1.streamAIPlatform)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/stream_generate/', req, {
|
|
86
|
+
for await (const event of (0, core_1.streamAIPlatform)(this.gatewayOrigin, '/dy_open_api/ai_platform/llm_gen/stream_generate/', withDefaultStreamSource(req), {
|
|
74
87
|
accessToken: this.accessToken,
|
|
75
88
|
defaultHeaders: this.defaultHeaders,
|
|
76
89
|
appEnv: this.appEnv,
|
|
@@ -60,7 +60,6 @@ export interface StreamGenerateRequest {
|
|
|
60
60
|
parameters: string;
|
|
61
61
|
}>;
|
|
62
62
|
extra?: Record<string, string>;
|
|
63
|
-
source: number;
|
|
64
63
|
}
|
|
65
64
|
export interface GenerateMessage {
|
|
66
65
|
Role: Role;
|
|
@@ -109,7 +108,6 @@ export interface GenerateRequest {
|
|
|
109
108
|
Parameters: string;
|
|
110
109
|
}>;
|
|
111
110
|
Extra?: Record<string, string>;
|
|
112
|
-
Source: number;
|
|
113
111
|
}
|
|
114
112
|
/**
|
|
115
113
|
* 图片生成请求。
|
|
@@ -144,7 +142,6 @@ export interface GenerateImageRequest {
|
|
|
144
142
|
Prompt: string;
|
|
145
143
|
ModelTenant: string;
|
|
146
144
|
ModelKey: string;
|
|
147
|
-
Source: number;
|
|
148
145
|
/**
|
|
149
146
|
* 字段语义依模型而变:
|
|
150
147
|
* - `glm-image`:可选图片输入
|
|
@@ -201,7 +198,6 @@ export interface GenerateVideoRequest {
|
|
|
201
198
|
Prompt: string;
|
|
202
199
|
ModelTenant: string;
|
|
203
200
|
ModelKey: string;
|
|
204
|
-
Source: number;
|
|
205
201
|
/**
|
|
206
202
|
* 示例:
|
|
207
203
|
* - Seedance Pro:首帧、首尾帧或参考图
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AIPlatformCallOptions, CheckMiniProgramModelPermissionRequest, CheckMiniProgramModelPermissionResponse } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* 判断小程序是否有目标模型权限。
|
|
4
|
-
* 这里保留原始响应,避免在未知响应结构上做过度假设。
|
|
5
|
-
*/
|
|
6
|
-
export declare function checkMiniProgramModelPermission(req: CheckMiniProgramModelPermissionRequest, options?: AIPlatformCallOptions): Promise<CheckMiniProgramModelPermissionResponse>;
|
|
7
|
-
/**
|
|
8
|
-
* 基于常见布尔字段做轻量归一化。
|
|
9
|
-
* 如果接口未返回这些字段,则返回 null,让上层自行读取原始响应。
|
|
10
|
-
*/
|
|
11
|
-
export declare function getMiniProgramModelPermissionStatus(response: CheckMiniProgramModelPermissionResponse): boolean | null;
|
|
12
|
-
/**
|
|
13
|
-
* 权限明确为 false 时抛错;响应里没有标准布尔字段时,只返回原始响应。
|
|
14
|
-
*/
|
|
15
|
-
export declare function assertMiniProgramModelPermission(req: CheckMiniProgramModelPermissionRequest, options?: AIPlatformCallOptions): Promise<CheckMiniProgramModelPermissionResponse>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkMiniProgramModelPermission = checkMiniProgramModelPermission;
|
|
4
|
-
exports.getMiniProgramModelPermissionStatus = getMiniProgramModelPermissionStatus;
|
|
5
|
-
exports.assertMiniProgramModelPermission = assertMiniProgramModelPermission;
|
|
6
|
-
const core_1 = require("./core");
|
|
7
|
-
/**
|
|
8
|
-
* 判断小程序是否有目标模型权限。
|
|
9
|
-
* 这里保留原始响应,避免在未知响应结构上做过度假设。
|
|
10
|
-
*/
|
|
11
|
-
async function checkMiniProgramModelPermission(req, options) {
|
|
12
|
-
return (0, core_1.postMiniProgramModelPermission)(req, options);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 基于常见布尔字段做轻量归一化。
|
|
16
|
-
* 如果接口未返回这些字段,则返回 null,让上层自行读取原始响应。
|
|
17
|
-
*/
|
|
18
|
-
function getMiniProgramModelPermissionStatus(response) {
|
|
19
|
-
const candidates = [
|
|
20
|
-
response.data?.allowed,
|
|
21
|
-
response.data?.allow,
|
|
22
|
-
response.data?.has_permission,
|
|
23
|
-
response.data?.can_use,
|
|
24
|
-
];
|
|
25
|
-
for (const candidate of candidates) {
|
|
26
|
-
if (typeof candidate === 'boolean') {
|
|
27
|
-
return candidate;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 权限明确为 false 时抛错;响应里没有标准布尔字段时,只返回原始响应。
|
|
34
|
-
*/
|
|
35
|
-
async function assertMiniProgramModelPermission(req, options) {
|
|
36
|
-
const response = await checkMiniProgramModelPermission(req, options);
|
|
37
|
-
const granted = getMiniProgramModelPermissionStatus(response);
|
|
38
|
-
if (granted === false) {
|
|
39
|
-
throw new Error(response.message ||
|
|
40
|
-
response.err_msg ||
|
|
41
|
-
'mini_program_model_permission_denied');
|
|
42
|
-
}
|
|
43
|
-
return response;
|
|
44
|
-
}
|