@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.
Files changed (40) hide show
  1. package/{types → lib}/agent/index.d.ts +2 -2
  2. package/{types → lib}/ai.d.ts +7 -8
  3. package/lib/ai.js +20 -28
  4. package/{types → lib}/index.d.ts +3 -2
  5. package/lib/index.js +4 -3
  6. package/{types/types.d.ts → lib/model-type.d.ts} +62 -14
  7. package/lib/model-type.js +24 -0
  8. package/lib/models/Chat.d.ts +14 -0
  9. package/lib/models/Chat.js +36 -0
  10. package/lib/models/Default/index.d.ts +11 -0
  11. package/lib/models/{default.js → Default/index.js} +28 -11
  12. package/lib/models/QwenDocTurbo/index.d.ts +84 -0
  13. package/lib/models/QwenDocTurbo/index.js +178 -0
  14. package/lib/models/QwenImage/index.d.ts +81 -0
  15. package/lib/models/QwenImage/index.js +208 -0
  16. package/lib/models/QwenSketchToImage/index.d.ts +35 -0
  17. package/lib/models/QwenSketchToImage/index.js +155 -0
  18. package/lib/models/QwenStyleRepaintV1/index.d.ts +114 -0
  19. package/lib/models/QwenStyleRepaintV1/index.js +213 -0
  20. package/lib/models/QwenVlMax/index.d.ts +78 -0
  21. package/lib/models/QwenVlMax/index.js +121 -0
  22. package/lib/models/index.d.ts +50 -0
  23. package/lib/models/index.js +44 -4
  24. package/{types → lib}/models/react.d.ts +3 -2
  25. package/lib/models/react.js +3 -3
  26. package/{types → lib}/stream.d.ts +1 -8
  27. package/lib/tokenManager.d.ts +36 -0
  28. package/lib/tokenManager.js +89 -0
  29. package/lib/utils.js +2 -3
  30. package/package.json +4 -5
  31. package/lib/models/model-types.js +0 -6
  32. package/lib/types.js +0 -11
  33. package/types/models/default.d.ts +0 -13
  34. package/types/models/index.d.ts +0 -23
  35. package/types/models/model-types.d.ts +0 -131
  36. /package/{types → lib}/eventsource_parser/index.d.ts +0 -0
  37. /package/{types → lib}/eventsource_parser/parse.d.ts +0 -0
  38. /package/{types → lib}/eventsource_parser/stream.d.ts +0 -0
  39. /package/{types → lib}/eventsource_parser/types.d.ts +0 -0
  40. /package/{types → lib}/utils.d.ts +0 -0
@@ -1,6 +1,6 @@
1
- import type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, SendMessageInput } from "@vectorx/agent-runtime";
1
+ import type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, SendMessageInput } from "@vectorx/ai-types";
2
2
  import type { IAbstractRequest } from "@vectorx/ai-types";
3
- import type { IAgent, IAgentOptions } from "../types";
3
+ import type { IAgent, IAgentOptions } from "../model-type";
4
4
  export declare enum AiSdkEnv {
5
5
  Cloud = "cloud",
6
6
  MiniProgram = "miniprogram"
@@ -1,17 +1,16 @@
1
1
  import type { IAbstractRequest } from "@vectorx/ai-types";
2
2
  import { Agent } from "./agent";
3
3
  import { AiSdkEnv } from "./index";
4
+ import type * as types from "./model-type";
4
5
  import * as models from "./models";
5
- import type * as types from "./types";
6
- declare class AI {
7
- baseUrl: string;
8
- request: IAbstractRequest;
9
- modelSubUrl: string;
6
+ import { TokenManager } from "./tokenManager";
7
+ export declare class AI {
10
8
  env: AiSdkEnv;
9
+ protected baseUrl: string;
10
+ protected request: IAbstractRequest;
11
+ tokenManager: TokenManager;
11
12
  constructor(request: IAbstractRequest, baseUrl: string, env: AiSdkEnv);
12
- createModel(model: models.ModelName): models.ReactModel;
13
- modelRequest: (options: types.ModelRequestOptions) => Promise<any>;
13
+ createModel(model: models.ModelName | models.MultiModalModelName): models.ReActModel;
14
14
  createAgent(options: types.IAgentOptions): Agent;
15
15
  registerFunctionTool(functionTool: types.FunctionTool): void;
16
16
  }
17
- export { AI };
package/lib/ai.js CHANGED
@@ -32,50 +32,42 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
35
  Object.defineProperty(exports, "__esModule", { value: true });
45
36
  exports.AI = void 0;
46
37
  const agent_1 = require("./agent");
47
38
  const index_1 = require("./index");
48
39
  const models = __importStar(require("./models"));
49
- const utils_1 = require("./utils");
40
+ const tokenManager_1 = require("./tokenManager");
50
41
  class AI {
51
42
  constructor(request, baseUrl, env) {
52
- this.modelSubUrl = "conversation/chat";
53
- this.modelRequest = (options) => __awaiter(this, void 0, void 0, function* () {
54
- const fetchHeaders = {
55
- "Content-Type": "application/json",
56
- };
57
- options.stream && Object.assign(fetchHeaders, { Accept: "text/event-stream" });
58
- const { data: responseData, header } = (yield this.request.fetch({
59
- method: "post",
60
- headers: Object.assign({}, fetchHeaders),
61
- body: JSON.stringify(options),
62
- url: `${this.baseUrl}/${this.modelSubUrl}`,
63
- stream: options.stream,
64
- }));
65
- return (0, utils_1.handleResponseData)(responseData, header);
66
- });
43
+ this.env = index_1.AiSdkEnv.Cloud;
67
44
  this.baseUrl = baseUrl;
68
45
  this.request = request;
69
46
  this.env = env;
47
+ this.tokenManager = new tokenManager_1.TokenManager(this.request, this.baseUrl);
70
48
  }
71
49
  createModel(model) {
72
50
  if (this.env === index_1.AiSdkEnv.MiniProgram) {
73
51
  console.warn(`[${index_1.AiSdkEnv.MiniProgram}] is not supported for model creation`);
74
52
  return null;
75
53
  }
76
- const simpleModel = new models.DefaultSimpleModel(this.modelRequest, model);
77
- const reactModel = new models.ReactModel(simpleModel);
78
- return reactModel;
54
+ if (!models.isValidModel(model)) {
55
+ throw new Error(`[${model}] is not supported, please check the model name`);
56
+ }
57
+ switch (model) {
58
+ case models.MultiModalModelName.QwenImage:
59
+ return new models.ReActModel(new models.QwenImageModel(this.request, models.QwenImageModel.BASE_URL, this.tokenManager));
60
+ case models.MultiModalModelName.WanxSketchToImageLite:
61
+ return new models.ReActModel(new models.WanxSketchToImageLiteModel(this.request, models.WanxSketchToImageLiteModel.BASE_URL, this.tokenManager));
62
+ case models.MultiModalModelName.QwenStyleRepaintV1:
63
+ return new models.ReActModel(new models.QwenStyleRepaintV1Model(this.request, models.QwenStyleRepaintV1Model.BASE_URL, this.tokenManager));
64
+ case models.MultiModalModelName.QwenVlMax:
65
+ return new models.ReActModel(new models.QwenVlMax(this.request, models.QwenVlMax.BASE_URL, model, this.tokenManager));
66
+ case models.MultiModalModelName.QwenDocTurbo:
67
+ return new models.ReActModel(new models.QwenDocTurbo(this.request, models.QwenDocTurbo.BASE_URL, model, this.tokenManager));
68
+ default:
69
+ return new models.ReActModel(new models.DefaultSimpleModel(this.request, this.baseUrl, model));
70
+ }
79
71
  }
80
72
  createAgent(options) {
81
73
  if (this.env === index_1.AiSdkEnv.Cloud) {
@@ -1,13 +1,14 @@
1
1
  import type { IAbstractRequest } from "@vectorx/ai-types";
2
2
  import { AiSdkEnv } from "./agent";
3
3
  import { AI } from "./ai";
4
+ import { IAgentEnv } from "./model-type";
4
5
  import * as models from "./models";
5
- import { IAgentEnv } from "./types";
6
6
  interface ICreateAi {
7
7
  getBaseUrl: () => string;
8
8
  request: IAbstractRequest;
9
9
  env?: AiSdkEnv;
10
10
  }
11
11
  declare function createAi({ getBaseUrl, request, env }: ICreateAi): AI;
12
- export * from "./types";
12
+ export * from "./model-type";
13
+ export * from "./tokenManager";
13
14
  export { createAi, models, AI, AiSdkEnv, IAgentEnv };
package/lib/index.js CHANGED
@@ -42,14 +42,15 @@ const agent_1 = require("./agent");
42
42
  Object.defineProperty(exports, "AiSdkEnv", { enumerable: true, get: function () { return agent_1.AiSdkEnv; } });
43
43
  const ai_1 = require("./ai");
44
44
  Object.defineProperty(exports, "AI", { enumerable: true, get: function () { return ai_1.AI; } });
45
+ const model_type_1 = require("./model-type");
46
+ Object.defineProperty(exports, "IAgentEnv", { enumerable: true, get: function () { return model_type_1.IAgentEnv; } });
45
47
  const models = __importStar(require("./models"));
46
48
  exports.models = models;
47
- const types_1 = require("./types");
48
- Object.defineProperty(exports, "IAgentEnv", { enumerable: true, get: function () { return types_1.IAgentEnv; } });
49
49
  function createAi({ getBaseUrl, request, env = agent_1.AiSdkEnv.Cloud }) {
50
50
  if (getBaseUrl == null || typeof getBaseUrl !== "function") {
51
51
  throw new Error("`getBaseUrl` is required!");
52
52
  }
53
53
  return new ai_1.AI(request, getBaseUrl(), env);
54
54
  }
55
- __exportStar(require("./types"), exports);
55
+ __exportStar(require("./model-type"), exports);
56
+ __exportStar(require("./tokenManager"), exports);
@@ -1,23 +1,61 @@
1
- import type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, SendMessageInput } from "@vectorx/agent-runtime";
1
+ import type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, QueryTasksResponse, SendMessageInput, UploadFileInput, UploadFileResponse } from "@vectorx/ai-types";
2
2
  import type { ModelName } from "./models";
3
- export type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, SendMessageInput, };
4
- type RawResponse = {
5
- rawResponse?: any;
6
- };
7
- export type DoGenerateOutput = BaseDoGenerateOutput & RawResponse;
8
- export type DoStreamOutput = AsyncIterableReadableStream<BaseDoStreamOutputChunk & RawResponse>;
9
- export type ChatModelConstructor = typeof SimpleChatModel;
3
+ export type { GetAgentInfoResponse, GetConversationsResponse, GetHistoryMessagesParams, GetHistoryMessagesResponse, SendMessageInput, QueryTasksResponse, UploadFileInput, UploadFileResponse, };
4
+ export type DoGenerateOutput = BaseDoGenerateOutput;
5
+ export type DoStreamOutput = AsyncIterableReadableStream<BaseDoStreamOutputChunk>;
10
6
  export type AsyncIterableReadableStream<T> = ReadableStream<T> & {
11
7
  [Symbol.asyncIterator]: () => {
12
8
  next(): Promise<IteratorResult<T>>;
13
9
  };
14
10
  };
15
- export declare abstract class SimpleChatModel {
16
- abstract doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
17
- abstract doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
11
+ export interface TextContent {
12
+ type: "text";
13
+ text: string;
14
+ }
15
+ export interface ImageUrlContent {
16
+ type: "image_url";
17
+ image_url: {
18
+ url: string;
19
+ detail?: "auto" | "low" | "high";
20
+ };
21
+ }
22
+ export interface DocUrlContent {
23
+ type: "doc_url";
24
+ doc_url: string[];
25
+ file_parsing_strategy?: "auto" | "text_only";
26
+ }
27
+ export interface VideoUrlContent {
28
+ type: "video_url";
29
+ video_url: {
30
+ url: string;
31
+ };
32
+ }
33
+ export interface AudioUrlContent {
34
+ type: "audio_url";
35
+ audio_url: {
36
+ url: string;
37
+ };
38
+ }
39
+ export interface VideoContent {
40
+ type: "video";
41
+ video: string[];
18
42
  }
43
+ export interface AudioContent {
44
+ type: "audio";
45
+ audio: string[];
46
+ }
47
+ export type MultiModalContent = TextContent | ImageUrlContent | DocUrlContent | VideoUrlContent | AudioUrlContent | VideoContent | AudioContent;
48
+ export type SupportedContentType = MultiModalContent["type"];
49
+ export declare function filterContentByTypes<T extends SupportedContentType>(content: MultiModalContent[], supportedTypes: T[]): Extract<MultiModalContent, {
50
+ type: T;
51
+ }>[];
52
+ export declare function hasContentType(content: string | MultiModalContent[], type: SupportedContentType): boolean;
53
+ export declare function extractContentByType<T extends SupportedContentType>(content: string | MultiModalContent[], type: T): Extract<MultiModalContent, {
54
+ type: T;
55
+ }>[];
19
56
  export interface ModelRequestOptions {
20
- model: ModelName;
57
+ async?: boolean;
58
+ model: ModelName | string;
21
59
  max_tokens?: number;
22
60
  temperature?: number;
23
61
  top_p?: number;
@@ -32,7 +70,7 @@ export interface ModelRequestOptions {
32
70
  }>;
33
71
  messages?: Array<{
34
72
  role: string;
35
- content: string;
73
+ content: string | MultiModalContent[];
36
74
  }>;
37
75
  knowledge_base?: Array<{
38
76
  knowledge_base_id: string;
@@ -43,6 +81,7 @@ export interface ModelRequestOptions {
43
81
  db_base?: any[];
44
82
  enable_thinking?: boolean;
45
83
  enable_search?: boolean;
84
+ parameters?: any;
46
85
  }
47
86
  export type ModelReq = <T extends ModelRequestOptions>(props: T) => T["stream"] extends true ? Promise<ReadableStream<Uint8Array>> : Promise<Object>;
48
87
  export interface IAgentReqInput {
@@ -55,6 +94,8 @@ export interface IAgentReqInput {
55
94
  }
56
95
  export interface ReqOptions {
57
96
  timeout?: number;
97
+ headers?: Record<string, string>;
98
+ method?: string;
58
99
  }
59
100
  export type AgentReq = <T extends IAgentReqInput>(props: T) => T["stream"] extends true ? Promise<ReadableStream<Uint8Array>> : Promise<Object>;
60
101
  export type UserMessage = {
@@ -113,13 +154,14 @@ export interface ChatCompletion {
113
154
  log_id: string;
114
155
  object: string;
115
156
  error: string;
157
+ message?: string;
116
158
  code: number;
117
159
  created: number;
118
160
  model: string;
119
161
  choices: Choice[];
120
162
  usage: Usage;
121
163
  }
122
- export type MessageType = "answer" | "function_call" | "function_call_response" | "knowledge_base_search" | "knowledge_base_search_response";
164
+ export type MessageType = "answer" | "image" | "video" | "async_task" | "function_call" | "function_call_response" | "knowledge_base_search" | "knowledge_base_search_response" | "error";
123
165
  export interface Choice {
124
166
  index: number;
125
167
  message: {
@@ -133,6 +175,10 @@ export interface Choice {
133
175
  search_results?: any[];
134
176
  };
135
177
  finish_reason: string;
178
+ delta?: {
179
+ content?: string;
180
+ reasoning_content?: string;
181
+ };
136
182
  }
137
183
  interface Usage {
138
184
  prompt_tokens: number;
@@ -146,6 +192,8 @@ export interface IAgent {
146
192
  getHistoryMessages?(input: GetHistoryMessagesParams): Promise<GetHistoryMessagesResponse>;
147
193
  getAgentInfo?(): Promise<GetAgentInfoResponse>;
148
194
  getConversations?(): Promise<GetConversationsResponse>;
195
+ queryTasks?(task_id?: string): Promise<QueryTasksResponse>;
196
+ uploadFile?(input: UploadFileInput): Promise<UploadFileResponse>;
149
197
  }
150
198
  export declare enum IAgentEnv {
151
199
  Production = "production",
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IAgentEnv = void 0;
4
+ exports.filterContentByTypes = filterContentByTypes;
5
+ exports.hasContentType = hasContentType;
6
+ exports.extractContentByType = extractContentByType;
7
+ function filterContentByTypes(content, supportedTypes) {
8
+ return content.filter((item) => supportedTypes.includes(item.type));
9
+ }
10
+ function hasContentType(content, type) {
11
+ if (typeof content === "string")
12
+ return false;
13
+ return content.some((item) => item.type === type);
14
+ }
15
+ function extractContentByType(content, type) {
16
+ if (typeof content === "string")
17
+ return [];
18
+ return content.filter((item) => item.type === type);
19
+ }
20
+ var IAgentEnv;
21
+ (function (IAgentEnv) {
22
+ IAgentEnv["Production"] = "production";
23
+ IAgentEnv["Development"] = "development";
24
+ })(IAgentEnv || (exports.IAgentEnv = IAgentEnv = {}));
@@ -0,0 +1,14 @@
1
+ import type { IAbstractRequest } from "@vectorx/ai-types";
2
+ import { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../model-type";
3
+ import { TokenManager } from "../tokenManager";
4
+ export declare abstract class SimpleChatModel {
5
+ protected req: IAbstractRequest;
6
+ protected baseUrl: string;
7
+ protected subUrl: string;
8
+ protected tokenManager?: TokenManager;
9
+ constructor(req: IAbstractRequest, baseUrl: string, subUrl: string, tokenManager?: TokenManager);
10
+ abstract doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
11
+ abstract doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
12
+ protected getValidToken(): Promise<string>;
13
+ protected createAuthHeaders(additionalHeaders?: Record<string, string>): Promise<Record<string, string>>;
14
+ }
@@ -0,0 +1,36 @@
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.SimpleChatModel = void 0;
13
+ class SimpleChatModel {
14
+ constructor(req, baseUrl, subUrl, tokenManager) {
15
+ this.req = req;
16
+ this.baseUrl = baseUrl;
17
+ this.subUrl = subUrl;
18
+ if (tokenManager)
19
+ this.tokenManager = tokenManager;
20
+ }
21
+ getValidToken() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (!this.tokenManager) {
24
+ throw new Error("TokenManager is not set");
25
+ }
26
+ return yield this.tokenManager.getValidToken();
27
+ });
28
+ }
29
+ createAuthHeaders() {
30
+ return __awaiter(this, arguments, void 0, function* (additionalHeaders = {}) {
31
+ const token = yield this.getValidToken();
32
+ return Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${token}` }, additionalHeaders);
33
+ });
34
+ }
35
+ }
36
+ exports.SimpleChatModel = SimpleChatModel;
@@ -0,0 +1,11 @@
1
+ import type { IAbstractRequest } from "@vectorx/ai-types";
2
+ import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../../model-type";
3
+ import { SimpleChatModel } from "../Chat";
4
+ import type { ModelName } from "../index";
5
+ export declare class DefaultSimpleModel extends SimpleChatModel {
6
+ modelName: ModelName;
7
+ constructor(req: IAbstractRequest, baseUrl: string, modelName: ModelName);
8
+ protected modelRequest(data: ModelRequestOptions, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
9
+ doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
10
+ doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
11
+ }
@@ -9,11 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DefaultSimpleModel = exports.SimpleChatModel = void 0;
13
- const stream_1 = require("../stream");
14
- class SimpleChatModel {
15
- }
16
- exports.SimpleChatModel = SimpleChatModel;
12
+ exports.DefaultSimpleModel = void 0;
13
+ const stream_1 = require("../../stream");
14
+ const utils_1 = require("../../utils");
15
+ const Chat_1 = require("../Chat");
17
16
  const defaultOptions = {
18
17
  max_tokens: 1000,
19
18
  temperature: 0.7,
@@ -26,22 +25,40 @@ const defaultOptions = {
26
25
  enable_thinking: false,
27
26
  enable_search: false,
28
27
  };
29
- class DefaultSimpleModel {
30
- constructor(req, modelName) {
31
- this.req = req;
28
+ class DefaultSimpleModel extends Chat_1.SimpleChatModel {
29
+ constructor(req, baseUrl, modelName) {
30
+ super(req, baseUrl, "conversation/chat");
32
31
  this.modelName = modelName;
33
32
  }
33
+ modelRequest(data_1) {
34
+ return __awaiter(this, arguments, void 0, function* (data, options = {
35
+ timeout: 30 * 1000,
36
+ }) {
37
+ const fetchHeaders = Object.assign({ "Content-Type": "application/json" }, ((options === null || options === void 0 ? void 0 : options.headers) || {}));
38
+ data.stream && Object.assign(fetchHeaders, { Accept: "text/event-stream" });
39
+ const { data: responseData, header } = (yield this.req.fetch({
40
+ url: `${this.baseUrl}/${this.subUrl}`,
41
+ headers: Object.assign({}, fetchHeaders),
42
+ body: JSON.stringify(data),
43
+ method: "post",
44
+ stream: Boolean(data.stream),
45
+ }));
46
+ return (0, utils_1.handleResponseData)(responseData, header);
47
+ });
48
+ }
34
49
  doGenerate(data, options) {
35
50
  return __awaiter(this, void 0, void 0, function* () {
36
51
  data.model = this.modelName;
37
- const res = yield this.req(Object.assign(Object.assign(Object.assign(Object.assign({}, defaultOptions), data), (options || {})), { stream: false }));
38
- return Object.assign(Object.assign({}, res), { rawResponse: res });
52
+ const payload = Object.assign(Object.assign(Object.assign({}, defaultOptions), data), { stream: false });
53
+ const res = yield this.modelRequest(payload, options);
54
+ return res;
39
55
  });
40
56
  }
41
57
  doStream(data, options) {
42
58
  return __awaiter(this, void 0, void 0, function* () {
43
59
  data.model = this.modelName;
44
- const _stream = yield this.req(Object.assign(Object.assign(Object.assign(Object.assign({}, defaultOptions), data), (options || {})), { stream: true }));
60
+ const payload = Object.assign(Object.assign(Object.assign({}, defaultOptions), data), { stream: true });
61
+ const _stream = (yield this.modelRequest(payload, options));
45
62
  const stream = (0, stream_1.toPolyfillReadable)(_stream);
46
63
  const standardStream = (0, stream_1.intoStandardStream)(stream);
47
64
  return (0, stream_1.createAsyncIterable)(standardStream);
@@ -0,0 +1,84 @@
1
+ import type { IAbstractRequest } from "@vectorx/ai-types";
2
+ import type { DoGenerateOutput, DoStreamOutput, DocUrlContent, 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 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
+ export declare class QwenDocTurbo extends SimpleChatModel {
74
+ static BASE_URL: string;
75
+ static SUB_URL: string;
76
+ modelName: MultiModalModelName;
77
+ constructor(req: IAbstractRequest, baseUrl: string, modelName: MultiModalModelName, tokenManager: TokenManager);
78
+ protected modelRequest(data: QwenDocTurboAPIInput, options?: ReqOptions): Promise<ReadableStream<Uint8Array> | Promise<unknown>>;
79
+ protected normalizeResponse(response: QwenDocTurboResponse): DoGenerateOutput;
80
+ doGenerate(data: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
81
+ doStream(data: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
82
+ private normalizeStreamChunks;
83
+ private convertToQwenDocTurboRequestOptions;
84
+ }