@vectorx/ai-sdk 1.0.0 → 1.1.0
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.d.ts +1 -1
- package/lib/ai.js +14 -0
- package/lib/model-type.d.ts +26 -0
- package/lib/models/Chat.d.ts +2 -2
- package/lib/models/Default/index.d.ts +1 -0
- package/lib/models/Default/index.js +27 -1
- package/lib/models/Qwen25T2iPreview/index.d.ts +3 -1
- package/lib/models/Qwen25T2iPreview/index.js +49 -0
- package/lib/models/Qwen3VlPlus/index.d.ts +2 -0
- package/lib/models/Qwen3VlPlus/index.js +66 -2
- package/lib/models/QwenCosyVoiceTTS/index.d.ts +8 -0
- package/lib/models/QwenCosyVoiceTTS/index.js +178 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.d.ts +2 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.js +86 -11
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.d.ts +2 -0
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.js +102 -3
- package/lib/models/QwenImage/index.d.ts +3 -1
- package/lib/models/QwenImage/index.js +52 -1
- package/lib/models/QwenImage20/index.d.ts +91 -0
- package/lib/models/QwenImage20/index.js +244 -0
- package/lib/models/QwenImageEdit/index.d.ts +3 -1
- package/lib/models/QwenImageEdit/index.js +52 -1
- package/lib/models/QwenSketchToImage/index.d.ts +1 -1
- package/lib/models/QwenStyleRepaintV1/index.d.ts +1 -1
- package/lib/models/QwenStyleRepaintV1/index.js +3 -1
- package/lib/models/QwenVlMax/index.d.ts +2 -0
- package/lib/models/QwenVlMax/index.js +67 -2
- package/lib/models/TTSModel.d.ts +11 -0
- package/lib/models/TTSModel.js +75 -0
- package/lib/models/Wan26Image/index.d.ts +3 -1
- package/lib/models/Wan26Image/index.js +52 -1
- package/lib/models/index.d.ts +25 -3
- package/lib/models/index.js +49 -2
- package/lib/models/react.d.ts +6 -2
- package/lib/models/react.js +22 -0
- package/lib/stream.js +10 -7
- package/lib/tokenManager.js +11 -1
- package/package.json +9 -7
|
@@ -40,13 +40,16 @@ class DashScopeApi {
|
|
|
40
40
|
return {
|
|
41
41
|
role,
|
|
42
42
|
content: Array.isArray(msg.content)
|
|
43
|
-
? ((_a = msg.content.find((c) => c.type === "text")) === null || _a === void 0 ? void 0 : _a.text) ||
|
|
43
|
+
? ((_a = msg.content.find((c) => c.type === "text")) === null || _a === void 0 ? void 0 : _a.text) ||
|
|
44
|
+
""
|
|
44
45
|
: msg.content,
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
return {
|
|
48
49
|
role,
|
|
49
|
-
content: Array.isArray(msg.content)
|
|
50
|
+
content: Array.isArray(msg.content)
|
|
51
|
+
? (0, model_type_1.filterContentByTypes)(msg.content, ["text", "doc_url"])
|
|
52
|
+
: msg.content,
|
|
50
53
|
};
|
|
51
54
|
});
|
|
52
55
|
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) || {}));
|
|
@@ -76,6 +79,10 @@ class DashScopeApi {
|
|
|
76
79
|
}
|
|
77
80
|
normalizeResponse(response) {
|
|
78
81
|
var _a, _b, _c, _d, _e;
|
|
82
|
+
const res = response;
|
|
83
|
+
if (this.isErrorResponse(res)) {
|
|
84
|
+
return this.normalizeErrorResponse(res);
|
|
85
|
+
}
|
|
79
86
|
const output = response.output || {};
|
|
80
87
|
const choice = (_a = output.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
81
88
|
const requestId = response.request_id || "";
|
|
@@ -92,7 +99,13 @@ class DashScopeApi {
|
|
|
92
99
|
choices: [
|
|
93
100
|
{
|
|
94
101
|
index: 0,
|
|
95
|
-
message: {
|
|
102
|
+
message: {
|
|
103
|
+
id: requestId,
|
|
104
|
+
role: "assistant",
|
|
105
|
+
type: "answer",
|
|
106
|
+
content,
|
|
107
|
+
reasoning_content: "",
|
|
108
|
+
},
|
|
96
109
|
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
97
110
|
},
|
|
98
111
|
],
|
|
@@ -105,6 +118,51 @@ class DashScopeApi {
|
|
|
105
118
|
},
|
|
106
119
|
};
|
|
107
120
|
}
|
|
121
|
+
isErrorResponse(obj) {
|
|
122
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.error) && typeof obj.error === "object" && obj.error.code)
|
|
123
|
+
return true;
|
|
124
|
+
if (typeof (obj === null || obj === void 0 ? void 0 : obj.code) === "string" && !(obj === null || obj === void 0 ? void 0 : obj.output))
|
|
125
|
+
return true;
|
|
126
|
+
if (typeof (obj === null || obj === void 0 ? void 0 : obj.code) === "number" && obj.code !== 0 && !(obj === null || obj === void 0 ? void 0 : obj.output))
|
|
127
|
+
return true;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
normalizeErrorResponse(res) {
|
|
131
|
+
const err = typeof (res === null || res === void 0 ? void 0 : res.error) === "object" ? res.error : {};
|
|
132
|
+
const errorCode = (err === null || err === void 0 ? void 0 : err.code) || (res === null || res === void 0 ? void 0 : res.code) || "unknown_error";
|
|
133
|
+
const errorMessage = (err === null || err === void 0 ? void 0 : err.message) || (res === null || res === void 0 ? void 0 : res.message) || "Unknown error";
|
|
134
|
+
const id = (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
135
|
+
const created = Math.floor(Date.now() / 1000);
|
|
136
|
+
return {
|
|
137
|
+
id,
|
|
138
|
+
object: "chat.completion",
|
|
139
|
+
created,
|
|
140
|
+
model: this.modelName,
|
|
141
|
+
log_id: id,
|
|
142
|
+
error: `[${errorCode}] ${errorMessage}`,
|
|
143
|
+
code: typeof (res === null || res === void 0 ? void 0 : res.code) === "number" ? res.code : -1,
|
|
144
|
+
choices: [
|
|
145
|
+
{
|
|
146
|
+
index: 0,
|
|
147
|
+
message: {
|
|
148
|
+
id,
|
|
149
|
+
role: "assistant",
|
|
150
|
+
type: "error",
|
|
151
|
+
content: `[${errorCode}] ${errorMessage}`,
|
|
152
|
+
reasoning_content: "",
|
|
153
|
+
},
|
|
154
|
+
finish_reason: "error",
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
usage: {
|
|
158
|
+
prompt_tokens: 0,
|
|
159
|
+
completion_tokens: 0,
|
|
160
|
+
knowledge_tokens: 0,
|
|
161
|
+
reasoning_tokens: 0,
|
|
162
|
+
total_tokens: 0,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
108
166
|
normalizeStream(_stream) {
|
|
109
167
|
const modelName = this.modelName;
|
|
110
168
|
const stream = (0, stream_1.toPolyfillReadable)(_stream);
|
|
@@ -113,19 +171,36 @@ class DashScopeApi {
|
|
|
113
171
|
return raw.pipeThrough(new stream_1.TransformStream({
|
|
114
172
|
transform(chunk, controller) {
|
|
115
173
|
var _a, _b, _c, _d, _e;
|
|
116
|
-
const
|
|
174
|
+
const raw = chunk;
|
|
175
|
+
const requestId = raw.request_id || "";
|
|
117
176
|
const created = Math.floor(Date.now() / 1000);
|
|
118
|
-
|
|
119
|
-
|
|
177
|
+
const hasNestedError = (raw === null || raw === void 0 ? void 0 : raw.error) && typeof raw.error === "object" && raw.error.code;
|
|
178
|
+
const hasCodeError = "code" in raw && raw.code !== undefined && !("output" in chunk);
|
|
179
|
+
if (hasNestedError || hasCodeError) {
|
|
180
|
+
const err = typeof (raw === null || raw === void 0 ? void 0 : raw.error) === "object" ? raw.error : {};
|
|
181
|
+
const errorCode = (err === null || err === void 0 ? void 0 : err.code) || (raw === null || raw === void 0 ? void 0 : raw.code) || "unknown_error";
|
|
182
|
+
const errorMessage = (err === null || err === void 0 ? void 0 : err.message) || (raw === null || raw === void 0 ? void 0 : raw.message) || String(errorCode);
|
|
120
183
|
controller.enqueue({
|
|
121
|
-
id:
|
|
184
|
+
id: raw.request_id || requestId,
|
|
122
185
|
object: "chat.completion.chunk",
|
|
123
186
|
created,
|
|
124
187
|
model: modelName,
|
|
125
|
-
log_id:
|
|
126
|
-
error:
|
|
127
|
-
code: typeof
|
|
128
|
-
choices: [
|
|
188
|
+
log_id: raw.request_id || requestId,
|
|
189
|
+
error: `[${errorCode}] ${errorMessage}`,
|
|
190
|
+
code: typeof raw.code === "number" ? raw.code : -1,
|
|
191
|
+
choices: [
|
|
192
|
+
{
|
|
193
|
+
index: 0,
|
|
194
|
+
message: {
|
|
195
|
+
id: requestId,
|
|
196
|
+
role: "assistant",
|
|
197
|
+
type: "error",
|
|
198
|
+
content: `[${errorCode}] ${errorMessage}`,
|
|
199
|
+
reasoning_content: "",
|
|
200
|
+
},
|
|
201
|
+
finish_reason: "error",
|
|
202
|
+
},
|
|
203
|
+
],
|
|
129
204
|
usage: {
|
|
130
205
|
prompt_tokens: 0,
|
|
131
206
|
completion_tokens: 0,
|
|
@@ -19,6 +19,8 @@ export declare class OpenAICompatApi implements QwenDocTurboApi {
|
|
|
19
19
|
private createAuthHeaders;
|
|
20
20
|
buildPayload(data: ModelRequestOptions, stream: boolean): OpenAICompatibleAPIInput;
|
|
21
21
|
request(payload: OpenAICompatibleAPIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | unknown>;
|
|
22
|
+
private isErrorResponse;
|
|
23
|
+
private normalizeErrorResponse;
|
|
22
24
|
normalizeResponse(response: OpenAICompatibleResponse): DoGenerateOutput;
|
|
23
25
|
normalizeStream(_stream: ReadableStream<Uint8Array>): ReadableStream<BaseDoStreamOutputChunk>;
|
|
24
26
|
}
|
|
@@ -64,8 +64,60 @@ class OpenAICompatApi {
|
|
|
64
64
|
return (0, utils_1.handleResponseData)(data, header);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
isErrorResponse(obj) {
|
|
68
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.error) && typeof obj.error === "object" && obj.error.code)
|
|
69
|
+
return true;
|
|
70
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.error) && typeof obj.error === "string" && obj.error.length > 0 && !obj.choices)
|
|
71
|
+
return true;
|
|
72
|
+
if (typeof (obj === null || obj === void 0 ? void 0 : obj.code) === "number" && obj.code !== 0 && !obj.choices)
|
|
73
|
+
return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
normalizeErrorResponse(res) {
|
|
77
|
+
var _a;
|
|
78
|
+
const err = typeof (res === null || res === void 0 ? void 0 : res.error) === "object" ? res.error : {};
|
|
79
|
+
const errorCode = (err === null || err === void 0 ? void 0 : err.code) || (res === null || res === void 0 ? void 0 : res.code) || "unknown_error";
|
|
80
|
+
const errorMessage = (err === null || err === void 0 ? void 0 : err.message) ||
|
|
81
|
+
(res === null || res === void 0 ? void 0 : res.message) ||
|
|
82
|
+
(typeof (res === null || res === void 0 ? void 0 : res.error) === "string" ? res.error : "Unknown error");
|
|
83
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || "";
|
|
84
|
+
const created = (_a = res === null || res === void 0 ? void 0 : res.created) !== null && _a !== void 0 ? _a : Math.floor(Date.now() / 1000);
|
|
85
|
+
return {
|
|
86
|
+
id,
|
|
87
|
+
object: "chat.completion",
|
|
88
|
+
created,
|
|
89
|
+
model: this.modelName,
|
|
90
|
+
log_id: id,
|
|
91
|
+
error: `[${errorCode}] ${errorMessage}`,
|
|
92
|
+
code: typeof (res === null || res === void 0 ? void 0 : res.code) === "number" ? res.code : -1,
|
|
93
|
+
choices: [
|
|
94
|
+
{
|
|
95
|
+
index: 0,
|
|
96
|
+
message: {
|
|
97
|
+
id,
|
|
98
|
+
role: "assistant",
|
|
99
|
+
type: "error",
|
|
100
|
+
content: `[${errorCode}] ${errorMessage}`,
|
|
101
|
+
reasoning_content: "",
|
|
102
|
+
},
|
|
103
|
+
finish_reason: "error",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
usage: {
|
|
107
|
+
prompt_tokens: 0,
|
|
108
|
+
completion_tokens: 0,
|
|
109
|
+
knowledge_tokens: 0,
|
|
110
|
+
reasoning_tokens: 0,
|
|
111
|
+
total_tokens: 0,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
67
115
|
normalizeResponse(response) {
|
|
68
116
|
var _a, _b, _c, _d, _e;
|
|
117
|
+
const res = response;
|
|
118
|
+
if (this.isErrorResponse(res)) {
|
|
119
|
+
return this.normalizeErrorResponse(res);
|
|
120
|
+
}
|
|
69
121
|
const choice = (_a = response.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
70
122
|
const requestId = response.id || "";
|
|
71
123
|
const created = response.created || Math.floor(Date.now() / 1000);
|
|
@@ -81,7 +133,13 @@ class OpenAICompatApi {
|
|
|
81
133
|
choices: [
|
|
82
134
|
{
|
|
83
135
|
index: 0,
|
|
84
|
-
message: {
|
|
136
|
+
message: {
|
|
137
|
+
id: requestId,
|
|
138
|
+
role: "assistant",
|
|
139
|
+
type: "answer",
|
|
140
|
+
content,
|
|
141
|
+
reasoning_content: "",
|
|
142
|
+
},
|
|
85
143
|
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
86
144
|
},
|
|
87
145
|
],
|
|
@@ -101,8 +159,49 @@ class OpenAICompatApi {
|
|
|
101
159
|
return raw.pipeThrough(new stream_1.TransformStream({
|
|
102
160
|
transform(chunk, controller) {
|
|
103
161
|
var _a, _b, _c, _d, _e;
|
|
104
|
-
const
|
|
105
|
-
const
|
|
162
|
+
const raw = chunk;
|
|
163
|
+
const requestId = raw.id || "";
|
|
164
|
+
const created = raw.created || Math.floor(Date.now() / 1000);
|
|
165
|
+
const hasNestedError = (raw === null || raw === void 0 ? void 0 : raw.error) && typeof raw.error === "object" && raw.error.code;
|
|
166
|
+
const hasStringError = (raw === null || raw === void 0 ? void 0 : raw.error) && typeof raw.error === "string" && raw.error.length > 0 && !raw.choices;
|
|
167
|
+
const hasCodeError = typeof (raw === null || raw === void 0 ? void 0 : raw.code) === "number" && raw.code !== 0 && !raw.choices;
|
|
168
|
+
if (hasNestedError || hasStringError || hasCodeError) {
|
|
169
|
+
const err = typeof (raw === null || raw === void 0 ? void 0 : raw.error) === "object" ? raw.error : {};
|
|
170
|
+
const errorCode = (err === null || err === void 0 ? void 0 : err.code) || (raw === null || raw === void 0 ? void 0 : raw.code) || "unknown_error";
|
|
171
|
+
const errorMessage = (err === null || err === void 0 ? void 0 : err.message) ||
|
|
172
|
+
(raw === null || raw === void 0 ? void 0 : raw.message) ||
|
|
173
|
+
(typeof (raw === null || raw === void 0 ? void 0 : raw.error) === "string" ? raw.error : "Unknown error");
|
|
174
|
+
controller.enqueue({
|
|
175
|
+
id: requestId,
|
|
176
|
+
object: "chat.completion.chunk",
|
|
177
|
+
created,
|
|
178
|
+
model: modelName,
|
|
179
|
+
log_id: requestId,
|
|
180
|
+
error: `[${errorCode}] ${errorMessage}`,
|
|
181
|
+
code: typeof raw.code === "number" ? raw.code : -1,
|
|
182
|
+
choices: [
|
|
183
|
+
{
|
|
184
|
+
index: 0,
|
|
185
|
+
message: {
|
|
186
|
+
id: requestId,
|
|
187
|
+
role: "assistant",
|
|
188
|
+
type: "error",
|
|
189
|
+
content: `[${errorCode}] ${errorMessage}`,
|
|
190
|
+
reasoning_content: "",
|
|
191
|
+
},
|
|
192
|
+
finish_reason: "error",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
usage: {
|
|
196
|
+
prompt_tokens: 0,
|
|
197
|
+
completion_tokens: 0,
|
|
198
|
+
knowledge_tokens: 0,
|
|
199
|
+
reasoning_tokens: 0,
|
|
200
|
+
total_tokens: 0,
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
106
205
|
const choice = (_a = chunk.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
107
206
|
const deltaContent = ((_b = choice === null || choice === void 0 ? void 0 : choice.delta) === null || _b === void 0 ? void 0 : _b.content) || "";
|
|
108
207
|
if (!deltaContent && !(choice === null || choice === void 0 ? void 0 : choice.finish_reason))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
2
|
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../../model-type";
|
|
3
|
-
import { TokenManager } from "../../tokenManager";
|
|
3
|
+
import type { TokenManager } from "../../tokenManager";
|
|
4
4
|
import { SimpleChatModel } from "../Chat";
|
|
5
5
|
export interface QwenImageParameters {
|
|
6
6
|
negative_prompt?: string;
|
|
@@ -76,6 +76,8 @@ export declare class QwenImageModel extends SimpleChatModel {
|
|
|
76
76
|
parameters?: QwenImageParameters;
|
|
77
77
|
}): QwenImageRequestOptions;
|
|
78
78
|
protected modelRequest(data: QwenImageRequestOptions, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
|
|
79
|
+
private isErrorResponse;
|
|
80
|
+
private normalizeErrorResponse;
|
|
79
81
|
doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
80
82
|
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
81
83
|
}
|
|
@@ -52,7 +52,9 @@ class QwenImageModel extends Chat_1.SimpleChatModel {
|
|
|
52
52
|
}
|
|
53
53
|
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);
|
|
54
54
|
const message = (_h = first === null || first === void 0 ? void 0 : first.message) !== null && _h !== void 0 ? _h : {};
|
|
55
|
-
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
|
+
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)
|
|
56
|
+
? String(message.content[0].image)
|
|
57
|
+
: "";
|
|
56
58
|
const created = (_k = res === null || res === void 0 ? void 0 : res.created) !== null && _k !== void 0 ? _k : Math.floor(Date.now() / 1000);
|
|
57
59
|
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
58
60
|
const normalized = {
|
|
@@ -138,6 +140,52 @@ class QwenImageModel extends Chat_1.SimpleChatModel {
|
|
|
138
140
|
return (0, utils_1.handleResponseData)(responseData, header);
|
|
139
141
|
});
|
|
140
142
|
}
|
|
143
|
+
isErrorResponse(obj) {
|
|
144
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.error) && typeof obj.error === "object" && obj.error.code)
|
|
145
|
+
return true;
|
|
146
|
+
if (typeof (obj === null || obj === void 0 ? void 0 : obj.code) === "string" && !(obj === null || obj === void 0 ? void 0 : obj.output))
|
|
147
|
+
return true;
|
|
148
|
+
if (typeof (obj === null || obj === void 0 ? void 0 : obj.code) === "number" && obj.code !== 0 && !(obj === null || obj === void 0 ? void 0 : obj.output))
|
|
149
|
+
return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
normalizeErrorResponse(res) {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
const err = typeof (res === null || res === void 0 ? void 0 : res.error) === "object" ? res.error : {};
|
|
155
|
+
const errorCode = (err === null || err === void 0 ? void 0 : err.code) || (res === null || res === void 0 ? void 0 : res.code) || "unknown_error";
|
|
156
|
+
const errorMessage = (err === null || err === void 0 ? void 0 : err.message) || (res === null || res === void 0 ? void 0 : res.message) || "Unknown error";
|
|
157
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
158
|
+
const created = (_a = res === null || res === void 0 ? void 0 : res.created) !== null && _a !== void 0 ? _a : Math.floor(Date.now() / 1000);
|
|
159
|
+
return {
|
|
160
|
+
id,
|
|
161
|
+
object: "chat.completion",
|
|
162
|
+
created,
|
|
163
|
+
model: (_b = res === null || res === void 0 ? void 0 : res.model) !== null && _b !== void 0 ? _b : this.modelName,
|
|
164
|
+
log_id: id,
|
|
165
|
+
error: `[${errorCode}] ${errorMessage}`,
|
|
166
|
+
code: typeof (res === null || res === void 0 ? void 0 : res.code) === "number" ? res.code : -1,
|
|
167
|
+
choices: [
|
|
168
|
+
{
|
|
169
|
+
index: 0,
|
|
170
|
+
message: {
|
|
171
|
+
id,
|
|
172
|
+
role: "assistant",
|
|
173
|
+
type: "error",
|
|
174
|
+
content: `[${errorCode}] ${errorMessage}`,
|
|
175
|
+
reasoning_content: "",
|
|
176
|
+
},
|
|
177
|
+
finish_reason: "error",
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
usage: {
|
|
181
|
+
prompt_tokens: 0,
|
|
182
|
+
completion_tokens: 0,
|
|
183
|
+
knowledge_tokens: 0,
|
|
184
|
+
reasoning_tokens: 0,
|
|
185
|
+
total_tokens: 0,
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
141
189
|
doGenerate(data, options) {
|
|
142
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
191
|
data.model = this.modelName;
|
|
@@ -152,6 +200,9 @@ class QwenImageModel extends Chat_1.SimpleChatModel {
|
|
|
152
200
|
}
|
|
153
201
|
const payload = this.coverModelRequestToQwenInput(data);
|
|
154
202
|
const res = (yield this.modelRequest(payload, options));
|
|
203
|
+
if (this.isErrorResponse(res)) {
|
|
204
|
+
return this.normalizeErrorResponse(res);
|
|
205
|
+
}
|
|
155
206
|
return this.normalizeStandardImageCompletion(res, this.modelName);
|
|
156
207
|
});
|
|
157
208
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../../model-type";
|
|
3
|
+
import type { TokenManager } from "../../tokenManager";
|
|
4
|
+
import { SimpleChatModel } from "../Chat";
|
|
5
|
+
export interface QwenImage20Parameters {
|
|
6
|
+
negative_prompt?: string;
|
|
7
|
+
size?: string;
|
|
8
|
+
n?: number;
|
|
9
|
+
prompt_extend?: boolean;
|
|
10
|
+
watermark?: boolean;
|
|
11
|
+
seed?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface QwenImage20APIInput {
|
|
14
|
+
model: string;
|
|
15
|
+
input: {
|
|
16
|
+
messages: Array<{
|
|
17
|
+
role: "user";
|
|
18
|
+
content: Array<{
|
|
19
|
+
image?: string;
|
|
20
|
+
text?: string;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
parameters?: QwenImage20Parameters;
|
|
25
|
+
}
|
|
26
|
+
export type QwenImage20RequestOptions = QwenImage20APIInput & {
|
|
27
|
+
parameters?: QwenImage20Parameters;
|
|
28
|
+
};
|
|
29
|
+
export type QwenImage20ContentItem = {
|
|
30
|
+
image?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
image_url?: string | {
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
b64_json?: string;
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
};
|
|
38
|
+
export interface QwenImage20APIResponse {
|
|
39
|
+
output?: {
|
|
40
|
+
choices?: Array<{
|
|
41
|
+
finish_reason: string;
|
|
42
|
+
message: {
|
|
43
|
+
role: "assistant" | "user";
|
|
44
|
+
content: QwenImage20ContentItem[];
|
|
45
|
+
};
|
|
46
|
+
}>;
|
|
47
|
+
task_status?: string;
|
|
48
|
+
task_id?: string;
|
|
49
|
+
task_metric?: {
|
|
50
|
+
TOTAL: number;
|
|
51
|
+
FAILED: number;
|
|
52
|
+
SUCCEEDED: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
usage?: {
|
|
56
|
+
width?: number;
|
|
57
|
+
height?: number;
|
|
58
|
+
image_count?: number;
|
|
59
|
+
};
|
|
60
|
+
request_id?: string;
|
|
61
|
+
id?: string;
|
|
62
|
+
model?: string;
|
|
63
|
+
created?: number;
|
|
64
|
+
object?: string;
|
|
65
|
+
code?: number | string;
|
|
66
|
+
error?: string;
|
|
67
|
+
message?: string;
|
|
68
|
+
}
|
|
69
|
+
export declare class QwenImage20Model extends SimpleChatModel {
|
|
70
|
+
static BASE_URL: string;
|
|
71
|
+
static SUB_URL: string;
|
|
72
|
+
modelName: string;
|
|
73
|
+
constructor(req: IAbstractRequest, baseUrl: string, tokenManager: TokenManager, model?: string);
|
|
74
|
+
protected normalizeStandardImageCompletion(res: QwenImage20APIResponse, fallbackModel: string): DoGenerateOutput;
|
|
75
|
+
protected convertToQwenImage20Input(data: ModelRequestOptions & {
|
|
76
|
+
parameters?: QwenImage20Parameters;
|
|
77
|
+
} & Record<string, any>): QwenImage20RequestOptions;
|
|
78
|
+
protected modelRequest(data: QwenImage20RequestOptions, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
|
|
79
|
+
private isErrorResponse;
|
|
80
|
+
private normalizeErrorResponse;
|
|
81
|
+
doGenerate(data: ModelRequestOptions & {
|
|
82
|
+
parameters?: QwenImage20Parameters;
|
|
83
|
+
}, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
84
|
+
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
85
|
+
}
|
|
86
|
+
export declare class QwenImage20ProModel extends QwenImage20Model {
|
|
87
|
+
constructor(req: IAbstractRequest, baseUrl: string, tokenManager: TokenManager);
|
|
88
|
+
}
|
|
89
|
+
export declare class QwenImage20FastModel extends QwenImage20Model {
|
|
90
|
+
constructor(req: IAbstractRequest, baseUrl: string, tokenManager: TokenManager);
|
|
91
|
+
}
|