@botpress/cognitive 0.1.45 → 0.1.46

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/refresh-models.ts CHANGED
@@ -3,14 +3,13 @@ import * as fs from 'fs'
3
3
  import * as path from 'path'
4
4
  import { Model } from 'src/schemas.gen'
5
5
 
6
- const builtInModels = ['auto', 'best', 'fast', 'reasoning', 'cheapest', 'balance']
6
+ const builtInModels = ['auto', 'best', 'fast']
7
7
  const filteredLifecycles = ['deprecated', 'discontinued']
8
- const filteredTags = ['deprecated']
9
8
 
10
9
  const modelsListPath = path.resolve(__dirname, 'src/cognitive-v2', 'models.ts')
11
10
  const typesPath = path.resolve(__dirname, 'src/cognitive-v2', 'types.ts')
12
11
 
13
- type RemoteModel = Model & { lifecycle?: string }
12
+ type RemoteModel = Model & { lifecycle?: string; aliases?: string[] }
14
13
 
15
14
  const toRef = (m: RemoteModel | string | null | undefined): string | null => {
16
15
  if (!m) return null
@@ -36,17 +35,6 @@ async function main(): Promise<void> {
36
35
  },
37
36
  })
38
37
 
39
- const uniqueTags = [
40
- ...new Set(
41
- models
42
- .map((m) => m.tags)
43
- .flat()
44
- .filter((t) => !filteredTags.includes(t))
45
- ),
46
- ]
47
-
48
- console.log(`Unique tags: ${uniqueTags.join(', ')}`)
49
-
50
38
  const modelsObj = models.reduce((acc, m) => ((acc[m.id] = m), acc), {} as Record<string, RemoteModel>)
51
39
 
52
40
  const defaultModel: RemoteModel = {
@@ -62,7 +50,6 @@ async function main(): Promise<void> {
62
50
  const newFile = `import { Model } from 'src/schemas.gen'\n
63
51
  export type RemoteModel = Model & { aliases?: string[]; lifecycle: 'live' | 'beta' | 'deprecated' | 'discontinued' }\n
64
52
  export const models: Record<string, RemoteModel> = ${JSON.stringify(modelsObj, null, 2)}\n
65
- export const knownTags = [${[...builtInModels, ...uniqueTags].map((t) => `'${t}'`).join(', ')}]\n
66
53
  export const defaultModel: RemoteModel = ${JSON.stringify(defaultModel, undefined, 2)}
67
54
  `
68
55
 
@@ -72,6 +59,12 @@ export const defaultModel: RemoteModel = ${JSON.stringify(defaultModel, undefine
72
59
 
73
60
  const withoutDeprecated = models.filter((m) => !filteredLifecycles.includes(m.lifecycle))
74
61
  const refs = Array.from(new Set(withoutDeprecated.map(toRef).filter(Boolean))).sort((a, b) => a.localeCompare(b))
62
+ const aliases = models.flatMap((m) =>
63
+ (m.aliases || []).map((a) => {
64
+ const [provider] = m.id.split(':')
65
+ return `${provider}:${a}`
66
+ })
67
+ )
75
68
 
76
69
  const content = fs.readFileSync(typesPath, 'utf8')
77
70
 
@@ -85,7 +78,7 @@ export const defaultModel: RemoteModel = ${JSON.stringify(defaultModel, undefine
85
78
  throw new Error('Could not locate Models union block in models.ts')
86
79
  }
87
80
 
88
- const items = [...builtInModels, ...uniqueTags, ...refs].map((r) => ` | '${r}'`)
81
+ const items = [...builtInModels, ...refs, ...aliases].map((r) => ` | '${r}'`)
89
82
  const unionBlock = ['type Models =', ...items, ' | ({} & string)', ''].join('\n')
90
83
 
91
84
  const nextContent = content.slice(0, startIdx) + unionBlock + content.slice(endIdx)