@botpress/zai 2.1.19 → 2.2.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/src/zai.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@botpress/client'
2
- import { BotpressClientLike, Cognitive, Model } from '@botpress/cognitive'
2
+ import { BotpressClientLike, Cognitive, Model, Models } from '@botpress/cognitive'
3
3
 
4
4
  import { type TextTokenizer, getWasmTokenizer } from '@bpinternal/thicktoken'
5
5
  import { z } from '@bpinternal/zui'
@@ -8,8 +8,6 @@ import { Adapter } from './adapters/adapter'
8
8
  import { TableAdapter } from './adapters/botpress-table'
9
9
  import { MemoryAdapter } from './adapters/memory'
10
10
 
11
- type ModelId = Required<Parameters<Cognitive['generateContent']>[0]['model']>
12
-
13
11
  type ActiveLearning = {
14
12
  enable: boolean
15
13
  tableName: string
@@ -39,7 +37,7 @@ const _ActiveLearning = z.object({
39
37
  type ZaiConfig = {
40
38
  client: BotpressClientLike | Cognitive
41
39
  userId?: string
42
- modelId?: ModelId | string
40
+ modelId?: Models
43
41
  activeLearning?: ActiveLearning
44
42
  namespace?: string
45
43
  }
@@ -48,7 +46,7 @@ const _ZaiConfig = z.object({
48
46
  client: z.custom<BotpressClientLike | Cognitive>(),
49
47
  userId: z.string().describe('The ID of the user consuming the API').optional(),
50
48
  modelId: z
51
- .custom<ModelId | string>(
49
+ .custom<Models>(
52
50
  (value) => {
53
51
  if (typeof value !== 'string') {
54
52
  return false
@@ -65,7 +63,7 @@ const _ZaiConfig = z.object({
65
63
  }
66
64
  )
67
65
  .describe('The ID of the model you want to use')
68
- .default('best' satisfies ModelId),
66
+ .default('best' satisfies Models),
69
67
  activeLearning: _ActiveLearning.default({ enable: false }),
70
68
  namespace: z
71
69
  .string()
@@ -84,7 +82,7 @@ export class Zai {
84
82
 
85
83
  private _userId: string | undefined
86
84
 
87
- protected Model: ModelId
85
+ protected Model: Models
88
86
  protected ModelDetails: Model
89
87
  protected namespace: string
90
88
  protected adapter: Adapter
@@ -100,7 +98,7 @@ export class Zai {
100
98
 
101
99
  this.namespace = parsed.namespace
102
100
  this._userId = parsed.userId
103
- this.Model = parsed.modelId as ModelId
101
+ this.Model = parsed.modelId as Models
104
102
  this.activeLearning = parsed.activeLearning as ActiveLearning
105
103
 
106
104
  this.adapter = parsed.activeLearning?.enable
@@ -117,7 +115,7 @@ export class Zai {
117
115
  ): ReturnType<Cognitive['generateContent']> {
118
116
  return this.client.generateContent({
119
117
  ...props,
120
- model: this.Model,
118
+ model: this.Model as Required<Parameters<Cognitive['generateContent']>[0]>['model'],
121
119
  userId: this._userId,
122
120
  })
123
121
  }