@botpress/cognitive 0.1.0 → 0.1.2
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/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-generate.log +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +14 -13
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +2 -2
- package/e2e/client.test.ts +126 -0
- package/e2e/client.ts +13 -0
- package/e2e/models.json +562 -0
- package/e2e/models.test.ts +131 -0
- package/package.json +4 -4
- package/tsconfig.build.json +9 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test } from 'vitest'
|
|
2
|
+
import { getBestModels, getFastModels, Model, ModelPreferences, pickModel, RemoteModelProvider } from '../src/models'
|
|
3
|
+
|
|
4
|
+
import MODELS from './models.json'
|
|
5
|
+
import { writeFileSync } from 'node:fs'
|
|
6
|
+
import { getTestClient } from './client'
|
|
7
|
+
|
|
8
|
+
describe('Models', () => {
|
|
9
|
+
test.skip('should fetch models', async () => {
|
|
10
|
+
// Run me manually if you need to re-generate the models.json file
|
|
11
|
+
// Make sure to setup the environment variables
|
|
12
|
+
const provider = new RemoteModelProvider(getTestClient())
|
|
13
|
+
const models = await provider.fetchInstalledModels()
|
|
14
|
+
writeFileSync('./models.json', JSON.stringify(models, null, 2))
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('Models ranking (best)', () => {
|
|
18
|
+
const best = getBestModels(MODELS as Model[])
|
|
19
|
+
expect(best.slice(0, 10).map((x) => x.ref)).toEqual([
|
|
20
|
+
'openai:gpt-4o-2024-11-20',
|
|
21
|
+
'openai:gpt-4o-2024-08-06',
|
|
22
|
+
'google-ai:models/gemini-1.5-pro-002',
|
|
23
|
+
'anthropic:claude-3-5-sonnet-20240620',
|
|
24
|
+
'openai:gpt-4o-mini-2024-07-18',
|
|
25
|
+
'groq:llama-3.2-90b-vision-preview',
|
|
26
|
+
'groq:llama-3.3-70b-versatile',
|
|
27
|
+
'fireworks-ai:accounts/fireworks/models/llama-v3p1-405b-instruct',
|
|
28
|
+
'google-ai:models/gemini-1.5-flash-002',
|
|
29
|
+
'openai:o1-mini-2024-09-12',
|
|
30
|
+
])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('Models ranking (fast)', () => {
|
|
34
|
+
const fast = getFastModels(MODELS as Model[])
|
|
35
|
+
expect(fast.slice(0, 10).map((x) => x.ref)).toEqual([
|
|
36
|
+
'openai:gpt-4o-mini-2024-07-18',
|
|
37
|
+
'google-ai:models/gemini-1.5-flash-002',
|
|
38
|
+
'google-ai:models/gemini-1.5-flash-8b-001',
|
|
39
|
+
'openai:gpt-4o-2024-11-20',
|
|
40
|
+
'openai:gpt-4o-2024-08-06',
|
|
41
|
+
'google-ai:models/gemini-1.5-pro-002',
|
|
42
|
+
'anthropic:claude-3-haiku-20240307',
|
|
43
|
+
'anthropic:claude-3-5-sonnet-20240620',
|
|
44
|
+
'groq:llama-3.2-90b-vision-preview',
|
|
45
|
+
'groq:llama-3.3-70b-versatile',
|
|
46
|
+
])
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('Models ranking (boosted)', () => {
|
|
50
|
+
const fast = getFastModels(MODELS as Model[], {
|
|
51
|
+
'groq:llama-3.3-70b-versatile': 10,
|
|
52
|
+
'openai:gpt-4o-mini-2024-07-18': -10,
|
|
53
|
+
'google-ai:': 20,
|
|
54
|
+
})
|
|
55
|
+
expect(fast.slice(0, 10).map((x) => x.ref)).toEqual([
|
|
56
|
+
'google-ai:models/gemini-1.5-flash-002',
|
|
57
|
+
'google-ai:models/gemini-1.5-flash-8b-001',
|
|
58
|
+
'google-ai:models/gemini-1.5-pro-002',
|
|
59
|
+
'groq:llama-3.3-70b-versatile',
|
|
60
|
+
'openai:gpt-4o-2024-11-20',
|
|
61
|
+
'openai:gpt-4o-2024-08-06',
|
|
62
|
+
'anthropic:claude-3-haiku-20240307',
|
|
63
|
+
'anthropic:claude-3-5-sonnet-20240620',
|
|
64
|
+
'groq:llama-3.2-90b-vision-preview',
|
|
65
|
+
'fireworks-ai:accounts/fireworks/models/llama-v3p1-405b-instruct',
|
|
66
|
+
])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('Pick model throws if none provided', () => {
|
|
70
|
+
expect(() => pickModel([])).toThrow()
|
|
71
|
+
expect(() => pickModel([], [])).toThrow()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('Pick model throws if all models down', () => {
|
|
75
|
+
expect(() =>
|
|
76
|
+
pickModel(
|
|
77
|
+
['a:b', 'b:c'],
|
|
78
|
+
[
|
|
79
|
+
{ ref: 'a:b', reason: 'down', startedAt: new Date().toISOString() },
|
|
80
|
+
{ ref: 'b:c', reason: 'down', startedAt: new Date().toISOString() },
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
).toThrow()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('Pick model picks the first one if all are up', () => {
|
|
87
|
+
expect(pickModel(['a:b', 'b:c'])).toEqual('a:b')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('Pick model picks fallback when first down', () => {
|
|
91
|
+
expect(pickModel(['a:b', 'b:c'], [{ ref: 'a:b', reason: 'down', startedAt: new Date().toISOString() }])).toEqual(
|
|
92
|
+
'b:c'
|
|
93
|
+
)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('Remote Model Provider', () => {
|
|
98
|
+
beforeEach(async () => {
|
|
99
|
+
const client = getTestClient()
|
|
100
|
+
const provider = new RemoteModelProvider(client)
|
|
101
|
+
await provider.deleteModelPreferences()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('fetch models preferences', async () => {
|
|
105
|
+
const client = getTestClient()
|
|
106
|
+
const provider = new RemoteModelProvider(client)
|
|
107
|
+
const preferences = await provider.fetchModelPreferences()
|
|
108
|
+
expect(preferences).toEqual(null)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('save file preferences', async () => {
|
|
112
|
+
const client = getTestClient()
|
|
113
|
+
const provider = new RemoteModelProvider(client)
|
|
114
|
+
|
|
115
|
+
const customPreferences = {
|
|
116
|
+
best: ['openai:gpt-4o-2024-11-20' as const],
|
|
117
|
+
fast: ['openai:gpt-4o-mini-2024-07-18' as const],
|
|
118
|
+
downtimes: [],
|
|
119
|
+
} satisfies ModelPreferences
|
|
120
|
+
|
|
121
|
+
await provider.saveModelPreferences(customPreferences)
|
|
122
|
+
|
|
123
|
+
const preferences = await provider.fetchModelPreferences()
|
|
124
|
+
|
|
125
|
+
expect(preferences).toEqual({
|
|
126
|
+
best: ['openai:gpt-4o-2024-11-20'],
|
|
127
|
+
downtimes: [],
|
|
128
|
+
fast: ['openai:gpt-4o-mini-2024-07-18'],
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cognitive",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Wrapper around the Botpress Client to call LLMs",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"check:type": "tsc --noEmit",
|
|
11
11
|
"generate": "ts-node -T ./types.ts ./src/gen",
|
|
12
|
-
"build:type": "tsup ./src/index.ts --dts-resolve --dts-only --clean",
|
|
12
|
+
"build:type": "tsup --tsconfig tsconfig.build.json ./src/index.ts --dts-resolve --dts-only --clean",
|
|
13
13
|
"build:neutral": "ts-node -T ./build.ts --neutral",
|
|
14
14
|
"build": "pnpm build:type && pnpm build:neutral && size-limit",
|
|
15
|
-
"test:e2e": "vitest run --dir ./
|
|
15
|
+
"test:e2e": "vitest run --dir ./e2e"
|
|
16
16
|
},
|
|
17
17
|
"size-limit": [
|
|
18
18
|
{
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@botpress/client": "workspace:*",
|
|
33
33
|
"@botpress/common": "workspace:*",
|
|
34
|
-
"@bpinternal/zui": "0.
|
|
34
|
+
"@bpinternal/zui": "0.13.5",
|
|
35
35
|
"@size-limit/file": "^11.1.6",
|
|
36
36
|
"@types/axios": "^0.14.4",
|
|
37
37
|
"@types/debug": "^4.1.12",
|