@vectorx/ai-sdk 0.5.1 → 0.6.2
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/lib/ai.js +2 -0
- package/lib/models/Qwen25T2iPreview/index.d.ts +76 -0
- package/lib/models/Qwen25T2iPreview/index.js +211 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.d.ts +25 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.js +179 -0
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.d.ts +24 -0
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.js +143 -0
- package/lib/models/QwenDocTurbo/index.d.ts +4 -72
- package/lib/models/QwenDocTurbo/index.js +51 -136
- package/lib/models/QwenDocTurbo/types.d.ts +124 -0
- package/lib/models/QwenDocTurbo/types.js +2 -0
- package/lib/models/index.d.ts +4 -1
- package/lib/models/index.js +5 -1
- package/lib/utils.js +11 -2
- package/package.json +2 -2
package/lib/ai.js
CHANGED
|
@@ -63,6 +63,8 @@ class AI {
|
|
|
63
63
|
return new models.ReActModel(new models.WanxSketchToImageLiteModel(this.request, models.WanxSketchToImageLiteModel.BASE_URL, this.tokenManager));
|
|
64
64
|
case models.MultiModalModelName.QwenStyleRepaintV1:
|
|
65
65
|
return new models.ReActModel(new models.QwenStyleRepaintV1Model(this.request, models.QwenStyleRepaintV1Model.BASE_URL, this.tokenManager));
|
|
66
|
+
case models.MultiModalModelName.Qwen25T2iPreview:
|
|
67
|
+
return new models.ReActModel(new models.Qwen25T2iPreviewModel(this.request, models.Qwen25T2iPreviewModel.BASE_URL, this.tokenManager));
|
|
66
68
|
case models.MultiModalModelName.QwenVlMax:
|
|
67
69
|
return new models.ReActModel(new models.QwenVlMax(this.request, models.QwenVlMax.BASE_URL, model, this.tokenManager));
|
|
68
70
|
case models.MultiModalModelName.QwenDocTurbo:
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../../model-type";
|
|
3
|
+
import { TokenManager } from "../../tokenManager";
|
|
4
|
+
import { SimpleChatModel } from "../Chat";
|
|
5
|
+
export interface Qwen25T2iPreviewParameters {
|
|
6
|
+
size?: string;
|
|
7
|
+
n?: number;
|
|
8
|
+
prompt_extend?: boolean;
|
|
9
|
+
watermark?: boolean;
|
|
10
|
+
seed?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Qwen25T2iPreviewAPIInput {
|
|
13
|
+
model: string;
|
|
14
|
+
input: {
|
|
15
|
+
prompt: string;
|
|
16
|
+
negative_prompt?: string;
|
|
17
|
+
images: string[];
|
|
18
|
+
};
|
|
19
|
+
parameters?: Qwen25T2iPreviewParameters;
|
|
20
|
+
}
|
|
21
|
+
export type Qwen25T2iPreviewRequestOptions = Qwen25T2iPreviewAPIInput & {
|
|
22
|
+
parameters?: Qwen25T2iPreviewParameters;
|
|
23
|
+
};
|
|
24
|
+
export interface Qwen25T2iPreviewAPIResponse {
|
|
25
|
+
async?: boolean;
|
|
26
|
+
output: {
|
|
27
|
+
choices?: Array<{
|
|
28
|
+
finish_reason: string;
|
|
29
|
+
message: {
|
|
30
|
+
role: "assistant" | "user";
|
|
31
|
+
content: Array<{
|
|
32
|
+
image?: string;
|
|
33
|
+
url?: string;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
task_status?: string;
|
|
38
|
+
task_id?: string;
|
|
39
|
+
task_metric?: {
|
|
40
|
+
TOTAL: number;
|
|
41
|
+
FAILED: number;
|
|
42
|
+
SUCCEEDED: number;
|
|
43
|
+
};
|
|
44
|
+
results?: Array<{
|
|
45
|
+
url?: string;
|
|
46
|
+
orig_prompt?: string;
|
|
47
|
+
actual_prompt?: string;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}>;
|
|
50
|
+
};
|
|
51
|
+
usage?: {
|
|
52
|
+
width?: number;
|
|
53
|
+
height?: number;
|
|
54
|
+
image_count?: number;
|
|
55
|
+
};
|
|
56
|
+
request_id?: string;
|
|
57
|
+
id?: string;
|
|
58
|
+
model?: string;
|
|
59
|
+
created?: number;
|
|
60
|
+
object?: string;
|
|
61
|
+
code?: number;
|
|
62
|
+
error?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare class Qwen25T2iPreviewModel extends SimpleChatModel {
|
|
65
|
+
static BASE_URL: string;
|
|
66
|
+
static SUB_GENERATION_URL: string;
|
|
67
|
+
modelName: string;
|
|
68
|
+
constructor(req: IAbstractRequest, baseUrl: string, tokenManager: TokenManager);
|
|
69
|
+
protected normalizeStandardImageCompletion(res: Qwen25T2iPreviewAPIResponse, fallbackModel: string): DoGenerateOutput;
|
|
70
|
+
protected coverModelRequestToQwenInput(data: ModelRequestOptions & {
|
|
71
|
+
parameters?: Qwen25T2iPreviewParameters;
|
|
72
|
+
}): Qwen25T2iPreviewRequestOptions;
|
|
73
|
+
protected modelRequest(data: Qwen25T2iPreviewRequestOptions, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
|
|
74
|
+
doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
75
|
+
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Qwen25T2iPreviewModel = void 0;
|
|
13
|
+
const stream_1 = require("../../stream");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const Chat_1 = require("../Chat");
|
|
16
|
+
class Qwen25T2iPreviewModel extends Chat_1.SimpleChatModel {
|
|
17
|
+
constructor(req, baseUrl, tokenManager) {
|
|
18
|
+
super(req, baseUrl, Qwen25T2iPreviewModel.SUB_GENERATION_URL, tokenManager);
|
|
19
|
+
this.modelName = "wan2.5-i2i-preview";
|
|
20
|
+
}
|
|
21
|
+
normalizeStandardImageCompletion(res, fallbackModel) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
23
|
+
const qOutput = (res === null || res === void 0 ? void 0 : res.output) || {};
|
|
24
|
+
if ((qOutput === null || qOutput === void 0 ? void 0 : qOutput.task_status) && (qOutput === null || qOutput === void 0 ? void 0 : qOutput.task_id)) {
|
|
25
|
+
const created = (_a = res === null || res === void 0 ? void 0 : res.created) !== null && _a !== void 0 ? _a : Math.floor(Date.now() / 1000);
|
|
26
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
27
|
+
const normalized = {
|
|
28
|
+
id,
|
|
29
|
+
object: (_b = res === null || res === void 0 ? void 0 : res.object) !== null && _b !== void 0 ? _b : "chat.completion",
|
|
30
|
+
created,
|
|
31
|
+
model: (_c = res === null || res === void 0 ? void 0 : res.model) !== null && _c !== void 0 ? _c : fallbackModel,
|
|
32
|
+
log_id: id,
|
|
33
|
+
error: (_d = res === null || res === void 0 ? void 0 : res.error) !== null && _d !== void 0 ? _d : "",
|
|
34
|
+
code: (_e = res === null || res === void 0 ? void 0 : res.code) !== null && _e !== void 0 ? _e : 0,
|
|
35
|
+
choices: [
|
|
36
|
+
{
|
|
37
|
+
index: 0,
|
|
38
|
+
message: {
|
|
39
|
+
id,
|
|
40
|
+
role: "assistant",
|
|
41
|
+
type: "async_task",
|
|
42
|
+
content: JSON.stringify(Object.assign(Object.assign({}, ((res === null || res === void 0 ? void 0 : res.output) || {})), { request_id: (res === null || res === void 0 ? void 0 : res.request_id) || id })),
|
|
43
|
+
reasoning_content: "",
|
|
44
|
+
},
|
|
45
|
+
finish_reason: "stop",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
usage: mapUsageToStandard(res === null || res === void 0 ? void 0 : res.usage),
|
|
49
|
+
};
|
|
50
|
+
return normalized;
|
|
51
|
+
}
|
|
52
|
+
const first = ((_g = (_f = qOutput === null || qOutput === void 0 ? void 0 : qOutput.choices) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : null);
|
|
53
|
+
const message = (_h = first === null || first === void 0 ? void 0 : first.message) !== null && _h !== void 0 ? _h : {};
|
|
54
|
+
const contentUrl = Array.isArray(message === null || message === void 0 ? void 0 : message.content) && ((_j = message.content[0]) === null || _j === void 0 ? void 0 : _j.image)
|
|
55
|
+
? String(message.content[0].image)
|
|
56
|
+
: Array.isArray(message === null || message === void 0 ? void 0 : message.content) && ((_k = message.content[0]) === null || _k === void 0 ? void 0 : _k.url)
|
|
57
|
+
? String(message.content[0].url)
|
|
58
|
+
: "";
|
|
59
|
+
const created = (_l = res === null || res === void 0 ? void 0 : res.created) !== null && _l !== void 0 ? _l : Math.floor(Date.now() / 1000);
|
|
60
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
61
|
+
const normalized = {
|
|
62
|
+
id,
|
|
63
|
+
object: (_m = res === null || res === void 0 ? void 0 : res.object) !== null && _m !== void 0 ? _m : "chat.completion",
|
|
64
|
+
created,
|
|
65
|
+
model: (_o = res === null || res === void 0 ? void 0 : res.model) !== null && _o !== void 0 ? _o : fallbackModel,
|
|
66
|
+
log_id: id,
|
|
67
|
+
error: (_p = res === null || res === void 0 ? void 0 : res.error) !== null && _p !== void 0 ? _p : "",
|
|
68
|
+
code: (_q = res === null || res === void 0 ? void 0 : res.code) !== null && _q !== void 0 ? _q : 0,
|
|
69
|
+
choices: [
|
|
70
|
+
{
|
|
71
|
+
index: 0,
|
|
72
|
+
message: {
|
|
73
|
+
id,
|
|
74
|
+
role: "assistant",
|
|
75
|
+
type: "image",
|
|
76
|
+
content: contentUrl || "",
|
|
77
|
+
reasoning_content: "",
|
|
78
|
+
},
|
|
79
|
+
finish_reason: (_r = first === null || first === void 0 ? void 0 : first.finish_reason) !== null && _r !== void 0 ? _r : "stop",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
usage: mapUsageToStandard(res === null || res === void 0 ? void 0 : res.usage),
|
|
83
|
+
};
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
coverModelRequestToQwenInput(data) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const imageUrls = [];
|
|
89
|
+
const texts = [];
|
|
90
|
+
let negativePrompt = "";
|
|
91
|
+
const messages = data.messages || data.history || [];
|
|
92
|
+
if (Array.isArray(messages) && messages.length > 0) {
|
|
93
|
+
const firstUser = (_a = messages.find((m) => (m === null || m === void 0 ? void 0 : m.role) === "user")) !== null && _a !== void 0 ? _a : messages[0];
|
|
94
|
+
const c = firstUser === null || firstUser === void 0 ? void 0 : firstUser.content;
|
|
95
|
+
if (Array.isArray(c)) {
|
|
96
|
+
for (const p of c) {
|
|
97
|
+
if ((p === null || p === void 0 ? void 0 : p.type) === "image_url" && ((_b = p.image_url) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
98
|
+
imageUrls.push(p.image_url.url);
|
|
99
|
+
}
|
|
100
|
+
else if ((p === null || p === void 0 ? void 0 : p.type) === "text" && typeof p.text === "string" && p.text.trim()) {
|
|
101
|
+
texts.push(p.text.trim());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (imageUrls.length === 0 && data.image) {
|
|
107
|
+
imageUrls.push(String(data.image));
|
|
108
|
+
}
|
|
109
|
+
if (imageUrls.length === 0 && data.images && Array.isArray(data.images)) {
|
|
110
|
+
imageUrls.push(...data.images);
|
|
111
|
+
}
|
|
112
|
+
if (texts.length === 0 && data.msg) {
|
|
113
|
+
texts.push(String(data.msg));
|
|
114
|
+
}
|
|
115
|
+
if (texts.length === 0 && data.prompt) {
|
|
116
|
+
texts.push(String(data.prompt));
|
|
117
|
+
}
|
|
118
|
+
if (data.negative_prompt) {
|
|
119
|
+
negativePrompt = String(data.negative_prompt);
|
|
120
|
+
}
|
|
121
|
+
if (imageUrls.length === 0)
|
|
122
|
+
throw new Error("Qwen25T2iPreview 需要提供至少一个图片 URL");
|
|
123
|
+
if (texts.length === 0)
|
|
124
|
+
throw new Error("Qwen25T2iPreview 需要提供至少一个文本提示词");
|
|
125
|
+
const prompt = texts.join(" ");
|
|
126
|
+
const parameters = Object.assign({ size: "1280*1280", n: 1, prompt_extend: false, watermark: false }, data.parameters);
|
|
127
|
+
if (negativePrompt) {
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
parameters,
|
|
131
|
+
model: this.modelName,
|
|
132
|
+
input: {
|
|
133
|
+
prompt,
|
|
134
|
+
negative_prompt: negativePrompt || undefined,
|
|
135
|
+
images: imageUrls,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
modelRequest(data_1) {
|
|
140
|
+
return __awaiter(this, arguments, void 0, function* (data, options = { timeout: 30 * 1000 }) {
|
|
141
|
+
const fetchHeaders = yield this.createAuthHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
142
|
+
fetchHeaders["X-DashScope-Async"] = "enable";
|
|
143
|
+
const joinedUrl = `${String(this.baseUrl).replace(/\/+$/, "")}/${String(this.subUrl).replace(/^\/+/, "")}`;
|
|
144
|
+
const { data: responseData, header } = (yield this.req.fetch({
|
|
145
|
+
url: joinedUrl,
|
|
146
|
+
headers: Object.assign({}, fetchHeaders),
|
|
147
|
+
body: JSON.stringify(data),
|
|
148
|
+
method: "post",
|
|
149
|
+
stream: false,
|
|
150
|
+
}));
|
|
151
|
+
return (0, utils_1.handleResponseData)(responseData, header);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
doGenerate(data, options) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
data.model = this.modelName;
|
|
157
|
+
const payload = this.coverModelRequestToQwenInput(data);
|
|
158
|
+
const res = (yield this.modelRequest(payload, options));
|
|
159
|
+
return this.normalizeStandardImageCompletion(res, this.modelName);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
doStream(data, options) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
const nonStream = yield this.doGenerate(Object.assign({}, data), options);
|
|
166
|
+
const msg = ((_b = (_a = nonStream.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || {};
|
|
167
|
+
const singleChunk = {
|
|
168
|
+
id: nonStream.id,
|
|
169
|
+
object: "chat.completion.chunk",
|
|
170
|
+
created: nonStream.created,
|
|
171
|
+
model: nonStream.model,
|
|
172
|
+
log_id: nonStream.log_id,
|
|
173
|
+
error: nonStream.error || "",
|
|
174
|
+
code: nonStream.code || 0,
|
|
175
|
+
choices: [
|
|
176
|
+
{
|
|
177
|
+
index: 0,
|
|
178
|
+
message: {
|
|
179
|
+
id: nonStream.id,
|
|
180
|
+
role: "assistant",
|
|
181
|
+
type: msg.type || "image",
|
|
182
|
+
content: msg.content || "",
|
|
183
|
+
reasoning_content: "",
|
|
184
|
+
},
|
|
185
|
+
finish_reason: "stop",
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
usage: nonStream.usage,
|
|
189
|
+
};
|
|
190
|
+
const stream = new stream_1.ReadableStream({
|
|
191
|
+
start(controller) {
|
|
192
|
+
controller.enqueue(singleChunk);
|
|
193
|
+
controller.close();
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
return (0, stream_1.createAsyncIterable)(stream);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.Qwen25T2iPreviewModel = Qwen25T2iPreviewModel;
|
|
201
|
+
Qwen25T2iPreviewModel.BASE_URL = "https://dashscope.aliyuncs.com";
|
|
202
|
+
Qwen25T2iPreviewModel.SUB_GENERATION_URL = "api/v1/services/aigc/image2image/image-synthesis";
|
|
203
|
+
function mapUsageToStandard(usage) {
|
|
204
|
+
return {
|
|
205
|
+
prompt_tokens: 0,
|
|
206
|
+
completion_tokens: 0,
|
|
207
|
+
knowledge_tokens: 0,
|
|
208
|
+
reasoning_tokens: 0,
|
|
209
|
+
total_tokens: 0,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
import type { BaseDoStreamOutputChunk, DoGenerateOutput, ModelRequestOptions, ReqOptions } from "../../../model-type";
|
|
3
|
+
import type { TokenManager } from "../../../tokenManager";
|
|
4
|
+
import type { QwenDocTurboApi } from "../types";
|
|
5
|
+
import type { QwenDocTurboAPIInput, QwenDocTurboResponse } from "../types";
|
|
6
|
+
export declare class DashScopeApi implements QwenDocTurboApi {
|
|
7
|
+
private req;
|
|
8
|
+
private baseUrl;
|
|
9
|
+
private subUrl;
|
|
10
|
+
private modelName;
|
|
11
|
+
private tokenManager?;
|
|
12
|
+
constructor(ctx: {
|
|
13
|
+
req: IAbstractRequest;
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
subUrl: string;
|
|
16
|
+
modelName: string;
|
|
17
|
+
tokenManager?: TokenManager;
|
|
18
|
+
});
|
|
19
|
+
private createAuthHeaders;
|
|
20
|
+
private clamp;
|
|
21
|
+
buildPayload(data: ModelRequestOptions, stream: boolean): QwenDocTurboAPIInput;
|
|
22
|
+
request(payload: QwenDocTurboAPIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | unknown>;
|
|
23
|
+
normalizeResponse(response: QwenDocTurboResponse): DoGenerateOutput;
|
|
24
|
+
normalizeStream(_stream: ReadableStream<Uint8Array>): ReadableStream<BaseDoStreamOutputChunk>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DashScopeApi = void 0;
|
|
13
|
+
const model_type_1 = require("../../../model-type");
|
|
14
|
+
const stream_1 = require("../../../stream");
|
|
15
|
+
const utils_1 = require("../../../utils");
|
|
16
|
+
class DashScopeApi {
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.req = ctx.req;
|
|
19
|
+
this.baseUrl = ctx.baseUrl;
|
|
20
|
+
this.subUrl = ctx.subUrl;
|
|
21
|
+
this.modelName = ctx.modelName;
|
|
22
|
+
this.tokenManager = ctx.tokenManager;
|
|
23
|
+
}
|
|
24
|
+
createAuthHeaders() {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function* (additionalHeaders = {}) {
|
|
26
|
+
if (!this.tokenManager)
|
|
27
|
+
throw new Error("TokenManager is not set");
|
|
28
|
+
const token = yield this.tokenManager.getValidToken();
|
|
29
|
+
return Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${token}` }, additionalHeaders);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
clamp(value, min, max, def) {
|
|
33
|
+
return value !== undefined ? Math.max(min, Math.min(max, value)) : def;
|
|
34
|
+
}
|
|
35
|
+
buildPayload(data, stream) {
|
|
36
|
+
const messages = (data.messages || []).map((msg) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const role = msg.role;
|
|
39
|
+
if (role === "system") {
|
|
40
|
+
return {
|
|
41
|
+
role,
|
|
42
|
+
content: Array.isArray(msg.content)
|
|
43
|
+
? ((_a = msg.content.find((c) => c.type === "text")) === null || _a === void 0 ? void 0 : _a.text) || ""
|
|
44
|
+
: msg.content,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
role,
|
|
49
|
+
content: Array.isArray(msg.content) ? (0, model_type_1.filterContentByTypes)(msg.content, ["text", "doc_url"]) : msg.content,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const parameters = Object.assign({ stream, max_tokens: this.clamp(data.max_tokens, 1, 8000, 2000), temperature: this.clamp(data.temperature, 0, 2, 1.0), top_p: this.clamp(data.top_p, 0, 1, 1.0), frequency_penalty: this.clamp(data.frequency_penalty, -2, 2, 0.0), presence_penalty: this.clamp(data.presence_penalty, -2, 2, 0.0), n: this.clamp(data.n, 1, 10, 1), incremental_output: false }, ((data === null || data === void 0 ? void 0 : data.parameters) || {}));
|
|
53
|
+
return {
|
|
54
|
+
model: this.modelName,
|
|
55
|
+
input: { messages },
|
|
56
|
+
parameters,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
request(payload, options) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const headers = yield this.createAuthHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
63
|
+
const isStreaming = (_b = (_a = payload.parameters) === null || _a === void 0 ? void 0 : _a.stream) !== null && _b !== void 0 ? _b : false;
|
|
64
|
+
if (isStreaming)
|
|
65
|
+
headers["X-DashScope-SSE"] = "enable";
|
|
66
|
+
const response = (yield this.req.fetch({
|
|
67
|
+
method: "post",
|
|
68
|
+
headers: Object.assign({}, headers),
|
|
69
|
+
body: JSON.stringify(payload),
|
|
70
|
+
url: `${this.baseUrl}/${this.subUrl}`,
|
|
71
|
+
stream: isStreaming,
|
|
72
|
+
}));
|
|
73
|
+
const { data, header } = response;
|
|
74
|
+
return (0, utils_1.handleResponseData)(data, header);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
normalizeResponse(response) {
|
|
78
|
+
var _a, _b, _c, _d, _e;
|
|
79
|
+
const output = response.output || {};
|
|
80
|
+
const choice = (_a = output.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
81
|
+
const requestId = response.request_id || "";
|
|
82
|
+
const created = Math.floor(Date.now() / 1000);
|
|
83
|
+
const content = ((_b = choice === null || choice === void 0 ? void 0 : choice.message) === null || _b === void 0 ? void 0 : _b.content) || output.text || "";
|
|
84
|
+
return {
|
|
85
|
+
id: requestId,
|
|
86
|
+
object: "chat.completion",
|
|
87
|
+
created,
|
|
88
|
+
model: this.modelName,
|
|
89
|
+
log_id: requestId,
|
|
90
|
+
error: "",
|
|
91
|
+
code: 0,
|
|
92
|
+
choices: [
|
|
93
|
+
{
|
|
94
|
+
index: 0,
|
|
95
|
+
message: { id: requestId, role: "assistant", type: "answer", content, reasoning_content: "" },
|
|
96
|
+
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
usage: {
|
|
100
|
+
prompt_tokens: ((_c = response.usage) === null || _c === void 0 ? void 0 : _c.input_tokens) || 0,
|
|
101
|
+
completion_tokens: ((_d = response.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) || 0,
|
|
102
|
+
knowledge_tokens: 0,
|
|
103
|
+
reasoning_tokens: 0,
|
|
104
|
+
total_tokens: ((_e = response.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
normalizeStream(_stream) {
|
|
109
|
+
const modelName = this.modelName;
|
|
110
|
+
const stream = (0, stream_1.toPolyfillReadable)(_stream);
|
|
111
|
+
const raw = (0, stream_1.intoStandardStream)(stream);
|
|
112
|
+
let previousContent = "";
|
|
113
|
+
return raw.pipeThrough(new stream_1.TransformStream({
|
|
114
|
+
transform(chunk, controller) {
|
|
115
|
+
var _a, _b, _c, _d, _e;
|
|
116
|
+
const requestId = chunk.request_id || "";
|
|
117
|
+
const created = Math.floor(Date.now() / 1000);
|
|
118
|
+
if ("code" in chunk && chunk.code !== undefined && !("output" in chunk)) {
|
|
119
|
+
const errorData = chunk;
|
|
120
|
+
controller.enqueue({
|
|
121
|
+
id: errorData.request_id || requestId,
|
|
122
|
+
object: "chat.completion.chunk",
|
|
123
|
+
created,
|
|
124
|
+
model: modelName,
|
|
125
|
+
log_id: errorData.request_id || requestId,
|
|
126
|
+
error: errorData.message || String(errorData.code),
|
|
127
|
+
code: typeof errorData.code === "string" ? -1 : errorData.code || -1,
|
|
128
|
+
choices: [],
|
|
129
|
+
usage: {
|
|
130
|
+
prompt_tokens: 0,
|
|
131
|
+
completion_tokens: 0,
|
|
132
|
+
knowledge_tokens: 0,
|
|
133
|
+
reasoning_tokens: 0,
|
|
134
|
+
total_tokens: 0,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const output = chunk.output || {};
|
|
140
|
+
const choice = (_a = output.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
141
|
+
const fullContent = ((_b = choice === null || choice === void 0 ? void 0 : choice.message) === null || _b === void 0 ? void 0 : _b.content) || output.text || "";
|
|
142
|
+
const deltaContent = fullContent.slice(previousContent.length);
|
|
143
|
+
previousContent = fullContent;
|
|
144
|
+
if (!deltaContent && (choice === null || choice === void 0 ? void 0 : choice.finish_reason) !== "stop")
|
|
145
|
+
return;
|
|
146
|
+
controller.enqueue({
|
|
147
|
+
id: requestId,
|
|
148
|
+
object: "chat.completion.chunk",
|
|
149
|
+
created,
|
|
150
|
+
model: modelName,
|
|
151
|
+
log_id: requestId,
|
|
152
|
+
error: "",
|
|
153
|
+
code: 0,
|
|
154
|
+
choices: [
|
|
155
|
+
{
|
|
156
|
+
index: 0,
|
|
157
|
+
message: {
|
|
158
|
+
id: requestId,
|
|
159
|
+
role: "assistant",
|
|
160
|
+
type: "answer",
|
|
161
|
+
content: deltaContent,
|
|
162
|
+
reasoning_content: "",
|
|
163
|
+
},
|
|
164
|
+
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || null,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
usage: {
|
|
168
|
+
prompt_tokens: ((_c = chunk.usage) === null || _c === void 0 ? void 0 : _c.input_tokens) || 0,
|
|
169
|
+
completion_tokens: ((_d = chunk.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) || 0,
|
|
170
|
+
knowledge_tokens: 0,
|
|
171
|
+
reasoning_tokens: 0,
|
|
172
|
+
total_tokens: ((_e = chunk.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.DashScopeApi = DashScopeApi;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
import type { BaseDoStreamOutputChunk, DoGenerateOutput, ModelRequestOptions, ReqOptions } from "../../../model-type";
|
|
3
|
+
import type { TokenManager } from "../../../tokenManager";
|
|
4
|
+
import type { QwenDocTurboApi } from "../types";
|
|
5
|
+
import type { OpenAICompatibleAPIInput, OpenAICompatibleResponse } from "../types";
|
|
6
|
+
export declare class OpenAICompatApi implements QwenDocTurboApi {
|
|
7
|
+
private req;
|
|
8
|
+
private baseUrl;
|
|
9
|
+
private subUrl;
|
|
10
|
+
private modelName;
|
|
11
|
+
private tokenManager?;
|
|
12
|
+
constructor(ctx: {
|
|
13
|
+
req: IAbstractRequest;
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
subUrl: string;
|
|
16
|
+
modelName: string;
|
|
17
|
+
tokenManager?: TokenManager;
|
|
18
|
+
});
|
|
19
|
+
private createAuthHeaders;
|
|
20
|
+
buildPayload(data: ModelRequestOptions, stream: boolean): OpenAICompatibleAPIInput;
|
|
21
|
+
request(payload: OpenAICompatibleAPIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | unknown>;
|
|
22
|
+
normalizeResponse(response: OpenAICompatibleResponse): DoGenerateOutput;
|
|
23
|
+
normalizeStream(_stream: ReadableStream<Uint8Array>): ReadableStream<BaseDoStreamOutputChunk>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OpenAICompatApi = void 0;
|
|
13
|
+
const stream_1 = require("../../../stream");
|
|
14
|
+
const utils_1 = require("../../../utils");
|
|
15
|
+
class OpenAICompatApi {
|
|
16
|
+
constructor(ctx) {
|
|
17
|
+
this.req = ctx.req;
|
|
18
|
+
this.baseUrl = ctx.baseUrl;
|
|
19
|
+
this.subUrl = ctx.subUrl;
|
|
20
|
+
this.modelName = ctx.modelName;
|
|
21
|
+
this.tokenManager = ctx.tokenManager;
|
|
22
|
+
}
|
|
23
|
+
createAuthHeaders() {
|
|
24
|
+
return __awaiter(this, arguments, void 0, function* (additionalHeaders = {}) {
|
|
25
|
+
if (!this.tokenManager)
|
|
26
|
+
throw new Error("TokenManager is not set");
|
|
27
|
+
const token = yield this.tokenManager.getValidToken();
|
|
28
|
+
return Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${token}` }, additionalHeaders);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
buildPayload(data, stream) {
|
|
32
|
+
const messages = (data.messages || []).map((msg) => {
|
|
33
|
+
const role = msg.role;
|
|
34
|
+
let contentStr = "";
|
|
35
|
+
if (typeof msg.content === "string")
|
|
36
|
+
contentStr = msg.content;
|
|
37
|
+
else if (Array.isArray(msg.content)) {
|
|
38
|
+
contentStr = msg.content
|
|
39
|
+
.map((c) => ((c === null || c === void 0 ? void 0 : c.type) === "text" ? c.text : ""))
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join("\n");
|
|
42
|
+
}
|
|
43
|
+
return { role, content: contentStr };
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
model: this.modelName,
|
|
47
|
+
messages,
|
|
48
|
+
stream,
|
|
49
|
+
stream_options: stream ? { include_usage: true } : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
request(payload, options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
var _a;
|
|
55
|
+
const headers = yield this.createAuthHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
56
|
+
const response = (yield this.req.fetch({
|
|
57
|
+
method: "post",
|
|
58
|
+
headers: Object.assign({}, headers),
|
|
59
|
+
body: JSON.stringify(payload),
|
|
60
|
+
url: `${this.baseUrl}/${this.subUrl}`,
|
|
61
|
+
stream: (_a = payload.stream) !== null && _a !== void 0 ? _a : false,
|
|
62
|
+
}));
|
|
63
|
+
const { data, header } = response;
|
|
64
|
+
return (0, utils_1.handleResponseData)(data, header);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
normalizeResponse(response) {
|
|
68
|
+
var _a, _b, _c, _d, _e;
|
|
69
|
+
const choice = (_a = response.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
70
|
+
const requestId = response.id || "";
|
|
71
|
+
const created = response.created || Math.floor(Date.now() / 1000);
|
|
72
|
+
const content = ((_b = choice === null || choice === void 0 ? void 0 : choice.message) === null || _b === void 0 ? void 0 : _b.content) || "";
|
|
73
|
+
return {
|
|
74
|
+
id: requestId,
|
|
75
|
+
object: "chat.completion",
|
|
76
|
+
created,
|
|
77
|
+
model: this.modelName,
|
|
78
|
+
log_id: requestId,
|
|
79
|
+
error: "",
|
|
80
|
+
code: 0,
|
|
81
|
+
choices: [
|
|
82
|
+
{
|
|
83
|
+
index: 0,
|
|
84
|
+
message: { id: requestId, role: "assistant", type: "answer", content, reasoning_content: "" },
|
|
85
|
+
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
usage: {
|
|
89
|
+
prompt_tokens: ((_c = response.usage) === null || _c === void 0 ? void 0 : _c.prompt_tokens) || 0,
|
|
90
|
+
completion_tokens: ((_d = response.usage) === null || _d === void 0 ? void 0 : _d.completion_tokens) || 0,
|
|
91
|
+
knowledge_tokens: 0,
|
|
92
|
+
reasoning_tokens: 0,
|
|
93
|
+
total_tokens: ((_e = response.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
normalizeStream(_stream) {
|
|
98
|
+
const modelName = this.modelName;
|
|
99
|
+
const stream = (0, stream_1.toPolyfillReadable)(_stream);
|
|
100
|
+
const raw = (0, stream_1.intoStandardStream)(stream);
|
|
101
|
+
return raw.pipeThrough(new stream_1.TransformStream({
|
|
102
|
+
transform(chunk, controller) {
|
|
103
|
+
var _a, _b, _c, _d, _e;
|
|
104
|
+
const requestId = chunk.id || "";
|
|
105
|
+
const created = chunk.created || Math.floor(Date.now() / 1000);
|
|
106
|
+
const choice = (_a = chunk.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
107
|
+
const deltaContent = ((_b = choice === null || choice === void 0 ? void 0 : choice.delta) === null || _b === void 0 ? void 0 : _b.content) || "";
|
|
108
|
+
if (!deltaContent && !(choice === null || choice === void 0 ? void 0 : choice.finish_reason))
|
|
109
|
+
return;
|
|
110
|
+
controller.enqueue({
|
|
111
|
+
id: requestId,
|
|
112
|
+
object: "chat.completion.chunk",
|
|
113
|
+
created,
|
|
114
|
+
model: modelName,
|
|
115
|
+
log_id: requestId,
|
|
116
|
+
error: "",
|
|
117
|
+
code: 0,
|
|
118
|
+
choices: [
|
|
119
|
+
{
|
|
120
|
+
index: (choice === null || choice === void 0 ? void 0 : choice.index) || 0,
|
|
121
|
+
message: {
|
|
122
|
+
id: requestId,
|
|
123
|
+
role: "assistant",
|
|
124
|
+
type: "answer",
|
|
125
|
+
content: deltaContent,
|
|
126
|
+
reasoning_content: "",
|
|
127
|
+
},
|
|
128
|
+
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || null,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
usage: {
|
|
132
|
+
prompt_tokens: ((_c = chunk.usage) === null || _c === void 0 ? void 0 : _c.prompt_tokens) || 0,
|
|
133
|
+
completion_tokens: ((_d = chunk.usage) === null || _d === void 0 ? void 0 : _d.completion_tokens) || 0,
|
|
134
|
+
knowledge_tokens: 0,
|
|
135
|
+
reasoning_tokens: 0,
|
|
136
|
+
total_tokens: ((_e = chunk.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.OpenAICompatApi = OpenAICompatApi;
|
|
@@ -1,84 +1,16 @@
|
|
|
1
1
|
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
-
import type { DoGenerateOutput, DoStreamOutput,
|
|
2
|
+
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../../model-type";
|
|
3
3
|
import type { TokenManager } from "../../tokenManager";
|
|
4
4
|
import { SimpleChatModel } from "../Chat";
|
|
5
5
|
import type { MultiModalModelName } from "../index";
|
|
6
|
-
export interface QwenDocTurboMessage {
|
|
7
|
-
role: "system" | "user" | "assistant";
|
|
8
|
-
content: string | Array<TextContent | DocUrlContent>;
|
|
9
|
-
}
|
|
10
|
-
export interface QwenDocTurboParameters {
|
|
11
|
-
temperature?: number;
|
|
12
|
-
top_p?: number;
|
|
13
|
-
max_tokens?: number;
|
|
14
|
-
n?: number;
|
|
15
|
-
stream?: boolean;
|
|
16
|
-
stop?: string | string[];
|
|
17
|
-
frequency_penalty?: number;
|
|
18
|
-
presence_penalty?: number;
|
|
19
|
-
user?: string;
|
|
20
|
-
stream_options?: {
|
|
21
|
-
include_usage?: boolean;
|
|
22
|
-
};
|
|
23
|
-
response_format?: {
|
|
24
|
-
type: "text" | "json_object";
|
|
25
|
-
};
|
|
26
|
-
tools?: Array<object>;
|
|
27
|
-
tool_choice?: string | object;
|
|
28
|
-
parallel_tool_calls?: boolean;
|
|
29
|
-
}
|
|
30
|
-
export interface QwenDocTurboAPIInput {
|
|
31
|
-
model: string;
|
|
32
|
-
input: {
|
|
33
|
-
messages: QwenDocTurboMessage[];
|
|
34
|
-
};
|
|
35
|
-
parameters?: QwenDocTurboParameters;
|
|
36
|
-
}
|
|
37
|
-
export interface QwenDocTurboResponse {
|
|
38
|
-
request_id?: string;
|
|
39
|
-
output?: {
|
|
40
|
-
text?: string;
|
|
41
|
-
choices?: Array<{
|
|
42
|
-
finish_reason: string;
|
|
43
|
-
message: {
|
|
44
|
-
role: string;
|
|
45
|
-
content: string;
|
|
46
|
-
};
|
|
47
|
-
}>;
|
|
48
|
-
};
|
|
49
|
-
usage?: {
|
|
50
|
-
input_tokens?: number;
|
|
51
|
-
output_tokens?: number;
|
|
52
|
-
total_tokens?: number;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export interface QwenDocTurboStreamChunk {
|
|
56
|
-
request_id?: string;
|
|
57
|
-
output?: {
|
|
58
|
-
text?: string;
|
|
59
|
-
choices?: Array<{
|
|
60
|
-
finish_reason: string;
|
|
61
|
-
message: {
|
|
62
|
-
role?: string;
|
|
63
|
-
content?: string;
|
|
64
|
-
};
|
|
65
|
-
}>;
|
|
66
|
-
};
|
|
67
|
-
usage?: {
|
|
68
|
-
input_tokens?: number;
|
|
69
|
-
output_tokens?: number;
|
|
70
|
-
total_tokens?: number;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
6
|
export declare class QwenDocTurbo extends SimpleChatModel {
|
|
74
7
|
static BASE_URL: string;
|
|
75
8
|
static SUB_URL: string;
|
|
9
|
+
static OPENAI_COMPATIBLE_SUB_URL: string;
|
|
76
10
|
modelName: MultiModalModelName;
|
|
77
11
|
constructor(req: IAbstractRequest, baseUrl: string, modelName: MultiModalModelName, tokenManager: TokenManager);
|
|
78
|
-
|
|
79
|
-
|
|
12
|
+
private hasFileIdProtocol;
|
|
13
|
+
private createApi;
|
|
80
14
|
doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
81
15
|
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
82
|
-
private normalizeStreamChunks;
|
|
83
|
-
private convertToQwenDocTurboRequestOptions;
|
|
84
16
|
}
|
|
@@ -10,162 +10,77 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.QwenDocTurbo = void 0;
|
|
13
|
-
const model_type_1 = require("../../model-type");
|
|
14
13
|
const stream_1 = require("../../stream");
|
|
15
|
-
const utils_1 = require("../../utils");
|
|
16
14
|
const Chat_1 = require("../Chat");
|
|
15
|
+
const DashScope_1 = require("./adapters/DashScope");
|
|
16
|
+
const OpenAICompat_1 = require("./adapters/OpenAICompat");
|
|
17
17
|
class QwenDocTurbo extends Chat_1.SimpleChatModel {
|
|
18
18
|
constructor(req, baseUrl, modelName, tokenManager) {
|
|
19
19
|
super(req, baseUrl, QwenDocTurbo.SUB_URL, tokenManager);
|
|
20
20
|
this.modelName = modelName;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
hasFileIdProtocol(messages) {
|
|
23
|
+
if (!messages)
|
|
24
|
+
return false;
|
|
25
|
+
return messages.some((msg) => {
|
|
26
|
+
if (msg.role !== "system")
|
|
27
|
+
return false;
|
|
28
|
+
const content = msg.content;
|
|
29
|
+
if (typeof content === "string") {
|
|
30
|
+
return content.includes("fileid://");
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(content)) {
|
|
33
|
+
return content.some((c) => {
|
|
34
|
+
if (c.type === "text" && typeof c.text === "string") {
|
|
35
|
+
return c.text.includes("fileid://");
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
method: "post",
|
|
32
|
-
headers: Object.assign({}, fetchHeaders),
|
|
33
|
-
body: JSON.stringify(data),
|
|
34
|
-
url: `${this.baseUrl}/${this.subUrl}`,
|
|
35
|
-
stream: isStreaming,
|
|
36
|
-
}));
|
|
37
|
-
return (0, utils_1.handleResponseData)(responseData, header);
|
|
40
|
+
return false;
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
index: 0,
|
|
58
|
-
message: {
|
|
59
|
-
id: requestId,
|
|
60
|
-
role: "assistant",
|
|
61
|
-
type: "answer",
|
|
62
|
-
content: content,
|
|
63
|
-
reasoning_content: "",
|
|
64
|
-
},
|
|
65
|
-
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
usage: {
|
|
69
|
-
prompt_tokens: ((_c = response.usage) === null || _c === void 0 ? void 0 : _c.input_tokens) || 0,
|
|
70
|
-
completion_tokens: ((_d = response.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) || 0,
|
|
71
|
-
knowledge_tokens: 0,
|
|
72
|
-
reasoning_tokens: 0,
|
|
73
|
-
total_tokens: ((_e = response.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
43
|
+
createApi(hasFileId) {
|
|
44
|
+
if (hasFileId) {
|
|
45
|
+
return new OpenAICompat_1.OpenAICompatApi({
|
|
46
|
+
req: this.req,
|
|
47
|
+
baseUrl: this.baseUrl,
|
|
48
|
+
subUrl: QwenDocTurbo.OPENAI_COMPATIBLE_SUB_URL,
|
|
49
|
+
modelName: this.modelName,
|
|
50
|
+
tokenManager: this.tokenManager,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return new DashScope_1.DashScopeApi({
|
|
54
|
+
req: this.req,
|
|
55
|
+
baseUrl: this.baseUrl,
|
|
56
|
+
subUrl: QwenDocTurbo.SUB_URL,
|
|
57
|
+
modelName: this.modelName,
|
|
58
|
+
tokenManager: this.tokenManager,
|
|
59
|
+
});
|
|
76
60
|
}
|
|
77
61
|
doGenerate(data, options) {
|
|
78
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
63
|
+
const hasFileId = this.hasFileIdProtocol(data.messages);
|
|
64
|
+
const api = this.createApi(hasFileId);
|
|
65
|
+
const payload = api.buildPayload(data, false);
|
|
66
|
+
console.log("==== api ====", payload, options);
|
|
67
|
+
const res = yield api.request(payload, options);
|
|
68
|
+
console.log("==== res ====", JSON.stringify(res, null, 2));
|
|
69
|
+
return api.normalizeResponse(res);
|
|
82
70
|
});
|
|
83
71
|
}
|
|
84
72
|
doStream(data, options) {
|
|
85
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
return (0, stream_1.createAsyncIterable)(
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
normalizeStreamChunks(stream) {
|
|
95
|
-
const modelName = this.modelName;
|
|
96
|
-
let previousContent = "";
|
|
97
|
-
return stream.pipeThrough(new stream_1.TransformStream({
|
|
98
|
-
transform(chunk, controller) {
|
|
99
|
-
var _a, _b, _c, _d, _e;
|
|
100
|
-
const output = chunk.output || {};
|
|
101
|
-
const choice = (_a = output.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
102
|
-
const requestId = chunk.request_id || "";
|
|
103
|
-
const created = Math.floor(Date.now() / 1000);
|
|
104
|
-
const fullContent = ((_b = choice === null || choice === void 0 ? void 0 : choice.message) === null || _b === void 0 ? void 0 : _b.content) || output.text || "";
|
|
105
|
-
const deltaContent = fullContent.slice(previousContent.length);
|
|
106
|
-
previousContent = fullContent;
|
|
107
|
-
if (!deltaContent && (choice === null || choice === void 0 ? void 0 : choice.finish_reason) !== "stop") {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const standardChunk = {
|
|
111
|
-
id: requestId,
|
|
112
|
-
object: "chat.completion.chunk",
|
|
113
|
-
created: created,
|
|
114
|
-
model: modelName,
|
|
115
|
-
log_id: requestId,
|
|
116
|
-
error: "",
|
|
117
|
-
code: 0,
|
|
118
|
-
choices: [
|
|
119
|
-
{
|
|
120
|
-
index: 0,
|
|
121
|
-
message: {
|
|
122
|
-
id: requestId,
|
|
123
|
-
role: "assistant",
|
|
124
|
-
type: "answer",
|
|
125
|
-
content: deltaContent,
|
|
126
|
-
reasoning_content: "",
|
|
127
|
-
},
|
|
128
|
-
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || null,
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
usage: {
|
|
132
|
-
prompt_tokens: ((_c = chunk.usage) === null || _c === void 0 ? void 0 : _c.input_tokens) || 0,
|
|
133
|
-
completion_tokens: ((_d = chunk.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) || 0,
|
|
134
|
-
knowledge_tokens: 0,
|
|
135
|
-
reasoning_tokens: 0,
|
|
136
|
-
total_tokens: ((_e = chunk.usage) === null || _e === void 0 ? void 0 : _e.total_tokens) || 0,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
controller.enqueue(standardChunk);
|
|
140
|
-
},
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
convertToQwenDocTurboRequestOptions(data, stream) {
|
|
144
|
-
const clamp = (value, min, max, defaultValue) => value !== undefined ? Math.max(min, Math.min(max, value)) : defaultValue;
|
|
145
|
-
const messages = (data.messages || []).map((msg) => {
|
|
146
|
-
var _a;
|
|
147
|
-
const role = msg.role;
|
|
148
|
-
if (role === "system") {
|
|
149
|
-
return {
|
|
150
|
-
role,
|
|
151
|
-
content: Array.isArray(msg.content) ? ((_a = msg.content.find((c) => c.type === "text")) === null || _a === void 0 ? void 0 : _a.text) || "" : msg.content,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
role,
|
|
156
|
-
content: Array.isArray(msg.content) ? (0, model_type_1.filterContentByTypes)(msg.content, ["text", "doc_url"]) : msg.content,
|
|
157
|
-
};
|
|
74
|
+
const hasFileId = this.hasFileIdProtocol(data.messages);
|
|
75
|
+
const api = this.createApi(hasFileId);
|
|
76
|
+
const payload = api.buildPayload(data, true);
|
|
77
|
+
const _stream = (yield api.request(payload, options));
|
|
78
|
+
const normalized = api.normalizeStream(_stream);
|
|
79
|
+
return (0, stream_1.createAsyncIterable)(normalized);
|
|
158
80
|
});
|
|
159
|
-
const parameters = Object.assign({ stream, max_tokens: clamp(data.max_tokens, 1, 8000, 2000), temperature: clamp(data.temperature, 0, 2, 1.0), top_p: clamp(data.top_p, 0, 1, 1.0), frequency_penalty: clamp(data.frequency_penalty, -2, 2, 0.0), presence_penalty: clamp(data.presence_penalty, -2, 2, 0.0), n: clamp(data.n, 1, 10, 1), incremental_output: false }, ((data === null || data === void 0 ? void 0 : data.parameters) || {}));
|
|
160
|
-
return {
|
|
161
|
-
model: this.modelName,
|
|
162
|
-
input: {
|
|
163
|
-
messages,
|
|
164
|
-
},
|
|
165
|
-
parameters,
|
|
166
|
-
};
|
|
167
81
|
}
|
|
168
82
|
}
|
|
169
83
|
exports.QwenDocTurbo = QwenDocTurbo;
|
|
170
84
|
QwenDocTurbo.BASE_URL = "https://dashscope.aliyuncs.com";
|
|
171
85
|
QwenDocTurbo.SUB_URL = "api/v1/services/aigc/text-generation/generation";
|
|
86
|
+
QwenDocTurbo.OPENAI_COMPATIBLE_SUB_URL = "compatible-mode/v1/chat/completions";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { DocUrlContent, TextContent } from "../../model-type";
|
|
2
|
+
export interface QwenDocTurboMessage {
|
|
3
|
+
role: "system" | "user" | "assistant";
|
|
4
|
+
content: string | Array<TextContent | DocUrlContent>;
|
|
5
|
+
}
|
|
6
|
+
export interface QwenDocTurboParameters {
|
|
7
|
+
temperature?: number;
|
|
8
|
+
top_p?: number;
|
|
9
|
+
max_tokens?: number;
|
|
10
|
+
n?: number;
|
|
11
|
+
stream?: boolean;
|
|
12
|
+
stop?: string | string[];
|
|
13
|
+
frequency_penalty?: number;
|
|
14
|
+
presence_penalty?: number;
|
|
15
|
+
user?: string;
|
|
16
|
+
stream_options?: {
|
|
17
|
+
include_usage?: boolean;
|
|
18
|
+
};
|
|
19
|
+
response_format?: {
|
|
20
|
+
type: "text" | "json_object";
|
|
21
|
+
};
|
|
22
|
+
tools?: Array<object>;
|
|
23
|
+
tool_choice?: string | object;
|
|
24
|
+
parallel_tool_calls?: boolean;
|
|
25
|
+
incremental_output?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface QwenDocTurboAPIInput {
|
|
28
|
+
model: string;
|
|
29
|
+
input: {
|
|
30
|
+
messages: QwenDocTurboMessage[];
|
|
31
|
+
};
|
|
32
|
+
parameters?: QwenDocTurboParameters;
|
|
33
|
+
}
|
|
34
|
+
export interface QwenDocTurboResponse {
|
|
35
|
+
request_id?: string;
|
|
36
|
+
output?: {
|
|
37
|
+
text?: string;
|
|
38
|
+
choices?: Array<{
|
|
39
|
+
finish_reason: string;
|
|
40
|
+
message: {
|
|
41
|
+
role: string;
|
|
42
|
+
content: string;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
usage?: {
|
|
47
|
+
input_tokens?: number;
|
|
48
|
+
output_tokens?: number;
|
|
49
|
+
total_tokens?: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface QwenDocTurboStreamChunk {
|
|
53
|
+
request_id?: string;
|
|
54
|
+
output?: {
|
|
55
|
+
text?: string;
|
|
56
|
+
choices?: Array<{
|
|
57
|
+
finish_reason: string;
|
|
58
|
+
message: {
|
|
59
|
+
role?: string;
|
|
60
|
+
content?: string;
|
|
61
|
+
};
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
usage?: {
|
|
65
|
+
input_tokens?: number;
|
|
66
|
+
output_tokens?: number;
|
|
67
|
+
total_tokens?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export interface OpenAICompatibleAPIInput {
|
|
71
|
+
model: string;
|
|
72
|
+
messages: Array<{
|
|
73
|
+
role: "system" | "user" | "assistant";
|
|
74
|
+
content: string;
|
|
75
|
+
}>;
|
|
76
|
+
stream?: boolean;
|
|
77
|
+
stream_options?: {
|
|
78
|
+
include_usage?: boolean;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface OpenAICompatibleResponse {
|
|
82
|
+
id?: string;
|
|
83
|
+
object?: string;
|
|
84
|
+
created?: number;
|
|
85
|
+
model?: string;
|
|
86
|
+
choices?: Array<{
|
|
87
|
+
index?: number;
|
|
88
|
+
message?: {
|
|
89
|
+
role?: string;
|
|
90
|
+
content?: string;
|
|
91
|
+
};
|
|
92
|
+
finish_reason?: string | null;
|
|
93
|
+
}>;
|
|
94
|
+
usage?: {
|
|
95
|
+
prompt_tokens?: number;
|
|
96
|
+
completion_tokens?: number;
|
|
97
|
+
total_tokens?: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export interface OpenAICompatibleStreamChunk {
|
|
101
|
+
id?: string;
|
|
102
|
+
object?: string;
|
|
103
|
+
created?: number;
|
|
104
|
+
model?: string;
|
|
105
|
+
choices?: Array<{
|
|
106
|
+
index?: number;
|
|
107
|
+
delta?: {
|
|
108
|
+
role?: string;
|
|
109
|
+
content?: string;
|
|
110
|
+
};
|
|
111
|
+
finish_reason?: string | null;
|
|
112
|
+
}>;
|
|
113
|
+
usage?: {
|
|
114
|
+
prompt_tokens?: number;
|
|
115
|
+
completion_tokens?: number;
|
|
116
|
+
total_tokens?: number;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export interface QwenDocTurboApi {
|
|
120
|
+
buildPayload(data: any, stream: boolean): unknown;
|
|
121
|
+
request(payload: unknown, options?: any): Promise<ReadableStream<Uint8Array> | unknown>;
|
|
122
|
+
normalizeResponse(res: unknown): any;
|
|
123
|
+
normalizeStream(stream: ReadableStream<Uint8Array>): ReadableStream<any>;
|
|
124
|
+
}
|
package/lib/models/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DefaultSimpleModel } from "./Default";
|
|
2
|
+
import { Qwen25T2iPreviewModel } from "./Qwen25T2iPreview";
|
|
2
3
|
import { QwenDocTurbo } from "./QwenDocTurbo";
|
|
3
4
|
import { QwenImageModel } from "./QwenImage";
|
|
4
5
|
import { QwenImageEditModel } from "./QwenImageEdit";
|
|
@@ -25,6 +26,7 @@ export declare enum MultiModalModelName {
|
|
|
25
26
|
Wanx21T2iTurbo = "wanx2.1-t2i-turbo",
|
|
26
27
|
QwenImage = "qwen-image",
|
|
27
28
|
QwenImageEdit = "qwen-image-edit",
|
|
29
|
+
Qwen25T2iPreview = "wan2.5-i2i-preview",
|
|
28
30
|
WanxSketchToImageLite = "wanx-sketch-to-image-lite",
|
|
29
31
|
QwenStyleRepaintV1 = "wanx-style-repaint-v1"
|
|
30
32
|
}
|
|
@@ -44,10 +46,11 @@ export declare const modelName: {
|
|
|
44
46
|
"wanx2.1-t2i-turbo": string;
|
|
45
47
|
"qwen-image": string;
|
|
46
48
|
"qwen-image-edit": string;
|
|
49
|
+
"wan2.5-i2i-preview": string;
|
|
47
50
|
"wanx-sketch-to-image-lite": string;
|
|
48
51
|
"wanx-style-repaint-v1": string;
|
|
49
52
|
};
|
|
50
53
|
export declare const isValidModel: (model: ModelName | MultiModalModelName) => model is ModelName | MultiModalModelName;
|
|
51
54
|
export declare const isMultiModalModel: (model: ModelName | MultiModalModelName) => model is MultiModalModelName;
|
|
52
55
|
declare const toolMap: Map<string, Function>;
|
|
53
|
-
export { DefaultSimpleModel, QwenDocTurbo, ReActModel, toolMap, WanxSketchToImageLiteModel, QwenImageModel, QwenImageEditModel, QwenVlMax, QwenStyleRepaintV1Model, };
|
|
56
|
+
export { DefaultSimpleModel, QwenDocTurbo, ReActModel, toolMap, WanxSketchToImageLiteModel, QwenImageModel, QwenImageEditModel, Qwen25T2iPreviewModel, QwenVlMax, QwenStyleRepaintV1Model, };
|
package/lib/models/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QwenStyleRepaintV1Model = exports.QwenVlMax = exports.QwenImageEditModel = exports.QwenImageModel = exports.WanxSketchToImageLiteModel = exports.toolMap = exports.ReActModel = exports.QwenDocTurbo = exports.DefaultSimpleModel = exports.isMultiModalModel = exports.isValidModel = exports.modelName = exports.MultiModalModelName = exports.ModelName = void 0;
|
|
3
|
+
exports.QwenStyleRepaintV1Model = exports.QwenVlMax = exports.Qwen25T2iPreviewModel = exports.QwenImageEditModel = exports.QwenImageModel = exports.WanxSketchToImageLiteModel = exports.toolMap = exports.ReActModel = exports.QwenDocTurbo = exports.DefaultSimpleModel = exports.isMultiModalModel = exports.isValidModel = exports.modelName = exports.MultiModalModelName = exports.ModelName = void 0;
|
|
4
4
|
const Default_1 = require("./Default");
|
|
5
5
|
Object.defineProperty(exports, "DefaultSimpleModel", { enumerable: true, get: function () { return Default_1.DefaultSimpleModel; } });
|
|
6
|
+
const Qwen25T2iPreview_1 = require("./Qwen25T2iPreview");
|
|
7
|
+
Object.defineProperty(exports, "Qwen25T2iPreviewModel", { enumerable: true, get: function () { return Qwen25T2iPreview_1.Qwen25T2iPreviewModel; } });
|
|
6
8
|
const QwenDocTurbo_1 = require("./QwenDocTurbo");
|
|
7
9
|
Object.defineProperty(exports, "QwenDocTurbo", { enumerable: true, get: function () { return QwenDocTurbo_1.QwenDocTurbo; } });
|
|
8
10
|
const QwenImage_1 = require("./QwenImage");
|
|
@@ -38,6 +40,7 @@ var MultiModalModelName;
|
|
|
38
40
|
MultiModalModelName["Wanx21T2iTurbo"] = "wanx2.1-t2i-turbo";
|
|
39
41
|
MultiModalModelName["QwenImage"] = "qwen-image";
|
|
40
42
|
MultiModalModelName["QwenImageEdit"] = "qwen-image-edit";
|
|
43
|
+
MultiModalModelName["Qwen25T2iPreview"] = "wan2.5-i2i-preview";
|
|
41
44
|
MultiModalModelName["WanxSketchToImageLite"] = "wanx-sketch-to-image-lite";
|
|
42
45
|
MultiModalModelName["QwenStyleRepaintV1"] = "wanx-style-repaint-v1";
|
|
43
46
|
})(MultiModalModelName || (exports.MultiModalModelName = MultiModalModelName = {}));
|
|
@@ -57,6 +60,7 @@ exports.modelName = {
|
|
|
57
60
|
[MultiModalModelName.Wanx21T2iTurbo]: "wanx2.1-t2i-turbo",
|
|
58
61
|
[MultiModalModelName.QwenImage]: "qwen-image",
|
|
59
62
|
[MultiModalModelName.QwenImageEdit]: "qwen-image-edit",
|
|
63
|
+
[MultiModalModelName.Qwen25T2iPreview]: "wan2.5-i2i-preview",
|
|
60
64
|
[MultiModalModelName.WanxSketchToImageLite]: "wanx-sketch-to-image-lite",
|
|
61
65
|
[MultiModalModelName.QwenStyleRepaintV1]: "wanx-style-repaint-v1",
|
|
62
66
|
};
|
package/lib/utils.js
CHANGED
|
@@ -13,12 +13,21 @@ exports.handleResponseData = handleResponseData;
|
|
|
13
13
|
function handleResponseData(responseData, header) {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
|
|
16
|
+
const isPromise = typeof responseData === "object" && responseData && "then" in responseData;
|
|
17
|
+
const isReadable = typeof (responseData === null || responseData === void 0 ? void 0 : responseData.getReader) === "function";
|
|
18
|
+
if (isPromise) {
|
|
17
19
|
const json = (yield responseData);
|
|
18
20
|
if (typeof json === "object" && json && "code" in json && json.code !== 0) {
|
|
19
21
|
throw new Error(`ModelRequest 请求出错,错误码:${json.code},错误信息:${json.message}\n${JSON.stringify(json, null, 2)}`);
|
|
20
22
|
}
|
|
21
|
-
return
|
|
23
|
+
return json;
|
|
24
|
+
}
|
|
25
|
+
if (!isReadable) {
|
|
26
|
+
const json = responseData;
|
|
27
|
+
if (typeof json === "object" && json && "code" in json && json.code !== 0) {
|
|
28
|
+
throw new Error(`ModelRequest 请求出错,错误码:${json.code},错误信息:${json.message}\n${JSON.stringify(json, null, 2)}`);
|
|
29
|
+
}
|
|
30
|
+
return json;
|
|
22
31
|
}
|
|
23
32
|
if ((_b = (_a = header === null || header === void 0 ? void 0 : header.get) === null || _a === void 0 ? void 0 : _a.call(header, "content-type")) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
|
|
24
33
|
const json = yield readableStream2JsonObject(responseData);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Cloud AI SDK",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@mattiasbuelens/web-streams-adapter": "^0.1.0",
|
|
25
|
-
"@vectorx/ai-types": "0.
|
|
25
|
+
"@vectorx/ai-types": "0.5.2",
|
|
26
26
|
"langfuse": "^3.38.4",
|
|
27
27
|
"openai": "^4.103.0",
|
|
28
28
|
"text-encoding-shim": "^1.0.5",
|