@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.
Files changed (94) hide show
  1. package/dist/cjs/index.d.ts +19 -19
  2. package/dist/cjs/index.js +2 -2
  3. package/dist/cjs/models/{YueZhi → Ark}/index.d.ts +8 -8
  4. package/dist/cjs/models/Ark/index.js +163 -0
  5. package/dist/{esm/models/HuoShan → cjs/models/Ark}/type.d.ts +5 -5
  6. package/dist/cjs/models/Ark/type.js +3 -0
  7. package/dist/{esm/models/HuoShan → cjs/models/DashScope}/index.d.ts +8 -8
  8. package/dist/cjs/models/DashScope/index.js +163 -0
  9. package/dist/cjs/models/{LingJi → DashScope}/type.d.ts +5 -5
  10. package/dist/cjs/models/DashScope/type.js +3 -0
  11. package/dist/cjs/models/HunYuan/index.d.ts +1 -1
  12. package/dist/cjs/models/HunYuan/index.js +2 -2
  13. package/dist/cjs/models/{HunYuanPreview → HunYuanBeta}/index.d.ts +2 -2
  14. package/dist/cjs/models/HunYuanBeta/index.js +191 -0
  15. package/dist/cjs/models/HunYuanBeta/type.js +3 -0
  16. package/dist/cjs/models/{HuoShan → Moonshot}/index.d.ts +8 -8
  17. package/dist/cjs/models/{HuoShan → Moonshot}/index.js +19 -19
  18. package/dist/cjs/models/{YueZhi → Moonshot}/type.d.ts +5 -5
  19. package/dist/cjs/models/Moonshot/type.js +3 -0
  20. package/dist/{esm/models/LingYi → cjs/models/Yi}/index.d.ts +7 -7
  21. package/dist/cjs/models/Yi/index.js +163 -0
  22. package/dist/cjs/models/{LingYi → Yi}/type.d.ts +5 -5
  23. package/dist/cjs/models/Yi/type.js +3 -0
  24. package/dist/cjs/models/ZhiPu/index.d.ts +1 -1
  25. package/dist/cjs/models/ZhiPu/index.js +1 -1
  26. package/dist/cjs/models/index.d.ts +13 -13
  27. package/dist/cjs/models/index.js +19 -19
  28. package/dist/cjs/type.d.ts +1 -1
  29. package/dist/cjs/type.js +1 -1
  30. package/dist/esm/index.d.ts +19 -19
  31. package/dist/esm/index.js +2 -2
  32. package/dist/esm/models/{LingJi → Ark}/index.d.ts +8 -8
  33. package/dist/esm/models/Ark/index.js +160 -0
  34. package/dist/{cjs/models/HuoShan → esm/models/Ark}/type.d.ts +5 -5
  35. package/dist/esm/models/Ark/type.js +2 -0
  36. package/dist/esm/models/DashScope/index.d.ts +24 -0
  37. package/dist/esm/models/DashScope/index.js +160 -0
  38. package/dist/esm/models/{LingJi → DashScope}/type.d.ts +5 -5
  39. package/dist/esm/models/DashScope/type.js +2 -0
  40. package/dist/esm/models/HunYuan/index.d.ts +1 -1
  41. package/dist/esm/models/HunYuan/index.js +2 -2
  42. package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/index.d.ts +2 -2
  43. package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/index.js +10 -10
  44. package/dist/esm/models/HunYuanBeta/type.js +2 -0
  45. package/dist/{cjs/models/LingJi → esm/models/Moonshot}/index.d.ts +8 -8
  46. package/dist/esm/models/{HuoShan → Moonshot}/index.js +18 -18
  47. package/dist/esm/models/{YueZhi → Moonshot}/type.d.ts +5 -5
  48. package/dist/esm/models/Moonshot/type.js +2 -0
  49. package/dist/{cjs/models/LingYi → esm/models/Yi}/index.d.ts +7 -7
  50. package/dist/esm/models/Yi/index.js +160 -0
  51. package/dist/esm/models/{LingYi → Yi}/type.d.ts +5 -5
  52. package/dist/esm/models/Yi/type.js +2 -0
  53. package/dist/esm/models/ZhiPu/index.d.ts +1 -1
  54. package/dist/esm/models/ZhiPu/index.js +1 -1
  55. package/dist/esm/models/index.d.ts +13 -13
  56. package/dist/esm/models/index.js +14 -14
  57. package/dist/esm/type.d.ts +1 -1
  58. package/dist/esm/type.js +1 -1
  59. package/package.json +3 -3
  60. package/src/index.ts +1 -1
  61. package/src/models/{HuoShan → Ark}/index.ts +12 -12
  62. package/src/models/{HuoShan → Ark}/type.ts +5 -5
  63. package/src/models/{LingJi → DashScope}/index.ts +12 -12
  64. package/src/models/{LingJi → DashScope}/type.ts +5 -5
  65. package/src/models/HunYuan/index.ts +2 -2
  66. package/src/models/{HunYuanPreview → HunYuanBeta}/index.ts +3 -3
  67. package/src/models/{YueZhi → Moonshot}/index.ts +12 -12
  68. package/src/models/{YueZhi → Moonshot}/type.ts +5 -5
  69. package/src/models/{LingYi → Yi}/index.ts +10 -10
  70. package/src/models/{LingYi → Yi}/type.ts +5 -5
  71. package/src/models/ZhiPu/index.ts +1 -1
  72. package/src/models/index.ts +13 -13
  73. package/src/type.ts +1 -1
  74. package/dist/cjs/models/HunYuanPreview/index.js +0 -191
  75. package/dist/cjs/models/HunYuanPreview/type.js +0 -3
  76. package/dist/cjs/models/HuoShan/type.js +0 -3
  77. package/dist/cjs/models/LingJi/index.js +0 -163
  78. package/dist/cjs/models/LingJi/type.js +0 -3
  79. package/dist/cjs/models/LingYi/index.js +0 -163
  80. package/dist/cjs/models/LingYi/type.js +0 -3
  81. package/dist/cjs/models/YueZhi/index.js +0 -163
  82. package/dist/cjs/models/YueZhi/type.js +0 -3
  83. package/dist/esm/models/HunYuanPreview/type.js +0 -2
  84. package/dist/esm/models/HuoShan/type.js +0 -2
  85. package/dist/esm/models/LingJi/index.js +0 -160
  86. package/dist/esm/models/LingJi/type.js +0 -2
  87. package/dist/esm/models/LingYi/index.js +0 -160
  88. package/dist/esm/models/LingYi/type.js +0 -2
  89. package/dist/esm/models/YueZhi/index.d.ts +0 -24
  90. package/dist/esm/models/YueZhi/index.js +0 -160
  91. package/dist/esm/models/YueZhi/type.js +0 -2
  92. /package/dist/cjs/models/{HunYuanPreview → HunYuanBeta}/type.d.ts +0 -0
  93. /package/dist/esm/models/{HunYuanPreview → HunYuanBeta}/type.d.ts +0 -0
  94. /package/src/models/{HunYuanPreview → HunYuanBeta}/type.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { type ParsedEvent } from 'eventsource-parser/stream'
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 { HuoShanInputData, HuoShanGenerateTextOutput, HuoShanStreamTextOutput } from './type'
9
+ import type { ArkInputData, ArkGenerateTextOutput, ArkStreamTextOutput } from './type'
10
10
  import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
11
11
 
12
- export class HuoShanModel implements ChatModel {
13
- public subUrl = 'toutiao/api/v3/chat/completions'
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: HuoShanInputData) {
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 HuoShanGenerateTextOutput
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: HuoShanInputData) {
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 HuoShanModelStreamResult(stream)
48
+ return new ArkModelStreamResult(stream)
49
49
  }
50
50
  }
51
51
 
52
- class HuoShanModelStreamResult implements StreamTextResult {
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, HuoShanStreamTextOutput>({
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 HuoShanStreamTextOutput
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<HuoShanStreamTextOutput, string>({
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 HuoShanMessage = {
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 HuoShanInputData = {
16
+ export type ArkInputData = {
17
17
  model: string
18
- messages: Array<HuoShanMessage>
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 HuoShanGenerateTextOutput = {
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 HuoShanStreamTextOutput = {
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/stream'
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 { LingJiInputData, LingJiGenerateTextOutput, LingJiStreamTextOutput } from './type'
9
+ import type { DashScopeInputData, DashScopeGenerateTextOutput, DashScopeStreamTextOutput } from './type'
10
10
  import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
11
11
 
12
- export class LingJiModel implements ChatModel {
13
- public subUrl = 'ali/compatible-mode/v1/chat/completions'
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: LingJiInputData) {
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 LingJiGenerateTextOutput
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: LingJiInputData) {
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 LingJiModelStreamResult(stream)
48
+ return new DashScopeModelStreamResult(stream)
49
49
  }
50
50
  }
51
51
 
52
- class LingJiModelStreamResult implements StreamTextResult {
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, LingJiStreamTextOutput>({
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 LingJiStreamTextOutput
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<LingJiStreamTextOutput, string>({
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 LingJiMessage = { role: 'user' | 'system' | 'assistant'; content: string }
1
+ type DashScopeMessage = { role: 'user' | 'system' | 'assistant'; content: string }
2
2
 
3
- export type LingJiInputData = {
3
+ export type DashScopeInputData = {
4
4
  model: string
5
- messages: Array<LingJiMessage>
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 LingJiGenerateTextOutput = {
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 LingJiStreamTextOutput = {
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/stream'
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 = 'tencent_hunyuan/'
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/stream'
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 HunYuanPreviewModel implements ChatModel {
13
- public subUrl = 'tencent_default/openapi/v1/chat/completions'
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/stream'
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 { YueZhiInputData, YueZhiGenerateTextOutput, YueZhiStreamTextOutput } from './type'
9
+ import type { MoonshotInputData, MoonshotGenerateTextOutput, MoonshotStreamTextOutput } from './type'
10
10
  import type { ChatModel, StreamTextResult, ModelReq } from '../../type'
11
11
 
12
- export class YueZhiModel implements ChatModel {
13
- public subUrl = 'yuezhianmian/v1/chat/completions'
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: YueZhiInputData) {
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 YueZhiGenerateTextOutput
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: YueZhiInputData) {
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 YueZhiModelStreamResult(stream)
48
+ return new MoonshotModelStreamResult(stream)
49
49
  }
50
50
  }
51
51
 
52
- class YueZhiModelStreamResult implements StreamTextResult {
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, YueZhiStreamTextOutput>({
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 YueZhiStreamTextOutput
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<YueZhiStreamTextOutput, string>({
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 YueZhiMessage = { role: 'user' | 'system' | 'assistant'; content: string }
1
+ type MoonshotMessage = { role: 'user' | 'system' | 'assistant'; content: string }
2
2
 
3
- export type YueZhiInputData = {
4
- messages: Array<YueZhiMessage>
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 YueZhiGenerateTextOutput = {
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 YueZhiStreamTextOutput = {
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/stream'
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 { LingYiGenerateTextOutput, LingYiStreamTextOutput } from './type'
9
+ import type { YiGenerateTextOutput, YiStreamTextOutput } from './type'
10
10
  import type { ChatModel, StreamTextResult, ModelReq, BaseChatModelInput } from '../../type'
11
11
 
12
- export class LingYiModel implements ChatModel {
13
- public subUrl = 'lingyiwanwu/v1/chat/completion'
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 LingYiGenerateTextOutput
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 LingYiModelStreamResult(stream)
48
+ return new YiModelStreamResult(stream)
49
49
  }
50
50
  }
51
51
 
52
- class LingYiModelStreamResult implements StreamTextResult {
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, LingYiStreamTextOutput>({
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 LingYiStreamTextOutput
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<LingYiStreamTextOutput, string>({
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 LingYiMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage
22
+ type YiMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage
23
23
 
24
- export type LingYiInputData = {
24
+ export type YiInputData = {
25
25
  model: string
26
- messages: Array<LingYiMessage>
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 LingYiGenerateTextOutput = {
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 LingYiStreamTextOutput = {
45
+ export type YiStreamTextOutput = {
46
46
  choices?: Array<{
47
47
  delta?: { content?: string }
48
48
  }>
@@ -1,4 +1,4 @@
1
- import { type ParsedEvent } from 'eventsource-parser/stream'
1
+ import { type ParsedEvent } from 'eventsource-parser'
2
2
  import {
3
3
  createAsyncIterable,
4
4
  TransformStream,
@@ -1,19 +1,19 @@
1
1
  import { HunYuanModel } from './HunYuan'
2
- import { HuoShanModel } from './HuoShan'
3
- import { LingJiModel } from './LingJi'
4
- import { LingYiModel } from './LingYi'
5
- import { YueZhiModel } from './YueZhi'
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 { HunYuanPreviewModel } from './HunYuanPreview'
7
+ import { HunYuanBetaModel } from './HunYuanBeta'
8
8
 
9
9
  export const MODELS = {
10
- HunYuan: HunYuanModel,
11
- HunYuanPreview: HunYuanPreviewModel,
12
- HuoShan: HuoShanModel,
13
- LingJi: LingJiModel,
14
- LingYi: LingYiModel,
15
- YueZhi: YueZhiModel,
16
- ZhiPu: ZhiPuModel,
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, HunYuanPreviewModel, HuoShanModel, LingJiModel, LingYiModel, YueZhiModel, ZhiPuModel }
19
+ export { HunYuanModel, HunYuanBetaModel, ArkModel, DashScopeModel, YiModel, MoonshotModel, ZhiPuModel }
package/src/type.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ParsedEvent } from 'eventsource-parser/stream'
1
+ import { type ParsedEvent } from 'eventsource-parser'
2
2
 
3
3
  export abstract class ChatModel {
4
4
  public abstract generateText(data: BaseChatModelInput): Promise<{ text: string; rawResponse: any }>