@promptbook/cli 0.92.0-7 → 0.92.0-9
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/esm/index.es.js +31 -6
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/package.json +2 -1
- package/umd/index.umd.js +35 -10
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,6 +27,7 @@ import * as OpenApiValidator from 'express-openapi-validator';
|
|
|
27
27
|
import swaggerUi from 'swagger-ui-express';
|
|
28
28
|
import Anthropic from '@anthropic-ai/sdk';
|
|
29
29
|
import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
|
|
30
|
+
import Bottleneck from 'bottleneck';
|
|
30
31
|
import OpenAI from 'openai';
|
|
31
32
|
import { Readability } from '@mozilla/readability';
|
|
32
33
|
import { JSDOM } from 'jsdom';
|
|
@@ -46,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
46
47
|
* @generated
|
|
47
48
|
* @see https://github.com/webgptorg/promptbook
|
|
48
49
|
*/
|
|
49
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
50
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
|
|
50
51
|
/**
|
|
51
52
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
52
53
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15737,6 +15738,9 @@ const OPENAI_MODELS = exportJson({
|
|
|
15737
15738
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15738
15739
|
*/
|
|
15739
15740
|
|
|
15741
|
+
// Default rate limits (requests per minute) - adjust as needed based on Azure OpenAI tier
|
|
15742
|
+
const DEFAULT_RPM$1 = 60;
|
|
15743
|
+
// <- TODO: !!! Put in some better place
|
|
15740
15744
|
/**
|
|
15741
15745
|
* Execution Tools for calling Azure OpenAI API.
|
|
15742
15746
|
*
|
|
@@ -15754,6 +15758,10 @@ class AzureOpenAiExecutionTools {
|
|
|
15754
15758
|
* OpenAI Azure API client.
|
|
15755
15759
|
*/
|
|
15756
15760
|
this.client = null;
|
|
15761
|
+
// TODO: Allow configuring rate limits via options
|
|
15762
|
+
this.limiter = new Bottleneck({
|
|
15763
|
+
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_RPM$1),
|
|
15764
|
+
});
|
|
15757
15765
|
}
|
|
15758
15766
|
get title() {
|
|
15759
15767
|
return 'Azure OpenAI';
|
|
@@ -15831,7 +15839,9 @@ class AzureOpenAiExecutionTools {
|
|
|
15831
15839
|
console.info(colors.bgWhite('messages'), JSON.stringify(messages, null, 4));
|
|
15832
15840
|
}
|
|
15833
15841
|
const rawRequest = [modelName, messages, modelSettings];
|
|
15834
|
-
const rawResponse = await this.
|
|
15842
|
+
const rawResponse = await this.limiter
|
|
15843
|
+
.schedule(() => this.withTimeout(client.getChatCompletions(...rawRequest)))
|
|
15844
|
+
.catch((error) => {
|
|
15835
15845
|
if (this.options.isVerbose) {
|
|
15836
15846
|
console.info(colors.bgRed('error'), error);
|
|
15837
15847
|
}
|
|
@@ -15927,7 +15937,9 @@ class AzureOpenAiExecutionTools {
|
|
|
15927
15937
|
[rawPromptContent],
|
|
15928
15938
|
modelSettings,
|
|
15929
15939
|
];
|
|
15930
|
-
const rawResponse = await this.
|
|
15940
|
+
const rawResponse = await this.limiter
|
|
15941
|
+
.schedule(() => this.withTimeout(client.getCompletions(...rawRequest)))
|
|
15942
|
+
.catch((error) => {
|
|
15931
15943
|
if (this.options.isVerbose) {
|
|
15932
15944
|
console.info(colors.bgRed('error'), error);
|
|
15933
15945
|
}
|
|
@@ -16777,6 +16789,9 @@ resultContent, rawResponse) {
|
|
|
16777
16789
|
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
|
|
16778
16790
|
*/
|
|
16779
16791
|
|
|
16792
|
+
// Default rate limits (requests per minute) - adjust as needed based on OpenAI tier
|
|
16793
|
+
const DEFAULT_RPM = 60;
|
|
16794
|
+
// <- TODO: !!! Put in some better place
|
|
16780
16795
|
/**
|
|
16781
16796
|
* Execution Tools for calling OpenAI API
|
|
16782
16797
|
*
|
|
@@ -16794,6 +16809,10 @@ class OpenAiExecutionTools {
|
|
|
16794
16809
|
* OpenAI API client.
|
|
16795
16810
|
*/
|
|
16796
16811
|
this.client = null;
|
|
16812
|
+
// TODO: Allow configuring rate limits via options
|
|
16813
|
+
this.limiter = new Bottleneck({
|
|
16814
|
+
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_RPM),
|
|
16815
|
+
});
|
|
16797
16816
|
}
|
|
16798
16817
|
get title() {
|
|
16799
16818
|
return 'OpenAI';
|
|
@@ -16897,7 +16916,9 @@ class OpenAiExecutionTools {
|
|
|
16897
16916
|
if (this.options.isVerbose) {
|
|
16898
16917
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
16899
16918
|
}
|
|
16900
|
-
const rawResponse = await
|
|
16919
|
+
const rawResponse = await this.limiter
|
|
16920
|
+
.schedule(() => client.chat.completions.create(rawRequest))
|
|
16921
|
+
.catch((error) => {
|
|
16901
16922
|
assertsError(error);
|
|
16902
16923
|
if (this.options.isVerbose) {
|
|
16903
16924
|
console.info(colors.bgRed('error'), error);
|
|
@@ -16974,7 +16995,9 @@ class OpenAiExecutionTools {
|
|
|
16974
16995
|
if (this.options.isVerbose) {
|
|
16975
16996
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
16976
16997
|
}
|
|
16977
|
-
const rawResponse = await
|
|
16998
|
+
const rawResponse = await this.limiter
|
|
16999
|
+
.schedule(() => client.completions.create(rawRequest))
|
|
17000
|
+
.catch((error) => {
|
|
16978
17001
|
assertsError(error);
|
|
16979
17002
|
if (this.options.isVerbose) {
|
|
16980
17003
|
console.info(colors.bgRed('error'), error);
|
|
@@ -17038,7 +17061,9 @@ class OpenAiExecutionTools {
|
|
|
17038
17061
|
if (this.options.isVerbose) {
|
|
17039
17062
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
17040
17063
|
}
|
|
17041
|
-
const rawResponse = await
|
|
17064
|
+
const rawResponse = await this.limiter
|
|
17065
|
+
.schedule(() => client.embeddings.create(rawRequest))
|
|
17066
|
+
.catch((error) => {
|
|
17042
17067
|
assertsError(error);
|
|
17043
17068
|
if (this.options.isVerbose) {
|
|
17044
17069
|
console.info(colors.bgRed('error'), error);
|