@vectorx/ai-sdk 0.1.3 → 0.4.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/{types → lib}/agent/index.d.ts +2 -2
- package/{types → lib}/ai.d.ts +7 -8
- package/lib/ai.js +20 -28
- package/{types → lib}/index.d.ts +3 -2
- package/lib/index.js +4 -3
- package/{types/types.d.ts → lib/model-type.d.ts} +62 -14
- package/lib/model-type.js +24 -0
- package/lib/models/Chat.d.ts +14 -0
- package/lib/models/Chat.js +36 -0
- package/lib/models/Default/index.d.ts +11 -0
- package/lib/models/{default.js → Default/index.js} +28 -11
- package/lib/models/QwenDocTurbo/index.d.ts +84 -0
- package/lib/models/QwenDocTurbo/index.js +178 -0
- package/lib/models/QwenImage/index.d.ts +81 -0
- package/lib/models/QwenImage/index.js +208 -0
- package/lib/models/QwenSketchToImage/index.d.ts +35 -0
- package/lib/models/QwenSketchToImage/index.js +155 -0
- package/lib/models/QwenStyleRepaintV1/index.d.ts +114 -0
- package/lib/models/QwenStyleRepaintV1/index.js +213 -0
- package/lib/models/QwenVlMax/index.d.ts +78 -0
- package/lib/models/QwenVlMax/index.js +121 -0
- package/lib/models/index.d.ts +50 -0
- package/lib/models/index.js +44 -4
- package/{types → lib}/models/react.d.ts +3 -2
- package/lib/models/react.js +3 -3
- package/{types → lib}/stream.d.ts +1 -8
- package/lib/tokenManager.d.ts +36 -0
- package/lib/tokenManager.js +89 -0
- package/lib/utils.js +2 -3
- package/package.json +4 -5
- package/lib/models/model-types.js +0 -6
- package/lib/types.js +0 -11
- package/types/models/default.d.ts +0 -13
- package/types/models/index.d.ts +0 -23
- package/types/models/model-types.d.ts +0 -131
- /package/{types → lib}/eventsource_parser/index.d.ts +0 -0
- /package/{types → lib}/eventsource_parser/parse.d.ts +0 -0
- /package/{types → lib}/eventsource_parser/stream.d.ts +0 -0
- /package/{types → lib}/eventsource_parser/types.d.ts +0 -0
- /package/{types → lib}/utils.d.ts +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
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 declare const STYLE_INDEX: {
|
|
6
|
+
readonly CUSTOM: -1;
|
|
7
|
+
readonly RETRO_COMIC: 0;
|
|
8
|
+
readonly FAIRY_TALE_3D: 1;
|
|
9
|
+
readonly ANIME_2D: 2;
|
|
10
|
+
readonly FRESH_STYLE: 3;
|
|
11
|
+
readonly FUTURE_TECH: 4;
|
|
12
|
+
readonly CHINESE_PAINTING: 5;
|
|
13
|
+
readonly GENERAL_BATTLE: 6;
|
|
14
|
+
readonly COLORFUL_CARTOON: 7;
|
|
15
|
+
readonly ELEGANT_CHINESE: 8;
|
|
16
|
+
readonly NEW_YEAR: 9;
|
|
17
|
+
readonly GONGBI_STYLE: 14;
|
|
18
|
+
readonly NEW_YEAR_GREET: 15;
|
|
19
|
+
readonly FAIRY_WORLD: 30;
|
|
20
|
+
readonly CLAY_WORLD: 31;
|
|
21
|
+
readonly PIXEL_WORLD: 32;
|
|
22
|
+
readonly ADVENTURE_WORLD: 33;
|
|
23
|
+
readonly JAPANESE_ANIME: 34;
|
|
24
|
+
readonly WORLD_3D: 35;
|
|
25
|
+
readonly ANIME_WORLD: 36;
|
|
26
|
+
readonly HAND_DRAWN: 37;
|
|
27
|
+
readonly CRAYON_WORLD: 38;
|
|
28
|
+
readonly FRIDGE_MAGNET: 39;
|
|
29
|
+
readonly BAJIQUAN_WORLD: 40;
|
|
30
|
+
};
|
|
31
|
+
export type StyleIndex = (typeof STYLE_INDEX)[keyof typeof STYLE_INDEX];
|
|
32
|
+
export interface QwenStyleRepaintV1Parameters {
|
|
33
|
+
style_index?: StyleIndex;
|
|
34
|
+
style_ref_url?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface QwenStyleRepaintV1StandardInput {
|
|
37
|
+
messages: Array<{
|
|
38
|
+
role: "user" | "assistant" | "system";
|
|
39
|
+
content: Array<{
|
|
40
|
+
type: "image_url";
|
|
41
|
+
image_url: {
|
|
42
|
+
url: string;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
type: "text";
|
|
46
|
+
text: string;
|
|
47
|
+
}>;
|
|
48
|
+
}>;
|
|
49
|
+
parameters?: QwenStyleRepaintV1Parameters;
|
|
50
|
+
}
|
|
51
|
+
export interface QwenStyleRepaintV1APIInput {
|
|
52
|
+
model: string;
|
|
53
|
+
input: {
|
|
54
|
+
image_url: string;
|
|
55
|
+
style_index: number;
|
|
56
|
+
style_ref_url?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export type QwenStyleRepaintV1RequestOptions = QwenStyleRepaintV1APIInput;
|
|
60
|
+
export type QwenStyleRepaintV1ContentItem = {
|
|
61
|
+
image?: string;
|
|
62
|
+
url?: string;
|
|
63
|
+
image_url?: string | {
|
|
64
|
+
url: string;
|
|
65
|
+
};
|
|
66
|
+
b64_json?: string;
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
};
|
|
69
|
+
export interface QwenStyleRepaintV1APIResponse {
|
|
70
|
+
async?: boolean;
|
|
71
|
+
output: {
|
|
72
|
+
choices?: Array<{
|
|
73
|
+
finish_reason: string;
|
|
74
|
+
message: {
|
|
75
|
+
role: "assistant" | "user";
|
|
76
|
+
content: QwenStyleRepaintV1ContentItem[];
|
|
77
|
+
};
|
|
78
|
+
}>;
|
|
79
|
+
task_status?: string;
|
|
80
|
+
task_id?: string;
|
|
81
|
+
task_metric?: {
|
|
82
|
+
TOTAL: number;
|
|
83
|
+
FAILED: number;
|
|
84
|
+
SUCCEEDED: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
usage?: {
|
|
88
|
+
width?: number;
|
|
89
|
+
height?: number;
|
|
90
|
+
image_count?: number;
|
|
91
|
+
};
|
|
92
|
+
request_id?: string;
|
|
93
|
+
id?: string;
|
|
94
|
+
model?: string;
|
|
95
|
+
created?: number;
|
|
96
|
+
object?: string;
|
|
97
|
+
code?: number;
|
|
98
|
+
error?: string;
|
|
99
|
+
}
|
|
100
|
+
export declare class QwenStyleRepaintV1Model extends SimpleChatModel {
|
|
101
|
+
static BASE_URL: string;
|
|
102
|
+
static SUB_URL: string;
|
|
103
|
+
modelName: string;
|
|
104
|
+
constructor(req: IAbstractRequest, baseUrl: string, tokenManager: TokenManager);
|
|
105
|
+
protected normalizeStandardImageCompletion(res: QwenStyleRepaintV1APIResponse, fallbackModel: string): DoGenerateOutput;
|
|
106
|
+
protected convertToStyleRepaintInput(data: ModelRequestOptions & {
|
|
107
|
+
parameters?: QwenStyleRepaintV1Parameters;
|
|
108
|
+
}): QwenStyleRepaintV1APIInput;
|
|
109
|
+
protected modelRequest(data: QwenStyleRepaintV1APIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
|
|
110
|
+
doGenerate(data: ModelRequestOptions & {
|
|
111
|
+
parameters?: QwenStyleRepaintV1Parameters;
|
|
112
|
+
}, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
113
|
+
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
114
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
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.QwenStyleRepaintV1Model = exports.STYLE_INDEX = void 0;
|
|
13
|
+
const stream_1 = require("../../stream");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const Chat_1 = require("../Chat");
|
|
16
|
+
const index_1 = require("../index");
|
|
17
|
+
exports.STYLE_INDEX = {
|
|
18
|
+
CUSTOM: -1,
|
|
19
|
+
RETRO_COMIC: 0,
|
|
20
|
+
FAIRY_TALE_3D: 1,
|
|
21
|
+
ANIME_2D: 2,
|
|
22
|
+
FRESH_STYLE: 3,
|
|
23
|
+
FUTURE_TECH: 4,
|
|
24
|
+
CHINESE_PAINTING: 5,
|
|
25
|
+
GENERAL_BATTLE: 6,
|
|
26
|
+
COLORFUL_CARTOON: 7,
|
|
27
|
+
ELEGANT_CHINESE: 8,
|
|
28
|
+
NEW_YEAR: 9,
|
|
29
|
+
GONGBI_STYLE: 14,
|
|
30
|
+
NEW_YEAR_GREET: 15,
|
|
31
|
+
FAIRY_WORLD: 30,
|
|
32
|
+
CLAY_WORLD: 31,
|
|
33
|
+
PIXEL_WORLD: 32,
|
|
34
|
+
ADVENTURE_WORLD: 33,
|
|
35
|
+
JAPANESE_ANIME: 34,
|
|
36
|
+
WORLD_3D: 35,
|
|
37
|
+
ANIME_WORLD: 36,
|
|
38
|
+
HAND_DRAWN: 37,
|
|
39
|
+
CRAYON_WORLD: 38,
|
|
40
|
+
FRIDGE_MAGNET: 39,
|
|
41
|
+
BAJIQUAN_WORLD: 40,
|
|
42
|
+
};
|
|
43
|
+
class QwenStyleRepaintV1Model extends Chat_1.SimpleChatModel {
|
|
44
|
+
constructor(req, baseUrl, tokenManager) {
|
|
45
|
+
super(req, baseUrl, QwenStyleRepaintV1Model.SUB_URL, tokenManager);
|
|
46
|
+
this.modelName = index_1.modelName[index_1.MultiModalModelName.QwenStyleRepaintV1];
|
|
47
|
+
}
|
|
48
|
+
normalizeStandardImageCompletion(res, fallbackModel) {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
50
|
+
const qOutput = (res === null || res === void 0 ? void 0 : res.output) || {};
|
|
51
|
+
if ((qOutput === null || qOutput === void 0 ? void 0 : qOutput.task_status) && (qOutput === null || qOutput === void 0 ? void 0 : qOutput.task_id)) {
|
|
52
|
+
const created = (_a = res === null || res === void 0 ? void 0 : res.created) !== null && _a !== void 0 ? _a : Math.floor(Date.now() / 1000);
|
|
53
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
54
|
+
const normalized = {
|
|
55
|
+
id,
|
|
56
|
+
object: (_b = res === null || res === void 0 ? void 0 : res.object) !== null && _b !== void 0 ? _b : "chat.completion",
|
|
57
|
+
created,
|
|
58
|
+
model: (_c = res === null || res === void 0 ? void 0 : res.model) !== null && _c !== void 0 ? _c : fallbackModel,
|
|
59
|
+
log_id: id,
|
|
60
|
+
error: (_d = res === null || res === void 0 ? void 0 : res.error) !== null && _d !== void 0 ? _d : "",
|
|
61
|
+
code: (_e = res === null || res === void 0 ? void 0 : res.code) !== null && _e !== void 0 ? _e : 0,
|
|
62
|
+
choices: [
|
|
63
|
+
{
|
|
64
|
+
index: 0,
|
|
65
|
+
message: {
|
|
66
|
+
id,
|
|
67
|
+
role: "assistant",
|
|
68
|
+
type: "async_task",
|
|
69
|
+
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 })),
|
|
70
|
+
reasoning_content: "",
|
|
71
|
+
},
|
|
72
|
+
finish_reason: "stop",
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
usage: mapUsageToStandard(res === null || res === void 0 ? void 0 : res.usage),
|
|
76
|
+
};
|
|
77
|
+
return normalized;
|
|
78
|
+
}
|
|
79
|
+
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);
|
|
80
|
+
const message = (_h = first === null || first === void 0 ? void 0 : first.message) !== null && _h !== void 0 ? _h : {};
|
|
81
|
+
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) ? String(message.content[0].image) : "";
|
|
82
|
+
const created = (_k = res === null || res === void 0 ? void 0 : res.created) !== null && _k !== void 0 ? _k : Math.floor(Date.now() / 1000);
|
|
83
|
+
const id = (res === null || res === void 0 ? void 0 : res.id) || (res === null || res === void 0 ? void 0 : res.request_id) || "";
|
|
84
|
+
const normalized = {
|
|
85
|
+
id,
|
|
86
|
+
object: (_l = res === null || res === void 0 ? void 0 : res.object) !== null && _l !== void 0 ? _l : "chat.completion",
|
|
87
|
+
created,
|
|
88
|
+
model: (_m = res === null || res === void 0 ? void 0 : res.model) !== null && _m !== void 0 ? _m : fallbackModel,
|
|
89
|
+
log_id: id,
|
|
90
|
+
error: (_o = res === null || res === void 0 ? void 0 : res.error) !== null && _o !== void 0 ? _o : "",
|
|
91
|
+
code: (_p = res === null || res === void 0 ? void 0 : res.code) !== null && _p !== void 0 ? _p : 0,
|
|
92
|
+
choices: [
|
|
93
|
+
{
|
|
94
|
+
index: 0,
|
|
95
|
+
message: {
|
|
96
|
+
id,
|
|
97
|
+
role: "assistant",
|
|
98
|
+
type: "image",
|
|
99
|
+
content: contentUrl || "",
|
|
100
|
+
reasoning_content: "",
|
|
101
|
+
},
|
|
102
|
+
finish_reason: (_q = first === null || first === void 0 ? void 0 : first.finish_reason) !== null && _q !== void 0 ? _q : "stop",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
usage: mapUsageToStandard(res === null || res === void 0 ? void 0 : res.usage),
|
|
106
|
+
};
|
|
107
|
+
return normalized;
|
|
108
|
+
}
|
|
109
|
+
convertToStyleRepaintInput(data) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
const messages = data.messages || [];
|
|
112
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
113
|
+
throw new Error("wanx-style-repaint-v1 请求需要提供 messages");
|
|
114
|
+
}
|
|
115
|
+
const userMessage = messages.find((m) => m.role === "user");
|
|
116
|
+
if (!userMessage || !Array.isArray(userMessage.content)) {
|
|
117
|
+
throw new Error("wanx-style-repaint-v1 请求需要提供 user 消息");
|
|
118
|
+
}
|
|
119
|
+
const imageContent = userMessage.content.find((c) => c.type === "image_url");
|
|
120
|
+
if (!((_a = imageContent === null || imageContent === void 0 ? void 0 : imageContent.image_url) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
121
|
+
throw new Error("wanx-style-repaint-v1 请求需要提供图片 URL");
|
|
122
|
+
}
|
|
123
|
+
const imageUrl = imageContent.image_url.url;
|
|
124
|
+
const modelParams = data.parameters || {};
|
|
125
|
+
const styleIndex = (_b = modelParams.style_index) !== null && _b !== void 0 ? _b : exports.STYLE_INDEX.FRESH_STYLE;
|
|
126
|
+
const styleRefUrl = modelParams.style_ref_url;
|
|
127
|
+
if (styleIndex === exports.STYLE_INDEX.CUSTOM && !styleRefUrl) {
|
|
128
|
+
throw new Error("使用自定义风格时(style_index: -1),必须提供 style_ref_url");
|
|
129
|
+
}
|
|
130
|
+
const input = {
|
|
131
|
+
image_url: imageUrl,
|
|
132
|
+
style_index: styleIndex,
|
|
133
|
+
};
|
|
134
|
+
if (styleIndex === exports.STYLE_INDEX.CUSTOM && styleRefUrl) {
|
|
135
|
+
input.style_ref_url = styleRefUrl;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
model: this.modelName,
|
|
139
|
+
input,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
modelRequest(data_1) {
|
|
143
|
+
return __awaiter(this, arguments, void 0, function* (data, options = {}) {
|
|
144
|
+
const fetchHeaders = yield this.createAuthHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
145
|
+
const { data: responseData, header } = (yield this.req.fetch({
|
|
146
|
+
method: "post",
|
|
147
|
+
headers: Object.assign(Object.assign({}, fetchHeaders), ((options === null || options === void 0 ? void 0 : options.headers) || {})),
|
|
148
|
+
body: JSON.stringify(data),
|
|
149
|
+
url: `${this.baseUrl}/${this.subUrl}`,
|
|
150
|
+
stream: false,
|
|
151
|
+
}));
|
|
152
|
+
return (0, utils_1.handleResponseData)(responseData, header);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
doGenerate(data, options) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
data.model = this.modelName;
|
|
158
|
+
const body = this.convertToStyleRepaintInput(data);
|
|
159
|
+
const headers = Object.assign(Object.assign({}, ((options === null || options === void 0 ? void 0 : options.headers) || {})), { "X-DashScope-Async": "enable" });
|
|
160
|
+
const res = (yield this.modelRequest(body, Object.assign(Object.assign({}, options), { headers })));
|
|
161
|
+
return this.normalizeStandardImageCompletion(res, this.modelName);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
doStream(data, options) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
const nonStream = yield this.doGenerate(data, options);
|
|
168
|
+
const msg = ((_b = (_a = nonStream.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || {};
|
|
169
|
+
const singleChunk = {
|
|
170
|
+
id: nonStream.id,
|
|
171
|
+
object: "chat.completion.chunk",
|
|
172
|
+
created: nonStream.created,
|
|
173
|
+
model: nonStream.model,
|
|
174
|
+
log_id: nonStream.log_id,
|
|
175
|
+
error: nonStream.error || "",
|
|
176
|
+
code: nonStream.code || 0,
|
|
177
|
+
choices: [
|
|
178
|
+
{
|
|
179
|
+
index: 0,
|
|
180
|
+
message: {
|
|
181
|
+
id: nonStream.id,
|
|
182
|
+
role: "assistant",
|
|
183
|
+
type: msg.type || "async_task",
|
|
184
|
+
content: msg.content || "",
|
|
185
|
+
reasoning_content: "",
|
|
186
|
+
},
|
|
187
|
+
finish_reason: "stop",
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
usage: nonStream.usage,
|
|
191
|
+
};
|
|
192
|
+
const stream = new stream_1.ReadableStream({
|
|
193
|
+
start(controller) {
|
|
194
|
+
controller.enqueue(singleChunk);
|
|
195
|
+
controller.close();
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
return (0, stream_1.createAsyncIterable)(stream);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.QwenStyleRepaintV1Model = QwenStyleRepaintV1Model;
|
|
203
|
+
QwenStyleRepaintV1Model.BASE_URL = "https://dashscope.aliyuncs.com";
|
|
204
|
+
QwenStyleRepaintV1Model.SUB_URL = "api/v1/services/aigc/image-generation/generation";
|
|
205
|
+
function mapUsageToStandard(usage) {
|
|
206
|
+
return {
|
|
207
|
+
prompt_tokens: 0,
|
|
208
|
+
completion_tokens: 0,
|
|
209
|
+
knowledge_tokens: 0,
|
|
210
|
+
reasoning_tokens: 0,
|
|
211
|
+
total_tokens: 0,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { IAbstractRequest } from "@vectorx/ai-types";
|
|
2
|
+
import type { DoGenerateOutput, DoStreamOutput, ImageUrlContent, ModelRequestOptions, ReqOptions, TextContent } from "../../model-type";
|
|
3
|
+
import type { TokenManager } from "../../tokenManager";
|
|
4
|
+
import { SimpleChatModel } from "../Chat";
|
|
5
|
+
import type { MultiModalModelName } from "../index";
|
|
6
|
+
export interface QwenVlMaxMessage {
|
|
7
|
+
role: "system" | "user" | "assistant";
|
|
8
|
+
content: string | Array<TextContent | ImageUrlContent>;
|
|
9
|
+
}
|
|
10
|
+
export interface QwenVlMaxParameters {
|
|
11
|
+
seed?: number;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
top_p?: number;
|
|
14
|
+
max_tokens?: number;
|
|
15
|
+
n?: number;
|
|
16
|
+
stream?: boolean;
|
|
17
|
+
stop?: string | string[];
|
|
18
|
+
frequency_penalty?: number;
|
|
19
|
+
presence_penalty?: number;
|
|
20
|
+
user?: string;
|
|
21
|
+
enable_search?: boolean;
|
|
22
|
+
enable_thinking?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface QwenVlMaxAPIInput extends QwenVlMaxParameters {
|
|
25
|
+
model: string;
|
|
26
|
+
messages: QwenVlMaxMessage[];
|
|
27
|
+
stream?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface QwenVlMaxResponse {
|
|
30
|
+
id: string;
|
|
31
|
+
object: string;
|
|
32
|
+
created: number;
|
|
33
|
+
model: string;
|
|
34
|
+
choices: Array<{
|
|
35
|
+
index: number;
|
|
36
|
+
message: {
|
|
37
|
+
role: string;
|
|
38
|
+
content: string;
|
|
39
|
+
};
|
|
40
|
+
finish_reason: string;
|
|
41
|
+
}>;
|
|
42
|
+
usage: {
|
|
43
|
+
prompt_tokens: number;
|
|
44
|
+
completion_tokens: number;
|
|
45
|
+
total_tokens: number;
|
|
46
|
+
output_tokens?: number;
|
|
47
|
+
input_tokens?: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface QwenVlMaxStreamChunk {
|
|
51
|
+
id: string;
|
|
52
|
+
object: string;
|
|
53
|
+
created: number;
|
|
54
|
+
model: string;
|
|
55
|
+
choices: Array<{
|
|
56
|
+
index: number;
|
|
57
|
+
delta: {
|
|
58
|
+
role?: string;
|
|
59
|
+
content?: string;
|
|
60
|
+
};
|
|
61
|
+
finish_reason: string | null;
|
|
62
|
+
}>;
|
|
63
|
+
usage?: {
|
|
64
|
+
prompt_tokens: number;
|
|
65
|
+
completion_tokens: number;
|
|
66
|
+
total_tokens: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export declare class QwenVlMax extends SimpleChatModel {
|
|
70
|
+
static BASE_URL: string;
|
|
71
|
+
modelName: MultiModalModelName;
|
|
72
|
+
constructor(req: IAbstractRequest, baseUrl: string, modelName: MultiModalModelName, tokenManager: TokenManager);
|
|
73
|
+
protected modelRequest(data: QwenVlMaxAPIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
|
|
74
|
+
protected normalizeResponse(response: QwenVlMaxResponse): DoGenerateOutput;
|
|
75
|
+
doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
76
|
+
doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
77
|
+
private convertToQwenVlMaxRequestOptions;
|
|
78
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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.QwenVlMax = void 0;
|
|
13
|
+
const model_type_1 = require("../../model-type");
|
|
14
|
+
const stream_1 = require("../../stream");
|
|
15
|
+
const utils_1 = require("../../utils");
|
|
16
|
+
const Chat_1 = require("../Chat");
|
|
17
|
+
const defaultParameters = {
|
|
18
|
+
max_tokens: 2000,
|
|
19
|
+
temperature: 1.0,
|
|
20
|
+
top_p: 1.0,
|
|
21
|
+
frequency_penalty: 0.0,
|
|
22
|
+
presence_penalty: 0.0,
|
|
23
|
+
stream: false,
|
|
24
|
+
enable_thinking: false,
|
|
25
|
+
enable_search: false,
|
|
26
|
+
n: 1,
|
|
27
|
+
};
|
|
28
|
+
class QwenVlMax extends Chat_1.SimpleChatModel {
|
|
29
|
+
constructor(req, baseUrl, modelName, tokenManager) {
|
|
30
|
+
super(req, baseUrl, "compatible-mode/v1/chat/completions", tokenManager);
|
|
31
|
+
this.modelName = modelName;
|
|
32
|
+
}
|
|
33
|
+
modelRequest(data, options) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const fetchHeaders = yield this.createAuthHeaders(options === null || options === void 0 ? void 0 : options.headers);
|
|
36
|
+
const { data: responseData, header } = (yield this.req.fetch({
|
|
37
|
+
method: "post",
|
|
38
|
+
headers: Object.assign({}, fetchHeaders),
|
|
39
|
+
body: JSON.stringify(data),
|
|
40
|
+
url: `${this.baseUrl}/${this.subUrl}`,
|
|
41
|
+
stream: Boolean(data.stream),
|
|
42
|
+
}));
|
|
43
|
+
return (0, utils_1.handleResponseData)(responseData, header);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
normalizeResponse(response) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
const choice = (_a = response.choices) === null || _a === void 0 ? void 0 : _a[0];
|
|
49
|
+
const message = choice === null || choice === void 0 ? void 0 : choice.message;
|
|
50
|
+
return {
|
|
51
|
+
id: response.id,
|
|
52
|
+
object: response.object,
|
|
53
|
+
created: response.created,
|
|
54
|
+
model: response.model,
|
|
55
|
+
log_id: response.id,
|
|
56
|
+
error: "",
|
|
57
|
+
code: 0,
|
|
58
|
+
choices: [
|
|
59
|
+
{
|
|
60
|
+
index: (choice === null || choice === void 0 ? void 0 : choice.index) || 0,
|
|
61
|
+
message: {
|
|
62
|
+
id: response.id,
|
|
63
|
+
role: (message === null || message === void 0 ? void 0 : message.role) || "assistant",
|
|
64
|
+
type: "answer",
|
|
65
|
+
content: (message === null || message === void 0 ? void 0 : message.content) || "",
|
|
66
|
+
reasoning_content: "",
|
|
67
|
+
},
|
|
68
|
+
finish_reason: (choice === null || choice === void 0 ? void 0 : choice.finish_reason) || "stop",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
usage: {
|
|
72
|
+
prompt_tokens: ((_b = response.usage) === null || _b === void 0 ? void 0 : _b.prompt_tokens) || 0,
|
|
73
|
+
completion_tokens: ((_c = response.usage) === null || _c === void 0 ? void 0 : _c.completion_tokens) || 0,
|
|
74
|
+
knowledge_tokens: 0,
|
|
75
|
+
reasoning_tokens: 0,
|
|
76
|
+
total_tokens: ((_d = response.usage) === null || _d === void 0 ? void 0 : _d.total_tokens) || 0,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
doGenerate(data, options) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const qwenVlMaxData = this.convertToQwenVlMaxRequestOptions(data);
|
|
83
|
+
const requestData = Object.assign(Object.assign({}, qwenVlMaxData), { stream: false });
|
|
84
|
+
const res = yield this.modelRequest(requestData, options);
|
|
85
|
+
return this.normalizeResponse(res);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
doStream(data, options) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const qwenVlMaxData = this.convertToQwenVlMaxRequestOptions(data);
|
|
91
|
+
const requestData = Object.assign(Object.assign({}, qwenVlMaxData), { stream: true });
|
|
92
|
+
const _stream = (yield this.modelRequest(requestData, options));
|
|
93
|
+
const stream = (0, stream_1.toPolyfillReadable)(_stream);
|
|
94
|
+
const standardStream = (0, stream_1.intoStandardStream)(stream);
|
|
95
|
+
return (0, stream_1.createAsyncIterable)(standardStream);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
convertToQwenVlMaxRequestOptions(data) {
|
|
99
|
+
var _a, _b, _c;
|
|
100
|
+
const clamp = (value, min, max, defaultValue) => value !== undefined ? Math.max(min, Math.min(max, value)) : defaultValue;
|
|
101
|
+
const messages = (data.messages || []).map((msg) => ({
|
|
102
|
+
role: msg.role,
|
|
103
|
+
content: Array.isArray(msg.content) ? (0, model_type_1.filterContentByTypes)(msg.content, ["text", "image_url"]) : msg.content,
|
|
104
|
+
}));
|
|
105
|
+
return {
|
|
106
|
+
model: this.modelName,
|
|
107
|
+
messages,
|
|
108
|
+
temperature: clamp(data.temperature, 0, 2, defaultParameters.temperature),
|
|
109
|
+
top_p: clamp(data.top_p, 0, 1, defaultParameters.top_p),
|
|
110
|
+
frequency_penalty: clamp(data.frequency_penalty, -2, 2, defaultParameters.frequency_penalty),
|
|
111
|
+
presence_penalty: clamp(data.presence_penalty, -2, 2, defaultParameters.presence_penalty),
|
|
112
|
+
max_tokens: clamp(data.max_tokens, 1, Number.POSITIVE_INFINITY, defaultParameters.max_tokens),
|
|
113
|
+
n: clamp(data.n, 1, Number.POSITIVE_INFINITY, defaultParameters.n),
|
|
114
|
+
stream: (_a = data.stream) !== null && _a !== void 0 ? _a : defaultParameters.stream,
|
|
115
|
+
enable_search: (_b = data.enable_search) !== null && _b !== void 0 ? _b : defaultParameters.enable_search,
|
|
116
|
+
enable_thinking: (_c = data.enable_thinking) !== null && _c !== void 0 ? _c : defaultParameters.enable_thinking,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.QwenVlMax = QwenVlMax;
|
|
121
|
+
QwenVlMax.BASE_URL = "https://dashscope.aliyuncs.com";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DefaultSimpleModel } from "./Default";
|
|
2
|
+
import { QwenDocTurbo } from "./QwenDocTurbo";
|
|
3
|
+
import { QwenImageModel } from "./QwenImage";
|
|
4
|
+
import { WanxSketchToImageLiteModel } from "./QwenSketchToImage";
|
|
5
|
+
import { QwenStyleRepaintV1Model } from "./QwenStyleRepaintV1";
|
|
6
|
+
import { QwenVlMax } from "./QwenVlMax";
|
|
7
|
+
import { ReActModel } from "./react";
|
|
8
|
+
export declare enum ModelName {
|
|
9
|
+
DeepSeekR1 = "deepseek-r1",
|
|
10
|
+
DeepSeekV3 = "deepseek-v3",
|
|
11
|
+
QwenMax = "qwen-max",
|
|
12
|
+
QwenLong = "qwen-long",
|
|
13
|
+
QwenPlus = "qwen-plus",
|
|
14
|
+
QwenTurbo = "qwen-turbo",
|
|
15
|
+
QwenVlOcr = "qwen-vl-ocr",
|
|
16
|
+
Wanx21T2iTurbo = "wanx2.1-t2i-turbo"
|
|
17
|
+
}
|
|
18
|
+
export declare enum MultiModalModelName {
|
|
19
|
+
QvqMaxLatest = "qvq-max-latest",
|
|
20
|
+
QwenVlMax = "qwen-vl-max",
|
|
21
|
+
QwenDocTurbo = "qwen-doc-turbo",
|
|
22
|
+
QwenOmniTurboRealtime = "qwen-omni-turbo-realtime",
|
|
23
|
+
Wanx21T2iPlus = "wanx2.1-t2i-plus",
|
|
24
|
+
Wanx21T2iTurbo = "wanx2.1-t2i-turbo",
|
|
25
|
+
QwenImage = "qwen-image",
|
|
26
|
+
WanxSketchToImageLite = "wanx-sketch-to-image-lite",
|
|
27
|
+
QwenStyleRepaintV1 = "wanx-style-repaint-v1"
|
|
28
|
+
}
|
|
29
|
+
export declare const modelName: {
|
|
30
|
+
"deepseek-r1": string;
|
|
31
|
+
"deepseek-v3": string;
|
|
32
|
+
"qwen-max": string;
|
|
33
|
+
"qwen-long": string;
|
|
34
|
+
"qwen-plus": string;
|
|
35
|
+
"qwen-turbo": string;
|
|
36
|
+
"qwen-vl-ocr": string;
|
|
37
|
+
"qvq-max-latest": string;
|
|
38
|
+
"qwen-vl-max": string;
|
|
39
|
+
"qwen-doc-turbo": string;
|
|
40
|
+
"qwen-omni-turbo-realtime": string;
|
|
41
|
+
"wanx2.1-t2i-plus": string;
|
|
42
|
+
"wanx2.1-t2i-turbo": string;
|
|
43
|
+
"qwen-image": string;
|
|
44
|
+
"wanx-sketch-to-image-lite": string;
|
|
45
|
+
"wanx-style-repaint-v1": string;
|
|
46
|
+
};
|
|
47
|
+
export declare const isValidModel: (model: ModelName | MultiModalModelName) => model is ModelName | MultiModalModelName;
|
|
48
|
+
export declare const isMultiModalModel: (model: ModelName | MultiModalModelName) => model is MultiModalModelName;
|
|
49
|
+
declare const toolMap: Map<string, Function>;
|
|
50
|
+
export { DefaultSimpleModel, QwenDocTurbo, ReActModel, toolMap, WanxSketchToImageLiteModel, QwenImageModel, QwenVlMax, QwenStyleRepaintV1Model, };
|
package/lib/models/index.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toolMap = exports.
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "DefaultSimpleModel", { enumerable: true, get: function () { return
|
|
3
|
+
exports.QwenStyleRepaintV1Model = exports.QwenVlMax = 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
|
+
const Default_1 = require("./Default");
|
|
5
|
+
Object.defineProperty(exports, "DefaultSimpleModel", { enumerable: true, get: function () { return Default_1.DefaultSimpleModel; } });
|
|
6
|
+
const QwenDocTurbo_1 = require("./QwenDocTurbo");
|
|
7
|
+
Object.defineProperty(exports, "QwenDocTurbo", { enumerable: true, get: function () { return QwenDocTurbo_1.QwenDocTurbo; } });
|
|
8
|
+
const QwenImage_1 = require("./QwenImage");
|
|
9
|
+
Object.defineProperty(exports, "QwenImageModel", { enumerable: true, get: function () { return QwenImage_1.QwenImageModel; } });
|
|
10
|
+
const QwenSketchToImage_1 = require("./QwenSketchToImage");
|
|
11
|
+
Object.defineProperty(exports, "WanxSketchToImageLiteModel", { enumerable: true, get: function () { return QwenSketchToImage_1.WanxSketchToImageLiteModel; } });
|
|
12
|
+
const QwenStyleRepaintV1_1 = require("./QwenStyleRepaintV1");
|
|
13
|
+
Object.defineProperty(exports, "QwenStyleRepaintV1Model", { enumerable: true, get: function () { return QwenStyleRepaintV1_1.QwenStyleRepaintV1Model; } });
|
|
14
|
+
const QwenVlMax_1 = require("./QwenVlMax");
|
|
15
|
+
Object.defineProperty(exports, "QwenVlMax", { enumerable: true, get: function () { return QwenVlMax_1.QwenVlMax; } });
|
|
6
16
|
const react_1 = require("./react");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "ReActModel", { enumerable: true, get: function () { return react_1.ReActModel; } });
|
|
8
18
|
var ModelName;
|
|
9
19
|
(function (ModelName) {
|
|
10
20
|
ModelName["DeepSeekR1"] = "deepseek-r1";
|
|
@@ -16,6 +26,18 @@ var ModelName;
|
|
|
16
26
|
ModelName["QwenVlOcr"] = "qwen-vl-ocr";
|
|
17
27
|
ModelName["Wanx21T2iTurbo"] = "wanx2.1-t2i-turbo";
|
|
18
28
|
})(ModelName || (exports.ModelName = ModelName = {}));
|
|
29
|
+
var MultiModalModelName;
|
|
30
|
+
(function (MultiModalModelName) {
|
|
31
|
+
MultiModalModelName["QvqMaxLatest"] = "qvq-max-latest";
|
|
32
|
+
MultiModalModelName["QwenVlMax"] = "qwen-vl-max";
|
|
33
|
+
MultiModalModelName["QwenDocTurbo"] = "qwen-doc-turbo";
|
|
34
|
+
MultiModalModelName["QwenOmniTurboRealtime"] = "qwen-omni-turbo-realtime";
|
|
35
|
+
MultiModalModelName["Wanx21T2iPlus"] = "wanx2.1-t2i-plus";
|
|
36
|
+
MultiModalModelName["Wanx21T2iTurbo"] = "wanx2.1-t2i-turbo";
|
|
37
|
+
MultiModalModelName["QwenImage"] = "qwen-image";
|
|
38
|
+
MultiModalModelName["WanxSketchToImageLite"] = "wanx-sketch-to-image-lite";
|
|
39
|
+
MultiModalModelName["QwenStyleRepaintV1"] = "wanx-style-repaint-v1";
|
|
40
|
+
})(MultiModalModelName || (exports.MultiModalModelName = MultiModalModelName = {}));
|
|
19
41
|
exports.modelName = {
|
|
20
42
|
[ModelName.DeepSeekR1]: "deepseek-r1",
|
|
21
43
|
[ModelName.DeepSeekV3]: "deepseek-v3",
|
|
@@ -24,6 +46,24 @@ exports.modelName = {
|
|
|
24
46
|
[ModelName.QwenPlus]: "qwen-plus",
|
|
25
47
|
[ModelName.QwenTurbo]: "qwen-turbo",
|
|
26
48
|
[ModelName.QwenVlOcr]: "qwen-vl-ocr",
|
|
49
|
+
[MultiModalModelName.QvqMaxLatest]: "qvq-max-latest",
|
|
50
|
+
[MultiModalModelName.QwenVlMax]: "qwen-vl-max",
|
|
51
|
+
[MultiModalModelName.QwenDocTurbo]: "qwen-doc-turbo",
|
|
52
|
+
[MultiModalModelName.QwenOmniTurboRealtime]: "qwen-omni-turbo-realtime",
|
|
53
|
+
[MultiModalModelName.Wanx21T2iPlus]: "wanx2.1-t2i-plus",
|
|
54
|
+
[MultiModalModelName.Wanx21T2iTurbo]: "wanx2.1-t2i-turbo",
|
|
55
|
+
[MultiModalModelName.QwenImage]: "qwen-image",
|
|
56
|
+
[MultiModalModelName.WanxSketchToImageLite]: "wanx-sketch-to-image-lite",
|
|
57
|
+
[MultiModalModelName.QwenStyleRepaintV1]: "wanx-style-repaint-v1",
|
|
27
58
|
};
|
|
59
|
+
const isValidModel = (model) => {
|
|
60
|
+
const modelNames = Object.values(exports.modelName);
|
|
61
|
+
return modelNames.includes(model);
|
|
62
|
+
};
|
|
63
|
+
exports.isValidModel = isValidModel;
|
|
64
|
+
const isMultiModalModel = (model) => {
|
|
65
|
+
return Object.values(MultiModalModelName).includes(model);
|
|
66
|
+
};
|
|
67
|
+
exports.isMultiModalModel = isMultiModalModel;
|
|
28
68
|
const toolMap = new Map();
|
|
29
69
|
exports.toolMap = toolMap;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions
|
|
2
|
-
|
|
1
|
+
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../model-type";
|
|
2
|
+
import type { SimpleChatModel } from "./Chat";
|
|
3
|
+
export declare class ReActModel {
|
|
3
4
|
private model;
|
|
4
5
|
constructor(model: SimpleChatModel);
|
|
5
6
|
generateText(_input: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
package/lib/models/react.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
class
|
|
12
|
+
exports.ReActModel = void 0;
|
|
13
|
+
class ReActModel {
|
|
14
14
|
constructor(model) {
|
|
15
15
|
this.model = model;
|
|
16
16
|
}
|
|
@@ -25,4 +25,4 @@ class ReactModel {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
exports.
|
|
28
|
+
exports.ReActModel = ReActModel;
|