@cloudbase/ai 2.7.3-beta.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 (96) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +15 -0
  3. package/LICENSE +202 -0
  4. package/dist/cjs/index.d.ts +40 -0
  5. package/dist/cjs/index.js +171 -0
  6. package/dist/cjs/models/HunYuan/index.d.ts +25 -0
  7. package/dist/cjs/models/HunYuan/index.js +191 -0
  8. package/dist/cjs/models/HunYuan/type.d.ts +52 -0
  9. package/dist/cjs/models/HunYuan/type.js +3 -0
  10. package/dist/cjs/models/HunYuanPreview/index.d.ts +25 -0
  11. package/dist/cjs/models/HunYuanPreview/index.js +191 -0
  12. package/dist/cjs/models/HunYuanPreview/type.d.ts +52 -0
  13. package/dist/cjs/models/HunYuanPreview/type.js +3 -0
  14. package/dist/cjs/models/HuoShan/index.d.ts +24 -0
  15. package/dist/cjs/models/HuoShan/index.js +163 -0
  16. package/dist/cjs/models/HuoShan/type.d.ts +38 -0
  17. package/dist/cjs/models/HuoShan/type.js +3 -0
  18. package/dist/cjs/models/LingJi/index.d.ts +24 -0
  19. package/dist/cjs/models/LingJi/index.js +163 -0
  20. package/dist/cjs/models/LingJi/type.d.ts +43 -0
  21. package/dist/cjs/models/LingJi/type.js +3 -0
  22. package/dist/cjs/models/LingYi/index.d.ts +24 -0
  23. package/dist/cjs/models/LingYi/index.js +163 -0
  24. package/dist/cjs/models/LingYi/type.d.ts +49 -0
  25. package/dist/cjs/models/LingYi/type.js +3 -0
  26. package/dist/cjs/models/YueZhi/index.d.ts +24 -0
  27. package/dist/cjs/models/YueZhi/index.js +163 -0
  28. package/dist/cjs/models/YueZhi/type.d.ts +31 -0
  29. package/dist/cjs/models/YueZhi/type.js +3 -0
  30. package/dist/cjs/models/ZhiPu/index.d.ts +24 -0
  31. package/dist/cjs/models/ZhiPu/index.js +163 -0
  32. package/dist/cjs/models/ZhiPu/type.d.ts +71 -0
  33. package/dist/cjs/models/ZhiPu/type.js +3 -0
  34. package/dist/cjs/models/index.d.ts +17 -0
  35. package/dist/cjs/models/index.js +27 -0
  36. package/dist/cjs/type.d.ts +37 -0
  37. package/dist/cjs/type.js +16 -0
  38. package/dist/cjs/utils.d.ts +28 -0
  39. package/dist/cjs/utils.js +152 -0
  40. package/dist/esm/index.d.ts +40 -0
  41. package/dist/esm/index.js +141 -0
  42. package/dist/esm/models/HunYuan/index.d.ts +25 -0
  43. package/dist/esm/models/HunYuan/index.js +188 -0
  44. package/dist/esm/models/HunYuan/type.d.ts +52 -0
  45. package/dist/esm/models/HunYuan/type.js +2 -0
  46. package/dist/esm/models/HunYuanPreview/index.d.ts +25 -0
  47. package/dist/esm/models/HunYuanPreview/index.js +188 -0
  48. package/dist/esm/models/HunYuanPreview/type.d.ts +52 -0
  49. package/dist/esm/models/HunYuanPreview/type.js +2 -0
  50. package/dist/esm/models/HuoShan/index.d.ts +24 -0
  51. package/dist/esm/models/HuoShan/index.js +160 -0
  52. package/dist/esm/models/HuoShan/type.d.ts +38 -0
  53. package/dist/esm/models/HuoShan/type.js +2 -0
  54. package/dist/esm/models/LingJi/index.d.ts +24 -0
  55. package/dist/esm/models/LingJi/index.js +160 -0
  56. package/dist/esm/models/LingJi/type.d.ts +43 -0
  57. package/dist/esm/models/LingJi/type.js +2 -0
  58. package/dist/esm/models/LingYi/index.d.ts +24 -0
  59. package/dist/esm/models/LingYi/index.js +160 -0
  60. package/dist/esm/models/LingYi/type.d.ts +49 -0
  61. package/dist/esm/models/LingYi/type.js +2 -0
  62. package/dist/esm/models/YueZhi/index.d.ts +24 -0
  63. package/dist/esm/models/YueZhi/index.js +160 -0
  64. package/dist/esm/models/YueZhi/type.d.ts +31 -0
  65. package/dist/esm/models/YueZhi/type.js +2 -0
  66. package/dist/esm/models/ZhiPu/index.d.ts +24 -0
  67. package/dist/esm/models/ZhiPu/index.js +160 -0
  68. package/dist/esm/models/ZhiPu/type.d.ts +71 -0
  69. package/dist/esm/models/ZhiPu/type.js +2 -0
  70. package/dist/esm/models/index.d.ts +17 -0
  71. package/dist/esm/models/index.js +18 -0
  72. package/dist/esm/type.d.ts +37 -0
  73. package/dist/esm/type.js +13 -0
  74. package/dist/esm/utils.d.ts +28 -0
  75. package/dist/esm/utils.js +147 -0
  76. package/package.json +36 -0
  77. package/src/index.ts +77 -0
  78. package/src/models/HunYuan/index.ts +110 -0
  79. package/src/models/HunYuan/type.ts +61 -0
  80. package/src/models/HunYuanPreview/index.ts +110 -0
  81. package/src/models/HunYuanPreview/type.ts +61 -0
  82. package/src/models/HuoShan/index.ts +92 -0
  83. package/src/models/HuoShan/type.ts +41 -0
  84. package/src/models/LingJi/index.ts +92 -0
  85. package/src/models/LingJi/type.ts +34 -0
  86. package/src/models/LingYi/index.ts +92 -0
  87. package/src/models/LingYi/type.ts +49 -0
  88. package/src/models/YueZhi/index.ts +92 -0
  89. package/src/models/YueZhi/type.ts +28 -0
  90. package/src/models/ZhiPu/index.ts +92 -0
  91. package/src/models/ZhiPu/type.ts +60 -0
  92. package/src/models/index.ts +19 -0
  93. package/src/type.ts +42 -0
  94. package/src/utils.ts +110 -0
  95. package/tsconfig.esm.json +16 -0
  96. package/tsconfig.json +16 -0
@@ -0,0 +1,147 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { TransformStream as _TransformStream, ReadableStream as _ReadableStream } from 'web-streams-polyfill';
38
+ import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
39
+ import { createParser } from 'eventsource-parser';
40
+ export var ReadableStream = _ReadableStream;
41
+ export var TransformStream = _TransformStream;
42
+ export var createEventSourceParserTransformStream = function () {
43
+ var parser;
44
+ return new TransformStream({
45
+ start: function (controller) {
46
+ parser = createParser(function (event) {
47
+ if (event.type === 'event') {
48
+ controller.enqueue(event);
49
+ }
50
+ });
51
+ },
52
+ transform: function (chunk) {
53
+ parser.feed(chunk);
54
+ },
55
+ });
56
+ };
57
+ export var toPolyfillReadable = createReadableStreamWrapper(ReadableStream);
58
+ var TextDecoderStream = (function () {
59
+ function TextDecoderStream(encoding, options) {
60
+ if (encoding === void 0) { encoding = 'utf-8'; }
61
+ if (options === void 0) { options = {}; }
62
+ var _this = this;
63
+ this.transform = new TransformStream({
64
+ transform: function (chunk, controller) {
65
+ var value = _this.handle.decode(chunk, { stream: true });
66
+ if (value) {
67
+ controller.enqueue(value);
68
+ }
69
+ },
70
+ flush: function (controller) {
71
+ var value = _this.handle.decode();
72
+ if (value) {
73
+ controller.enqueue(value);
74
+ }
75
+ controller.terminate();
76
+ },
77
+ });
78
+ this.handle = new TextDecoder(encoding, options);
79
+ }
80
+ Object.defineProperty(TextDecoderStream.prototype, "encoding", {
81
+ get: function () {
82
+ return this.handle.encoding;
83
+ },
84
+ enumerable: false,
85
+ configurable: true
86
+ });
87
+ Object.defineProperty(TextDecoderStream.prototype, "fatal", {
88
+ get: function () {
89
+ return this.handle.fatal;
90
+ },
91
+ enumerable: false,
92
+ configurable: true
93
+ });
94
+ Object.defineProperty(TextDecoderStream.prototype, "ignoreBOM", {
95
+ get: function () {
96
+ return this.handle.ignoreBOM;
97
+ },
98
+ enumerable: false,
99
+ configurable: true
100
+ });
101
+ Object.defineProperty(TextDecoderStream.prototype, "readable", {
102
+ get: function () {
103
+ return this.transform.readable;
104
+ },
105
+ enumerable: false,
106
+ configurable: true
107
+ });
108
+ Object.defineProperty(TextDecoderStream.prototype, "writable", {
109
+ get: function () {
110
+ return this.transform.writable;
111
+ },
112
+ enumerable: false,
113
+ configurable: true
114
+ });
115
+ Object.defineProperty(TextDecoderStream.prototype, Symbol.toStringTag, {
116
+ get: function () {
117
+ return 'TextDecoderStream';
118
+ },
119
+ enumerable: false,
120
+ configurable: true
121
+ });
122
+ return TextDecoderStream;
123
+ }());
124
+ export { TextDecoderStream };
125
+ export function createAsyncIterable(stream) {
126
+ var _stream = stream;
127
+ _stream[Symbol.asyncIterator] = function () {
128
+ var reader = stream.getReader();
129
+ return {
130
+ next: function () {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var _a, done, value;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0: return [4, reader.read()];
136
+ case 1:
137
+ _a = _b.sent(), done = _a.done, value = _a.value;
138
+ return [2, done ? { done: true, value: undefined } : { done: false, value: value }];
139
+ }
140
+ });
141
+ });
142
+ },
143
+ };
144
+ };
145
+ return _stream;
146
+ }
147
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsT0FBTyxFQUFFLGVBQWUsSUFBSSxnQkFBZ0IsRUFBRSxjQUFjLElBQUksZUFBZSxFQUFFLE1BQU0sc0JBQXNCLENBQUE7QUFDN0csT0FBTyxFQUFFLDJCQUEyQixFQUFFLE1BQU0scUNBQXFDLENBQUE7QUFDakYsT0FBTyxFQUFFLFlBQVksRUFBNEMsTUFBTSxvQkFBb0IsQ0FBQTtBQUczRixNQUFNLENBQUMsSUFBTSxjQUFjLEdBQUcsZUFXN0IsQ0FBQTtBQUVELE1BQU0sQ0FBQyxJQUFNLGVBQWUsR0FBRyxnQkFROUIsQ0FBQTtBQUVELE1BQU0sQ0FBQyxJQUFNLHNDQUFzQyxHQUFHO0lBQ3BELElBQUksTUFBMEIsQ0FBQTtJQUU5QixPQUFPLElBQUksZUFBZSxDQUFzQjtRQUM5QyxLQUFLLFlBQUMsVUFBVTtZQUNkLE1BQU0sR0FBRyxZQUFZLENBQUMsV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G4gICAgICAgIHJldHVybiBkb25lID8geyBkb25lOiB0cnVlLCB2YWx1ZTogdW5kZWZpbmVkIH0gOiB7IGRvbmU6IGZhbHNlLCB2YWx1ZSB9XG4gICAgICB9LFxuICAgIH1cbiAgfVxuICByZXR1cm4gX3N0cmVhbVxufVxuIl19
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@cloudbase/ai",
3
+ "version": "2.7.3-beta.0",
4
+ "description": "cloudbase js sdk ai module",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "scripts": {
8
+ "tsc": "rm -rf dist/ && tsc -p tsconfig.esm.json && tsc -p tsconfig.json",
9
+ "lint": "eslint --fix \"./src/**/*.ts\"",
10
+ "build": "npm run lint && npm run tsc",
11
+ "precommit": "npm run lint"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/TencentCloudBase/cloudbase-js-sdk"
19
+ },
20
+ "keywords": [
21
+ "tcb",
22
+ "cloudbase",
23
+ "javascript",
24
+ "typescript",
25
+ "serverless"
26
+ ],
27
+ "author": "",
28
+ "license": "Apache-2.0",
29
+ "dependencies": {
30
+ "@cloudbase/types": "^2.7.3-beta.0",
31
+ "@mattiasbuelens/web-streams-adapter": "^0.1.0",
32
+ "eventsource-parser": "^1.1.2",
33
+ "web-streams-polyfill": "^4.0.0"
34
+ },
35
+ "gitHead": "ba281f964f720e4f87e79e9f87c7cda352fd4eb2"
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,77 @@
1
+ import type { ICloudbase } from '@cloudbase/types'
2
+ import type { ICloudbaseComponent } from '@cloudbase/types/component'
3
+ import type { SDKRequestInterface } from '@cloudbase/adapter-interface'
4
+ import * as models from './models'
5
+ import * as types from './type'
6
+ import * as utils from './utils'
7
+
8
+ const { MODELS, ...restModels } = models
9
+
10
+ class AI {
11
+ constructor(private req: SDKRequestInterface, public baseUrl: string) {}
12
+
13
+ request: types.ModelReq = async ({ url, data, headers, stream }) => (
14
+ await this.req.fetch({
15
+ method: 'post',
16
+ headers: {
17
+ ...headers,
18
+ },
19
+ body: JSON.stringify(data),
20
+ url,
21
+ stream,
22
+ })
23
+ ).data
24
+
25
+ createModel<T extends keyof typeof MODELS>(model: T) {
26
+ return new MODELS[model](this.request, this.baseUrl) as InstanceType<(typeof MODELS)[T]>
27
+ }
28
+
29
+ registerModel(name: string, model: types.ChatModelConstructor) {
30
+ if (MODELS[name] != null) {
31
+ console.warn(`AI model ${name} already exists!`)
32
+ return
33
+ }
34
+ MODELS[name] = model
35
+ }
36
+ }
37
+
38
+ const COMPONENT_NAME = 'ai'
39
+
40
+ interface AIInitOption {
41
+ env?: string
42
+ region?: string
43
+ baseUrl?: string
44
+ }
45
+
46
+ async function ai(this: ICloudbase, options?: AIInitOption) {
47
+ const req = this.request
48
+
49
+ if (req.fetch == null) {
50
+ throw new Error('cloudbase.request.fetch() unimplemented!')
51
+ }
52
+
53
+ const accessTokenFromAuth = this.authInstance
54
+ ? await this.authInstance!.getAccessToken()
55
+ : { accessToken: '', env: '' }
56
+
57
+ const env = options?.env ?? accessTokenFromAuth.env
58
+ const region = options?.region ?? 'ap-shanghai'
59
+ const baseUrl = options?.baseUrl ?? `https://${env}.${region}.ai.tcloudbasegateway.com/v1/ai`
60
+
61
+ return new AI(req, baseUrl)
62
+ }
63
+
64
+ const component: ICloudbaseComponent = {
65
+ name: COMPONENT_NAME,
66
+ entity: { ai },
67
+ }
68
+
69
+ function registerAi(app: ICloudbase) {
70
+ try {
71
+ app.registerComponent(component)
72
+ } catch (e) {
73
+ console.warn(e)
74
+ }
75
+ }
76
+
77
+ export { types, utils, restModels as models, registerAi, AI }
@@ -0,0 +1,110 @@
1
+ import { type ParsedEvent } from 'eventsource-parser/stream'
2
+ import {
3
+ createAsyncIterable,
4
+ TransformStream,
5
+ TextDecoderStream,
6
+ createEventSourceParserTransformStream,
7
+ toPolyfillReadable,
8
+ } from '../../utils'
9
+ import type { HunYuanInputData, HunYaunGenerateTextOutput, HunYaunStreamTextOutput } from './type'
10
+ import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
11
+
12
+ export class HunYuanModel implements ChatModel {
13
+ public subUrl = 'tencent_hunyuan/'
14
+ constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
15
+ if (subUrl != null) {
16
+ this.subUrl = subUrl
17
+ }
18
+ }
19
+
20
+ private get url() {
21
+ return `${this.baseUrl}/${this.subUrl}`
22
+ }
23
+
24
+ async generateText(data: BaseChatModelInput) {
25
+ const processedData = this.processInput(data)
26
+ const res = (await this.req({
27
+ url: this.url,
28
+ headers: {
29
+ 'X-Tc-Action': 'ChatCompletions',
30
+ },
31
+ data: {
32
+ ...processedData,
33
+ Stream: false,
34
+ },
35
+ stream: false,
36
+ })) as HunYaunGenerateTextOutput
37
+ return {
38
+ text: (res?.choices?.[0]?.message?.content as string) ?? '',
39
+ rawResponse: res,
40
+ }
41
+ }
42
+
43
+ async streamText(data: BaseChatModelInput) {
44
+ const processedData = this.processInput(data)
45
+ const stream = await this.req({
46
+ url: this.url,
47
+ headers: {
48
+ 'X-Tc-Action': 'ChatCompletions',
49
+ },
50
+ data: {
51
+ ...processedData,
52
+ Stream: true,
53
+ },
54
+ stream: true,
55
+ })
56
+ return new HunyuanModelStreamResult(stream)
57
+ }
58
+
59
+ private processInput({ messages, model, temperature, top_p, ...rest }: BaseChatModelInput): HunYuanInputData {
60
+ return {
61
+ Messages: messages.map(({ content, role }) => ({ Content: content, Role: role })),
62
+ Model: model as any,
63
+ Temperature: temperature,
64
+ TopP: top_p,
65
+ ...rest,
66
+ }
67
+ }
68
+ }
69
+
70
+ class HunyuanModelStreamResult implements StreamTextResult {
71
+ private _eventSourceStream: ReadableStream<ParsedEvent>
72
+
73
+ constructor(_stream: ReadableStream<Uint8Array>) {
74
+ const stream = toPolyfillReadable(_stream) as typeof _stream
75
+ this._eventSourceStream = stream
76
+ .pipeThrough(new TextDecoderStream())
77
+ .pipeThrough(createEventSourceParserTransformStream())
78
+ }
79
+
80
+ private get teeedStream() {
81
+ const [s1, s2] = this._eventSourceStream.tee()
82
+ this._eventSourceStream = s2
83
+ return s1
84
+ }
85
+
86
+ get eventSourceStream() {
87
+ return createAsyncIterable(this.teeedStream)
88
+ }
89
+
90
+ get dataStream() {
91
+ return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, HunYaunStreamTextOutput>({
92
+ transform(chunk, controller) {
93
+ try {
94
+ const data = JSON.parse(chunk.data) as HunYaunStreamTextOutput
95
+ controller.enqueue(data)
96
+ } catch (e) {
97
+ console.warn('Error when transforming event source data to json', e)
98
+ }
99
+ },
100
+ }),),)
101
+ }
102
+
103
+ get textStream() {
104
+ return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<HunYaunStreamTextOutput, string>({
105
+ transform(chunk, controller) {
106
+ controller.enqueue(chunk?.choices?.[0]?.delta?.content ?? '')
107
+ },
108
+ }),),)
109
+ }
110
+ }
@@ -0,0 +1,61 @@
1
+ type HunYuanMessage = {
2
+ Role: 'user' | 'system' | 'assistant' | 'tool'
3
+ Content?: string
4
+ Contents?: Array<{
5
+ Type: 'text' | 'image_url'
6
+ Text?: string
7
+ ImageUrl?: string
8
+ }>
9
+ ToolCallId?: string
10
+ ToolCalls?: Array<{
11
+ Id: string
12
+ Type: 'function'
13
+ Function: {
14
+ Name: string
15
+ Arguments: string
16
+ }
17
+ }>
18
+ }
19
+
20
+ type HunYuanTool = {
21
+ Type: 'function'
22
+ Function: {
23
+ Name: string
24
+ Arguments: string
25
+ }
26
+ }
27
+
28
+ export type HunYuanInputData = {
29
+ Model:
30
+ | 'hunyuan-lite'
31
+ | 'hunyuan-standard'
32
+ | 'hunyuan-standard-256K'
33
+ | 'hunyuan-pro'
34
+ | 'hunyuan-code'
35
+ | 'hunyuan-role'
36
+ | 'hunyuan-functioncall'
37
+ | 'hunyuan-vision'
38
+ Messages: Array<HunYuanMessage>
39
+ StreamModeration?: boolean
40
+ TopP?: number
41
+ Temperature?: number
42
+ EnableEnhancement?: boolean
43
+ Tools?: Array<HunYuanTool>
44
+ ToolChoice?: 'none' | 'auto' | 'custom'
45
+ CustomTool?: HunYuanTool
46
+ SearchInfo?: boolean
47
+ }
48
+
49
+ // todo: more precise
50
+ export type HunYaunGenerateTextOutput = {
51
+ choices?: Array<{
52
+ message?: { content?: string }
53
+ }>
54
+ }
55
+
56
+ // todo: more precise
57
+ export type HunYaunStreamTextOutput = {
58
+ choices?: Array<{
59
+ delta?: { content?: string }
60
+ }>
61
+ }
@@ -0,0 +1,110 @@
1
+ import { type ParsedEvent } from 'eventsource-parser/stream'
2
+ import {
3
+ createAsyncIterable,
4
+ TransformStream,
5
+ TextDecoderStream,
6
+ createEventSourceParserTransformStream,
7
+ toPolyfillReadable,
8
+ } from '../../utils'
9
+ import type { HunYuanInputData, HunYaunGenerateTextOutput, HunYaunStreamTextOutput } from './type'
10
+ import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
11
+
12
+ export class HunYuanPreviewModel implements ChatModel {
13
+ public subUrl = 'tencent_default/openapi/v1/chat/completions'
14
+ constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
15
+ if (subUrl != null) {
16
+ this.subUrl = subUrl
17
+ }
18
+ }
19
+
20
+ private get url() {
21
+ return `${this.baseUrl}/${this.subUrl}`
22
+ }
23
+
24
+ async generateText(data: BaseChatModelInput) {
25
+ const processedData = this.processInput(data)
26
+ const res = (await this.req({
27
+ url: this.url,
28
+ headers: {
29
+ 'X-Tc-Action': 'ChatCompletions',
30
+ },
31
+ data: {
32
+ ...processedData,
33
+ Stream: false,
34
+ },
35
+ stream: false,
36
+ })) as HunYaunGenerateTextOutput
37
+ return {
38
+ text: (res?.choices?.[0]?.message?.content as string) ?? '',
39
+ rawResponse: res,
40
+ }
41
+ }
42
+
43
+ async streamText(data: BaseChatModelInput) {
44
+ const processedData = this.processInput(data)
45
+ const stream = await this.req({
46
+ url: this.url,
47
+ headers: {
48
+ 'X-Tc-Action': 'ChatCompletions',
49
+ },
50
+ data: {
51
+ ...processedData,
52
+ Stream: true,
53
+ },
54
+ stream: true,
55
+ })
56
+ return new HunyuanModelStreamResult(stream)
57
+ }
58
+
59
+ private processInput({ messages, model, temperature, top_p, ...rest }: BaseChatModelInput): HunYuanInputData {
60
+ return {
61
+ Messages: messages.map(({ content, role }) => ({ Content: content, Role: role })),
62
+ Model: model as any,
63
+ Temperature: temperature,
64
+ TopP: top_p,
65
+ ...rest,
66
+ }
67
+ }
68
+ }
69
+
70
+ class HunyuanModelStreamResult implements StreamTextResult {
71
+ private _eventSourceStream: ReadableStream<ParsedEvent>
72
+
73
+ constructor(_stream: ReadableStream<Uint8Array>) {
74
+ const stream = toPolyfillReadable(_stream) as typeof _stream
75
+ this._eventSourceStream = stream
76
+ .pipeThrough(new TextDecoderStream())
77
+ .pipeThrough(createEventSourceParserTransformStream())
78
+ }
79
+
80
+ private get teeedStream() {
81
+ const [s1, s2] = this._eventSourceStream.tee()
82
+ this._eventSourceStream = s2
83
+ return s1
84
+ }
85
+
86
+ get eventSourceStream() {
87
+ return createAsyncIterable(this.teeedStream)
88
+ }
89
+
90
+ get dataStream() {
91
+ return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, HunYaunStreamTextOutput>({
92
+ transform(chunk, controller) {
93
+ try {
94
+ const data = JSON.parse(chunk.data) as HunYaunStreamTextOutput
95
+ controller.enqueue(data)
96
+ } catch (e) {
97
+ console.warn('Error when transforming event source data to json', e)
98
+ }
99
+ },
100
+ }),),)
101
+ }
102
+
103
+ get textStream() {
104
+ return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<HunYaunStreamTextOutput, string>({
105
+ transform(chunk, controller) {
106
+ controller.enqueue(chunk?.choices?.[0]?.delta?.content ?? '')
107
+ },
108
+ }),),)
109
+ }
110
+ }
@@ -0,0 +1,61 @@
1
+ type HunYuanMessage = {
2
+ Role: 'user' | 'system' | 'assistant' | 'tool'
3
+ Content?: string
4
+ Contents?: Array<{
5
+ Type: 'text' | 'image_url'
6
+ Text?: string
7
+ ImageUrl?: string
8
+ }>
9
+ ToolCallId?: string
10
+ ToolCalls?: Array<{
11
+ Id: string
12
+ Type: 'function'
13
+ Function: {
14
+ Name: string
15
+ Arguments: string
16
+ }
17
+ }>
18
+ }
19
+
20
+ type HunYuanTool = {
21
+ Type: 'function'
22
+ Function: {
23
+ Name: string
24
+ Arguments: string
25
+ }
26
+ }
27
+
28
+ export type HunYuanInputData = {
29
+ Model:
30
+ | 'hunyuan-lite'
31
+ | 'hunyuan-standard'
32
+ | 'hunyuan-standard-256K'
33
+ | 'hunyuan-pro'
34
+ | 'hunyuan-code'
35
+ | 'hunyuan-role'
36
+ | 'hunyuan-functioncall'
37
+ | 'hunyuan-vision'
38
+ Messages: Array<HunYuanMessage>
39
+ StreamModeration?: boolean
40
+ TopP?: number
41
+ Temperature?: number
42
+ EnableEnhancement?: boolean
43
+ Tools?: Array<HunYuanTool>
44
+ ToolChoice?: 'none' | 'auto' | 'custom'
45
+ CustomTool?: HunYuanTool
46
+ SearchInfo?: boolean
47
+ }
48
+
49
+ // todo: more precise
50
+ export type HunYaunGenerateTextOutput = {
51
+ choices?: Array<{
52
+ message?: { content?: string }
53
+ }>
54
+ }
55
+
56
+ // todo: more precise
57
+ export type HunYaunStreamTextOutput = {
58
+ choices?: Array<{
59
+ delta?: { content?: string }
60
+ }>
61
+ }