@cloudbase/ai 2.7.5-beta.0 → 2.7.7-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.
- package/dist/cjs/index.d.ts +19 -19
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/models/{YueZhi → Ark}/index.d.ts +8 -8
- package/dist/cjs/models/Ark/index.js +163 -0
- package/dist/{esm/models/HuoShan → cjs/models/Ark}/type.d.ts +5 -5
- package/dist/cjs/models/Ark/type.js +3 -0
- package/dist/{esm/models/HuoShan → cjs/models/DashScope}/index.d.ts +8 -8
- package/dist/cjs/models/DashScope/index.js +163 -0
- package/dist/cjs/models/{LingJi → DashScope}/type.d.ts +5 -5
- package/dist/cjs/models/DashScope/type.js +3 -0
- package/dist/cjs/models/HunYuan/index.d.ts +1 -1
- package/dist/cjs/models/HunYuan/index.js +2 -2
- package/dist/cjs/models/{HunYuanPreview → HunYuanBeta}/index.d.ts +2 -2
- package/dist/cjs/models/HunYuanBeta/index.js +191 -0
- package/dist/cjs/models/HunYuanBeta/type.js +3 -0
- package/dist/cjs/models/{HuoShan → Moonshot}/index.d.ts +8 -8
- package/dist/cjs/models/{HuoShan → Moonshot}/index.js +19 -19
- package/dist/cjs/models/{YueZhi → Moonshot}/type.d.ts +5 -5
- package/dist/cjs/models/Moonshot/type.js +3 -0
- package/dist/{esm/models/LingYi → cjs/models/Yi}/index.d.ts +7 -7
- package/dist/cjs/models/Yi/index.js +163 -0
- package/dist/cjs/models/{LingYi → Yi}/type.d.ts +5 -5
- package/dist/cjs/models/Yi/type.js +3 -0
- package/dist/cjs/models/ZhiPu/index.d.ts +1 -1
- package/dist/cjs/models/ZhiPu/index.js +1 -1
- package/dist/cjs/models/index.d.ts +13 -13
- package/dist/cjs/models/index.js +19 -19
- package/dist/cjs/type.d.ts +1 -1
- package/dist/cjs/type.js +1 -1
- package/dist/esm/index.d.ts +19 -19
- package/dist/esm/index.js +2 -2
- package/dist/esm/models/{LingJi → Ark}/index.d.ts +8 -8
- package/dist/esm/models/Ark/index.js +160 -0
- package/dist/{cjs/models/HuoShan → esm/models/Ark}/type.d.ts +5 -5
- package/dist/esm/models/Ark/type.js +2 -0
- package/dist/esm/models/DashScope/index.d.ts +24 -0
- package/dist/esm/models/DashScope/index.js +160 -0
- package/dist/esm/models/{LingJi → DashScope}/type.d.ts +5 -5
- package/dist/esm/models/DashScope/type.js +2 -0
- package/dist/esm/models/HunYuan/index.d.ts +1 -1
- package/dist/esm/models/HunYuan/index.js +2 -2
- package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/index.d.ts +2 -2
- package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/index.js +10 -10
- package/dist/esm/models/HunYuanBeta/type.js +2 -0
- package/dist/{cjs/models/LingJi → esm/models/Moonshot}/index.d.ts +8 -8
- package/dist/esm/models/{HuoShan → Moonshot}/index.js +18 -18
- package/dist/esm/models/{YueZhi → Moonshot}/type.d.ts +5 -5
- package/dist/esm/models/Moonshot/type.js +2 -0
- package/dist/{cjs/models/LingYi → esm/models/Yi}/index.d.ts +7 -7
- package/dist/esm/models/Yi/index.js +160 -0
- package/dist/esm/models/{LingYi → Yi}/type.d.ts +5 -5
- package/dist/esm/models/Yi/type.js +2 -0
- package/dist/esm/models/ZhiPu/index.d.ts +1 -1
- package/dist/esm/models/ZhiPu/index.js +1 -1
- package/dist/esm/models/index.d.ts +13 -13
- package/dist/esm/models/index.js +14 -14
- package/dist/esm/type.d.ts +1 -1
- package/dist/esm/type.js +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/models/{HuoShan → Ark}/index.ts +12 -12
- package/src/models/{HuoShan → Ark}/type.ts +5 -5
- package/src/models/{LingJi → DashScope}/index.ts +12 -12
- package/src/models/{LingJi → DashScope}/type.ts +5 -5
- package/src/models/HunYuan/index.ts +2 -2
- package/src/models/{HunYuanPreview → HunYuanBeta}/index.ts +3 -3
- package/src/models/{YueZhi → Moonshot}/index.ts +12 -12
- package/src/models/{YueZhi → Moonshot}/type.ts +5 -5
- package/src/models/{LingYi → Yi}/index.ts +10 -10
- package/src/models/{LingYi → Yi}/type.ts +5 -5
- package/src/models/ZhiPu/index.ts +1 -1
- package/src/models/index.ts +13 -13
- package/src/type.ts +1 -1
- package/dist/cjs/models/HunYuanPreview/index.js +0 -191
- package/dist/cjs/models/HunYuanPreview/type.js +0 -3
- package/dist/cjs/models/HuoShan/type.js +0 -3
- package/dist/cjs/models/LingJi/index.js +0 -163
- package/dist/cjs/models/LingJi/type.js +0 -3
- package/dist/cjs/models/LingYi/index.js +0 -163
- package/dist/cjs/models/LingYi/type.js +0 -3
- package/dist/cjs/models/YueZhi/index.js +0 -163
- package/dist/cjs/models/YueZhi/type.js +0 -3
- package/dist/esm/models/HunYuanPreview/type.js +0 -2
- package/dist/esm/models/HuoShan/type.js +0 -2
- package/dist/esm/models/LingJi/index.js +0 -160
- package/dist/esm/models/LingJi/type.js +0 -2
- package/dist/esm/models/LingYi/index.js +0 -160
- package/dist/esm/models/LingYi/type.js +0 -2
- package/dist/esm/models/YueZhi/index.d.ts +0 -24
- package/dist/esm/models/YueZhi/index.js +0 -160
- package/dist/esm/models/YueZhi/type.js +0 -2
- /package/dist/cjs/models/{HunYuanPreview → HunYuanBeta}/type.d.ts +0 -0
- /package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/type.d.ts +0 -0
- /package/src/models/{HunYuanPreview → HunYuanBeta}/type.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
createEventSourceParserTransformStream,
|
|
7
7
|
toPolyfillReadable,
|
|
8
8
|
} from '../../utils'
|
|
9
|
-
import type {
|
|
9
|
+
import type { ArkInputData, ArkGenerateTextOutput, ArkStreamTextOutput } from './type'
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
public subUrl = '
|
|
12
|
+
export class ArkModel implements ChatModel {
|
|
13
|
+
public subUrl = 'ark/api/v3/chat/completions'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -21,7 +21,7 @@ export class HuoShanModel implements ChatModel {
|
|
|
21
21
|
return `${this.baseUrl}/${this.subUrl}`
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async generateText(data:
|
|
24
|
+
async generateText(data: ArkInputData) {
|
|
25
25
|
const res = (await this.req({
|
|
26
26
|
url: this.url,
|
|
27
27
|
data: {
|
|
@@ -29,14 +29,14 @@ export class HuoShanModel implements ChatModel {
|
|
|
29
29
|
stream: false,
|
|
30
30
|
},
|
|
31
31
|
stream: false,
|
|
32
|
-
})) as
|
|
32
|
+
})) as ArkGenerateTextOutput
|
|
33
33
|
return {
|
|
34
34
|
text: (res?.choices?.[0]?.message?.content as string) ?? '',
|
|
35
35
|
rawResponse: res,
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async streamText(data:
|
|
39
|
+
async streamText(data: ArkInputData) {
|
|
40
40
|
const stream = await this.req({
|
|
41
41
|
url: this.url,
|
|
42
42
|
data: {
|
|
@@ -45,11 +45,11 @@ export class HuoShanModel implements ChatModel {
|
|
|
45
45
|
},
|
|
46
46
|
stream: true,
|
|
47
47
|
})
|
|
48
|
-
return new
|
|
48
|
+
return new ArkModelStreamResult(stream)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
class
|
|
52
|
+
class ArkModelStreamResult implements StreamTextResult {
|
|
53
53
|
private _eventSourceStream: ReadableStream<ParsedEvent>
|
|
54
54
|
|
|
55
55
|
constructor(_stream: ReadableStream<Uint8Array>) {
|
|
@@ -70,10 +70,10 @@ class HuoShanModelStreamResult implements StreamTextResult {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
get dataStream() {
|
|
73
|
-
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent,
|
|
73
|
+
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, ArkStreamTextOutput>({
|
|
74
74
|
transform(chunk, controller) {
|
|
75
75
|
try {
|
|
76
|
-
const data = JSON.parse(chunk.data) as
|
|
76
|
+
const data = JSON.parse(chunk.data) as ArkStreamTextOutput
|
|
77
77
|
controller.enqueue(data)
|
|
78
78
|
} catch (e) {
|
|
79
79
|
console.warn('Error when transforming event source data to json', e)
|
|
@@ -83,7 +83,7 @@ class HuoShanModelStreamResult implements StreamTextResult {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
get textStream() {
|
|
86
|
-
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<
|
|
86
|
+
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<ArkStreamTextOutput, string>({
|
|
87
87
|
transform(chunk, controller) {
|
|
88
88
|
controller.enqueue(chunk?.choices?.[0]?.message?.content ?? '')
|
|
89
89
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
type ArkMessage = {
|
|
2
2
|
role: 'user' | 'system' | 'assistant'
|
|
3
3
|
content:
|
|
4
4
|
| string
|
|
@@ -13,9 +13,9 @@ type HuoShanMessage = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// 文档描述模糊,暂只提供基础定义
|
|
16
|
-
export type
|
|
16
|
+
export type ArkInputData = {
|
|
17
17
|
model: string
|
|
18
|
-
messages: Array<
|
|
18
|
+
messages: Array<ArkMessage>
|
|
19
19
|
max_tokens?: number
|
|
20
20
|
stop?: string | Array<string>
|
|
21
21
|
frequency_penalty?: number
|
|
@@ -27,14 +27,14 @@ export type HuoShanInputData = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// todo: more precise
|
|
30
|
-
export type
|
|
30
|
+
export type ArkGenerateTextOutput = {
|
|
31
31
|
choices?: Array<{
|
|
32
32
|
message?: { content?: string }
|
|
33
33
|
}>
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// todo: more precise
|
|
37
|
-
export type
|
|
37
|
+
export type ArkStreamTextOutput = {
|
|
38
38
|
choices?: Array<{
|
|
39
39
|
message?: { content?: string }
|
|
40
40
|
}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
createEventSourceParserTransformStream,
|
|
7
7
|
toPolyfillReadable,
|
|
8
8
|
} from '../../utils'
|
|
9
|
-
import type {
|
|
9
|
+
import type { DashScopeInputData, DashScopeGenerateTextOutput, DashScopeStreamTextOutput } from './type'
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
public subUrl = '
|
|
12
|
+
export class DashScopeModel implements ChatModel {
|
|
13
|
+
public subUrl = 'dashscope/compatible-mode/v1/chat/completions'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -21,7 +21,7 @@ export class LingJiModel implements ChatModel {
|
|
|
21
21
|
return `${this.baseUrl}/${this.subUrl}`
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async generateText(data:
|
|
24
|
+
async generateText(data: DashScopeInputData) {
|
|
25
25
|
const res = (await this.req({
|
|
26
26
|
url: this.url,
|
|
27
27
|
data: {
|
|
@@ -29,14 +29,14 @@ export class LingJiModel implements ChatModel {
|
|
|
29
29
|
stream: false,
|
|
30
30
|
},
|
|
31
31
|
stream: false,
|
|
32
|
-
})) as
|
|
32
|
+
})) as DashScopeGenerateTextOutput
|
|
33
33
|
return {
|
|
34
34
|
text: (res?.choices?.[0]?.message?.content as string) ?? '',
|
|
35
35
|
rawResponse: res,
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async streamText(data:
|
|
39
|
+
async streamText(data: DashScopeInputData) {
|
|
40
40
|
const stream = await this.req({
|
|
41
41
|
url: this.url,
|
|
42
42
|
data: {
|
|
@@ -45,11 +45,11 @@ export class LingJiModel implements ChatModel {
|
|
|
45
45
|
},
|
|
46
46
|
stream: true,
|
|
47
47
|
})
|
|
48
|
-
return new
|
|
48
|
+
return new DashScopeModelStreamResult(stream)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
class
|
|
52
|
+
class DashScopeModelStreamResult implements StreamTextResult {
|
|
53
53
|
private _eventSourceStream: ReadableStream<ParsedEvent>
|
|
54
54
|
|
|
55
55
|
constructor(_stream: ReadableStream<Uint8Array>) {
|
|
@@ -70,10 +70,10 @@ class LingJiModelStreamResult implements StreamTextResult {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
get dataStream() {
|
|
73
|
-
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent,
|
|
73
|
+
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, DashScopeStreamTextOutput>({
|
|
74
74
|
transform(chunk, controller) {
|
|
75
75
|
try {
|
|
76
|
-
const data = JSON.parse(chunk.data) as
|
|
76
|
+
const data = JSON.parse(chunk.data) as DashScopeStreamTextOutput
|
|
77
77
|
controller.enqueue(data)
|
|
78
78
|
} catch (e) {
|
|
79
79
|
console.warn('Error when transforming event source data to json', e)
|
|
@@ -83,7 +83,7 @@ class LingJiModelStreamResult implements StreamTextResult {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
get textStream() {
|
|
86
|
-
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<
|
|
86
|
+
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<DashScopeStreamTextOutput, string>({
|
|
87
87
|
transform(chunk, controller) {
|
|
88
88
|
controller.enqueue(chunk?.choices?.[0]?.delta?.content ?? '')
|
|
89
89
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type
|
|
1
|
+
type DashScopeMessage = { role: 'user' | 'system' | 'assistant'; content: string }
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type DashScopeInputData = {
|
|
4
4
|
model: string
|
|
5
|
-
messages: Array<
|
|
5
|
+
messages: Array<DashScopeMessage>
|
|
6
6
|
temperature?: number
|
|
7
7
|
top_p?: number
|
|
8
8
|
presence_penalty?: number
|
|
@@ -20,14 +20,14 @@ export type LingJiInputData = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// todo: more precise
|
|
23
|
-
export type
|
|
23
|
+
export type DashScopeGenerateTextOutput = {
|
|
24
24
|
choices?: Array<{
|
|
25
25
|
message?: { content?: string }
|
|
26
26
|
}>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// todo: more precise
|
|
30
|
-
export type
|
|
30
|
+
export type DashScopeStreamTextOutput = {
|
|
31
31
|
choices?: Array<{
|
|
32
32
|
delta?: { content?: string }
|
|
33
33
|
}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -10,7 +10,7 @@ import type { HunYuanInputData, HunYaunGenerateTextOutput, HunYaunStreamTextOutp
|
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
|
|
11
11
|
|
|
12
12
|
export class HunYuanModel implements ChatModel {
|
|
13
|
-
public subUrl = '
|
|
13
|
+
public subUrl = 'hunyuan'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
import type { HunYuanInputData, HunYaunGenerateTextOutput, HunYaunStreamTextOutput } from './type'
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
public subUrl = '
|
|
12
|
+
export class HunYuanBetaModel implements ChatModel {
|
|
13
|
+
public subUrl = 'hunyuan-beta/openapi/v1/chat/completions'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
createEventSourceParserTransformStream,
|
|
7
7
|
toPolyfillReadable,
|
|
8
8
|
} from '../../utils'
|
|
9
|
-
import type {
|
|
9
|
+
import type { MoonshotInputData, MoonshotGenerateTextOutput, MoonshotStreamTextOutput } from './type'
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
public subUrl = '
|
|
12
|
+
export class MoonshotModel implements ChatModel {
|
|
13
|
+
public subUrl = 'moonshot/v1/chat/completions'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -21,7 +21,7 @@ export class YueZhiModel implements ChatModel {
|
|
|
21
21
|
return `${this.baseUrl}/${this.subUrl}`
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async generateText(data:
|
|
24
|
+
async generateText(data: MoonshotInputData) {
|
|
25
25
|
const res = (await this.req({
|
|
26
26
|
url: this.url,
|
|
27
27
|
data: {
|
|
@@ -29,14 +29,14 @@ export class YueZhiModel implements ChatModel {
|
|
|
29
29
|
stream: false,
|
|
30
30
|
},
|
|
31
31
|
stream: false,
|
|
32
|
-
})) as
|
|
32
|
+
})) as MoonshotGenerateTextOutput
|
|
33
33
|
return {
|
|
34
34
|
text: (res?.choices?.[0]?.message?.content as string) ?? '',
|
|
35
35
|
rawResponse: res,
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async streamText(data:
|
|
39
|
+
async streamText(data: MoonshotInputData) {
|
|
40
40
|
const stream = await this.req({
|
|
41
41
|
url: this.url,
|
|
42
42
|
data: {
|
|
@@ -45,11 +45,11 @@ export class YueZhiModel implements ChatModel {
|
|
|
45
45
|
},
|
|
46
46
|
stream: true,
|
|
47
47
|
})
|
|
48
|
-
return new
|
|
48
|
+
return new MoonshotModelStreamResult(stream)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
class
|
|
52
|
+
class MoonshotModelStreamResult implements StreamTextResult {
|
|
53
53
|
private _eventSourceStream: ReadableStream<ParsedEvent>
|
|
54
54
|
|
|
55
55
|
constructor(_stream: ReadableStream<Uint8Array>) {
|
|
@@ -70,10 +70,10 @@ class YueZhiModelStreamResult implements StreamTextResult {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
get dataStream() {
|
|
73
|
-
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent,
|
|
73
|
+
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, MoonshotStreamTextOutput>({
|
|
74
74
|
transform(chunk, controller) {
|
|
75
75
|
try {
|
|
76
|
-
const data = JSON.parse(chunk.data) as
|
|
76
|
+
const data = JSON.parse(chunk.data) as MoonshotStreamTextOutput
|
|
77
77
|
controller.enqueue(data)
|
|
78
78
|
} catch (e) {
|
|
79
79
|
console.warn('Error when transforming event source data to json', e)
|
|
@@ -83,7 +83,7 @@ class YueZhiModelStreamResult implements StreamTextResult {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
get textStream() {
|
|
86
|
-
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<
|
|
86
|
+
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<MoonshotStreamTextOutput, string>({
|
|
87
87
|
transform(chunk, controller) {
|
|
88
88
|
controller.enqueue(chunk?.choices?.[0]?.delta?.content ?? '')
|
|
89
89
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
type
|
|
1
|
+
type MoonshotMessage = { role: 'user' | 'system' | 'assistant'; content: string }
|
|
2
2
|
|
|
3
|
-
export type
|
|
4
|
-
messages: Array<
|
|
3
|
+
export type MoonshotInputData = {
|
|
4
|
+
messages: Array<MoonshotMessage>
|
|
5
5
|
model: 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k'
|
|
6
6
|
max_tokens?: number
|
|
7
7
|
temperature?: number
|
|
@@ -14,14 +14,14 @@ export type YueZhiInputData = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// todo: more precise
|
|
17
|
-
export type
|
|
17
|
+
export type MoonshotGenerateTextOutput = {
|
|
18
18
|
choices?: Array<{
|
|
19
19
|
message?: { content?: string }
|
|
20
20
|
}>
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// todo: more precise
|
|
24
|
-
export type
|
|
24
|
+
export type MoonshotStreamTextOutput = {
|
|
25
25
|
choices?: Array<{
|
|
26
26
|
delta?: { content?: string }
|
|
27
27
|
}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ParsedEvent } from 'eventsource-parser
|
|
1
|
+
import { type ParsedEvent } from 'eventsource-parser'
|
|
2
2
|
import {
|
|
3
3
|
createAsyncIterable,
|
|
4
4
|
TransformStream,
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
createEventSourceParserTransformStream,
|
|
7
7
|
toPolyfillReadable,
|
|
8
8
|
} from '../../utils'
|
|
9
|
-
import type {
|
|
9
|
+
import type { YiGenerateTextOutput, YiStreamTextOutput } from './type'
|
|
10
10
|
import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
|
|
11
11
|
|
|
12
|
-
export class
|
|
13
|
-
public subUrl = '
|
|
12
|
+
export class YiModel implements ChatModel {
|
|
13
|
+
public subUrl = '01-ai/v1/chat/completions'
|
|
14
14
|
constructor(private req: ModelReq, public baseUrl: string, subUrl?: string) {
|
|
15
15
|
if (subUrl != null) {
|
|
16
16
|
this.subUrl = subUrl
|
|
@@ -29,7 +29,7 @@ export class LingYiModel implements ChatModel {
|
|
|
29
29
|
stream: false,
|
|
30
30
|
},
|
|
31
31
|
stream: false,
|
|
32
|
-
})) as
|
|
32
|
+
})) as YiGenerateTextOutput
|
|
33
33
|
return {
|
|
34
34
|
text: (res?.choices?.[0]?.message?.content as string) ?? '',
|
|
35
35
|
rawResponse: res,
|
|
@@ -45,11 +45,11 @@ export class LingYiModel implements ChatModel {
|
|
|
45
45
|
},
|
|
46
46
|
stream: true,
|
|
47
47
|
})
|
|
48
|
-
return new
|
|
48
|
+
return new YiModelStreamResult(stream)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
class
|
|
52
|
+
class YiModelStreamResult implements StreamTextResult {
|
|
53
53
|
private _eventSourceStream: ReadableStream<ParsedEvent>
|
|
54
54
|
|
|
55
55
|
constructor(_stream: ReadableStream<Uint8Array>) {
|
|
@@ -70,10 +70,10 @@ class LingYiModelStreamResult implements StreamTextResult {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
get dataStream() {
|
|
73
|
-
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent,
|
|
73
|
+
return createAsyncIterable(this.eventSourceStream.pipeThrough(new TransformStream<ParsedEvent, YiStreamTextOutput>({
|
|
74
74
|
transform(chunk, controller) {
|
|
75
75
|
try {
|
|
76
|
-
const data = JSON.parse(chunk.data) as
|
|
76
|
+
const data = JSON.parse(chunk.data) as YiStreamTextOutput
|
|
77
77
|
controller.enqueue(data)
|
|
78
78
|
} catch (e) {
|
|
79
79
|
console.warn('Error when transforming event source data to json', e)
|
|
@@ -83,7 +83,7 @@ class LingYiModelStreamResult implements StreamTextResult {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
get textStream() {
|
|
86
|
-
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<
|
|
86
|
+
return createAsyncIterable(this.dataStream.pipeThrough(new TransformStream<YiStreamTextOutput, string>({
|
|
87
87
|
transform(chunk, controller) {
|
|
88
88
|
controller.enqueue(chunk?.choices?.[0]?.delta?.content ?? '')
|
|
89
89
|
},
|
|
@@ -19,11 +19,11 @@ type ToolMessage = {
|
|
|
19
19
|
tool_call_id: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
type
|
|
22
|
+
type YiMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type YiInputData = {
|
|
25
25
|
model: string
|
|
26
|
-
messages: Array<
|
|
26
|
+
messages: Array<YiMessage>
|
|
27
27
|
tools?: Array<{
|
|
28
28
|
type: 'function'
|
|
29
29
|
function: { name: string; description?: string; parameters: object }
|
|
@@ -35,14 +35,14 @@ export type LingYiInputData = {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// todo: more precise
|
|
38
|
-
export type
|
|
38
|
+
export type YiGenerateTextOutput = {
|
|
39
39
|
choices?: Array<{
|
|
40
40
|
message?: { content?: string }
|
|
41
41
|
}>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// todo: more precise
|
|
45
|
-
export type
|
|
45
|
+
export type YiStreamTextOutput = {
|
|
46
46
|
choices?: Array<{
|
|
47
47
|
delta?: { content?: string }
|
|
48
48
|
}>
|
package/src/models/index.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { HunYuanModel } from './HunYuan'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { ArkModel } from './Ark'
|
|
3
|
+
import { DashScopeModel } from './DashScope'
|
|
4
|
+
import { YiModel } from './Yi'
|
|
5
|
+
import { MoonshotModel } from './Moonshot'
|
|
6
6
|
import { ZhiPuModel } from './ZhiPu'
|
|
7
|
-
import {
|
|
7
|
+
import { HunYuanBetaModel } from './HunYuanBeta'
|
|
8
8
|
|
|
9
9
|
export const MODELS = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
hunyuan: HunYuanModel,
|
|
11
|
+
'hunyuan-beta': HunYuanBetaModel,
|
|
12
|
+
ark: ArkModel,
|
|
13
|
+
dashscope: DashScopeModel,
|
|
14
|
+
'01-ai': YiModel,
|
|
15
|
+
moonshot: MoonshotModel,
|
|
16
|
+
zhipu: ZhiPuModel,
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export { HunYuanModel,
|
|
19
|
+
export { HunYuanModel, HunYuanBetaModel, ArkModel, DashScopeModel, YiModel, MoonshotModel, ZhiPuModel }
|
package/src/type.ts
CHANGED