@botpress/cognitive 0.3.18 → 0.4.1
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 +7 -7
- package/dist/index.cjs +82 -8
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +170 -6
- package/dist/index.mjs +80 -7
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cognitive@0.
|
|
2
|
+
> @botpress/cognitive@0.4.1 build /home/runner/work/botpress/botpress/packages/cognitive
|
|
3
3
|
> pnpm build:type && pnpm build:neutral && size-limit
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cognitive@0.
|
|
6
|
+
> @botpress/cognitive@0.4.1 build:type /home/runner/work/botpress/botpress/packages/cognitive
|
|
7
7
|
> tsup --tsconfig tsconfig.build.json ./src/index.ts --dts-resolve --dts-only --clean
|
|
8
8
|
|
|
9
9
|
CLI Building entry: ./src/index.ts
|
|
10
10
|
CLI Using tsconfig: tsconfig.build.json
|
|
11
11
|
CLI tsup v8.0.2
|
|
12
12
|
DTS Build start
|
|
13
|
-
DTS ⚡️ Build success in
|
|
14
|
-
DTS dist/index.d.ts
|
|
13
|
+
DTS ⚡️ Build success in 6815ms
|
|
14
|
+
DTS dist/index.d.ts 669.97 KB
|
|
15
15
|
|
|
16
|
-
> @botpress/cognitive@0.
|
|
16
|
+
> @botpress/cognitive@0.4.1 build:neutral /home/runner/work/botpress/botpress/packages/cognitive
|
|
17
17
|
> ts-node -T ./build.ts --neutral
|
|
18
18
|
|
|
19
19
|
Done
|
|
20
20
|
|
|
21
21
|
[1mdist/index.cjs[22m
|
|
22
22
|
Size limit: [32m[1m50 kB[22m[39m
|
|
23
|
-
Size: [32m[
|
|
23
|
+
Size: [32m[1m16.14 kB[22m[39m [90mbrotlied[39m
|
|
24
24
|
|
|
25
25
|
[1mdist/index.mjs[22m
|
|
26
26
|
Size limit: [32m[1m50 kB[22m[39m
|
|
27
|
-
Size: [32m[1m15.
|
|
27
|
+
Size: [32m[1m15.98 kB[22m[39m [90mbrotlied[39m
|
|
28
28
|
|
package/dist/index.cjs
CHANGED
|
@@ -582,7 +582,8 @@ __export(index_exports, {
|
|
|
582
582
|
CognitiveBeta: () => CognitiveBeta,
|
|
583
583
|
ModelProvider: () => ModelProvider,
|
|
584
584
|
RemoteModelProvider: () => RemoteModelProvider,
|
|
585
|
-
getCognitiveV2Model: () => getCognitiveV2Model
|
|
585
|
+
getCognitiveV2Model: () => getCognitiveV2Model,
|
|
586
|
+
isKnownV2Model: () => isKnownV2Model
|
|
586
587
|
});
|
|
587
588
|
module.exports = __toCommonJS(index_exports);
|
|
588
589
|
|
|
@@ -2348,6 +2349,23 @@ var CognitiveBeta = class _CognitiveBeta {
|
|
|
2348
2349
|
);
|
|
2349
2350
|
}
|
|
2350
2351
|
};
|
|
2352
|
+
var COGNITIVE_V2_PROVIDERS = /* @__PURE__ */ new Set([
|
|
2353
|
+
"openai",
|
|
2354
|
+
"anthropic",
|
|
2355
|
+
"google-ai",
|
|
2356
|
+
"groq",
|
|
2357
|
+
"cerebras",
|
|
2358
|
+
"fireworks-ai",
|
|
2359
|
+
"xai",
|
|
2360
|
+
"openrouter"
|
|
2361
|
+
]);
|
|
2362
|
+
var isKnownV2Model = (model) => {
|
|
2363
|
+
if (!model || ["auto", "best", "fast"].includes(model)) {
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
const provider = model.split(":")[0];
|
|
2367
|
+
return !!provider && COGNITIVE_V2_PROVIDERS.has(provider);
|
|
2368
|
+
};
|
|
2351
2369
|
var getCognitiveV2Model = (model) => {
|
|
2352
2370
|
if (models[model]) {
|
|
2353
2371
|
return models[model];
|
|
@@ -2619,6 +2637,9 @@ var Cognitive = class _Cognitive {
|
|
|
2619
2637
|
_downtimes = [];
|
|
2620
2638
|
_useBeta = false;
|
|
2621
2639
|
_debug = false;
|
|
2640
|
+
_remoteModelCache = /* @__PURE__ */ new Map();
|
|
2641
|
+
_remoteModelCacheTime = 0;
|
|
2642
|
+
_remoteModelCachePending = null;
|
|
2622
2643
|
_events = createNanoEvents();
|
|
2623
2644
|
constructor(props) {
|
|
2624
2645
|
this._client = getExtendedClient(props.client);
|
|
@@ -2642,6 +2663,9 @@ var Cognitive = class _Cognitive {
|
|
|
2642
2663
|
copy._models = [...this._models];
|
|
2643
2664
|
copy._preferences = this._preferences ? { ...this._preferences } : null;
|
|
2644
2665
|
copy._downtimes = [...this._downtimes];
|
|
2666
|
+
copy._remoteModelCache = new Map(this._remoteModelCache);
|
|
2667
|
+
copy._remoteModelCacheTime = this._remoteModelCacheTime;
|
|
2668
|
+
copy._remoteModelCachePending = null;
|
|
2645
2669
|
copy.interceptors.request = this.interceptors.request;
|
|
2646
2670
|
copy.interceptors.response = this.interceptors.response;
|
|
2647
2671
|
return copy;
|
|
@@ -2704,12 +2728,50 @@ var Cognitive = class _Cognitive {
|
|
|
2704
2728
|
}
|
|
2705
2729
|
return parseRef(pickModel([ref, ...preferences.best, ...preferences.fast], downtimes));
|
|
2706
2730
|
}
|
|
2731
|
+
async fetchRemoteModels() {
|
|
2732
|
+
if (this._remoteModelCacheTime > 0 && Date.now() - this._remoteModelCacheTime < 60 * 60 * 1e3) {
|
|
2733
|
+
return this._remoteModelCache;
|
|
2734
|
+
}
|
|
2735
|
+
if (this._remoteModelCachePending !== null) {
|
|
2736
|
+
return this._remoteModelCachePending;
|
|
2737
|
+
}
|
|
2738
|
+
this._remoteModelCachePending = this._doFetchRemoteModels().finally(() => {
|
|
2739
|
+
this._remoteModelCachePending = null;
|
|
2740
|
+
});
|
|
2741
|
+
return this._remoteModelCachePending;
|
|
2742
|
+
}
|
|
2743
|
+
async _doFetchRemoteModels() {
|
|
2744
|
+
const betaClient = new CognitiveBeta(this._client.config);
|
|
2745
|
+
const remoteModels = await betaClient.listModels();
|
|
2746
|
+
this._remoteModelCache.clear();
|
|
2747
|
+
this._remoteModelCacheTime = Date.now();
|
|
2748
|
+
for (const m of remoteModels) {
|
|
2749
|
+
const converted = { ...m, ref: m.id, integration: "cognitive-v2" };
|
|
2750
|
+
this._remoteModelCache.set(m.id, converted);
|
|
2751
|
+
if (m.aliases) {
|
|
2752
|
+
for (const alias of m.aliases) {
|
|
2753
|
+
this._remoteModelCache.set(alias, converted);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
return this._remoteModelCache;
|
|
2758
|
+
}
|
|
2707
2759
|
async getModelDetails(model) {
|
|
2708
2760
|
if (this._useBeta) {
|
|
2709
2761
|
const resolvedModel = getCognitiveV2Model(model);
|
|
2710
2762
|
if (resolvedModel) {
|
|
2711
2763
|
return { ...resolvedModel, ref: resolvedModel.id, integration: "cognitive-v2" };
|
|
2712
2764
|
}
|
|
2765
|
+
if (isKnownV2Model(model)) {
|
|
2766
|
+
try {
|
|
2767
|
+
const remoteModels = await this.fetchRemoteModels();
|
|
2768
|
+
const found = remoteModels.get(model);
|
|
2769
|
+
if (found) {
|
|
2770
|
+
return found;
|
|
2771
|
+
}
|
|
2772
|
+
} catch {
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2713
2775
|
}
|
|
2714
2776
|
await this.fetchInstalledModels();
|
|
2715
2777
|
const { integration, model: modelName } = await this._selectModel(model);
|
|
@@ -2720,12 +2782,23 @@ var Cognitive = class _Cognitive {
|
|
|
2720
2782
|
return def;
|
|
2721
2783
|
}
|
|
2722
2784
|
async generateContent(input) {
|
|
2723
|
-
if (!this._useBeta || !
|
|
2785
|
+
if (!this._useBeta || !isKnownV2Model(input.model)) {
|
|
2786
|
+
return this._generateContent(input);
|
|
2787
|
+
}
|
|
2788
|
+
try {
|
|
2789
|
+
return await this._generateContentV2(input);
|
|
2790
|
+
} catch (err) {
|
|
2791
|
+
if (input.signal?.aborted) {
|
|
2792
|
+
throw err;
|
|
2793
|
+
}
|
|
2724
2794
|
return this._generateContent(input);
|
|
2725
2795
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2796
|
+
}
|
|
2797
|
+
async _generateContentV2(input) {
|
|
2798
|
+
const v2Input = { ...input, messages: [...input.messages] };
|
|
2799
|
+
if (v2Input.systemPrompt) {
|
|
2800
|
+
v2Input.messages.unshift({ role: "system", content: v2Input.systemPrompt });
|
|
2801
|
+
delete v2Input.systemPrompt;
|
|
2729
2802
|
}
|
|
2730
2803
|
const betaClient = new CognitiveBeta(this._client.config);
|
|
2731
2804
|
const props = { input };
|
|
@@ -2738,7 +2811,7 @@ var Cognitive = class _Cognitive {
|
|
|
2738
2811
|
betaClient.on("retry", (_req, error) => {
|
|
2739
2812
|
this._events.emit("retry", props, error);
|
|
2740
2813
|
});
|
|
2741
|
-
const response = await betaClient.generateText(
|
|
2814
|
+
const response = await betaClient.generateText(v2Input, {
|
|
2742
2815
|
signal: input.signal,
|
|
2743
2816
|
timeout: this._timeoutMs
|
|
2744
2817
|
});
|
|
@@ -2753,7 +2826,7 @@ var Cognitive = class _Cognitive {
|
|
|
2753
2826
|
content: response.output,
|
|
2754
2827
|
role: "assistant",
|
|
2755
2828
|
index: 0,
|
|
2756
|
-
stopReason: response.metadata.stopReason
|
|
2829
|
+
stopReason: response.metadata.stopReason ?? "stop"
|
|
2757
2830
|
}
|
|
2758
2831
|
],
|
|
2759
2832
|
usage: {
|
|
@@ -2860,6 +2933,7 @@ var Cognitive = class _Cognitive {
|
|
|
2860
2933
|
CognitiveBeta,
|
|
2861
2934
|
ModelProvider,
|
|
2862
2935
|
RemoteModelProvider,
|
|
2863
|
-
getCognitiveV2Model
|
|
2936
|
+
getCognitiveV2Model,
|
|
2937
|
+
isKnownV2Model
|
|
2864
2938
|
});
|
|
2865
2939
|
//# sourceMappingURL=index.cjs.map
|