@promptbook/openai 0.89.0-1 → 0.89.0-13
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/README.md +3 -1
- package/esm/index.es.js +116 -43
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +18 -4
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +18 -20
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +16 -8
- package/esm/typings/src/errors/0-index.d.ts +9 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +10 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
- package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
- package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +36 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -3
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +89 -4
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +116 -43
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -64
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
1
2
|
import type { Promisable } from 'type-fest';
|
|
2
3
|
import type { PipelineCollection } from '../../collection/PipelineCollection';
|
|
4
|
+
import { AuthenticationError } from '../../errors/AuthenticationError';
|
|
3
5
|
import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
|
|
6
|
+
import type { ExecutionTools } from '../../execution/ExecutionTools';
|
|
4
7
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
5
8
|
import type { string_app_id } from '../../types/typeAliases';
|
|
9
|
+
import type { string_email } from '../../types/typeAliases';
|
|
10
|
+
import type { string_password } from '../../types/typeAliases';
|
|
6
11
|
import type { string_uri } from '../../types/typeAliases';
|
|
7
12
|
import type { string_user_id } from '../../types/typeAliases';
|
|
13
|
+
import type { ApplicationModeIdentification } from '../socket-types/_subtypes/Identification';
|
|
14
|
+
import type { Identification } from '../socket-types/_subtypes/Identification';
|
|
8
15
|
/**
|
|
9
16
|
* @@@
|
|
10
17
|
*
|
|
@@ -16,7 +23,6 @@ import type { string_user_id } from '../../types/typeAliases';
|
|
|
16
23
|
*
|
|
17
24
|
* You can enable both modes at the same time.
|
|
18
25
|
*
|
|
19
|
-
* @public exported from `@promptbook/remote-client`
|
|
20
26
|
* @public exported from `@promptbook/remote-server`
|
|
21
27
|
*/
|
|
22
28
|
export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
|
|
@@ -32,8 +38,25 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
|
|
|
32
38
|
* @default '/'
|
|
33
39
|
* @example '/api/promptbook/'
|
|
34
40
|
*/
|
|
35
|
-
readonly rootPath
|
|
36
|
-
|
|
41
|
+
readonly rootPath?: string_uri;
|
|
42
|
+
/**
|
|
43
|
+
* Creates execution tools the client
|
|
44
|
+
*
|
|
45
|
+
* This is relevant also in anonymous mode in oposition to `createLlmExecutionTools`
|
|
46
|
+
*
|
|
47
|
+
* Note: You can provide only some tools and leave the rest to the default ones also llm tools are created by `createLlmExecutionTools`
|
|
48
|
+
* Note: This is useful when you want to provide some custom restrictions for example:
|
|
49
|
+
* - Limit access to certain websites for some users
|
|
50
|
+
* - Bind user-interface tools to email agent
|
|
51
|
+
* - Allow / block script execution
|
|
52
|
+
* - And many more
|
|
53
|
+
*/
|
|
54
|
+
createExecutionTools?(options: Identification<TCustomOptions>): Promisable<Partial<Omit<ExecutionTools, 'llm'>>>;
|
|
55
|
+
} & ((AnonymousRemoteServerOptions & {
|
|
56
|
+
readonly isApplicationModeAllowed?: false;
|
|
57
|
+
}) | ({
|
|
58
|
+
readonly isAnonymousModeAllowed?: false;
|
|
59
|
+
} & ApplicationRemoteServerOptions<TCustomOptions>) | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
|
|
37
60
|
export type AnonymousRemoteServerOptions = {
|
|
38
61
|
/**
|
|
39
62
|
* Enable anonymous mode
|
|
@@ -51,10 +74,22 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
|
|
|
51
74
|
* This is used to check validity of the prompt to prevent misuse
|
|
52
75
|
*/
|
|
53
76
|
readonly collection: PipelineCollection;
|
|
77
|
+
/**
|
|
78
|
+
* User tries to login to the server, this function will be called verify the user and return the identification or throw an error
|
|
79
|
+
* This can be also doubled as a function to register the user
|
|
80
|
+
*
|
|
81
|
+
* Note: In most cases, you will return `PromptbookServer_ApplicationIdentification`
|
|
82
|
+
* `PromptbookServer_AnonymousIdentification` is useful only in scenarios when user stores its own api keys on the application server and
|
|
83
|
+
* server acts only as a api key provider
|
|
84
|
+
*
|
|
85
|
+
* Note: In most cases DO NOT THROW `AuthenticationError` but return `isSuccess: false` with message
|
|
86
|
+
* @throws `AuthenticationError` if the user is not allowed to login for example because of invalid credentials
|
|
87
|
+
*/
|
|
88
|
+
login(loginRequest: LoginRequest): Promise<LoginResponse<TCustomOptions>>;
|
|
54
89
|
/**
|
|
55
90
|
* Creates llm execution tools for each client
|
|
56
91
|
*/
|
|
57
|
-
createLlmExecutionTools(options:
|
|
92
|
+
createLlmExecutionTools(options: ApplicationModeIdentification<TCustomOptions>): Promisable<LlmExecutionTools>;
|
|
58
93
|
};
|
|
59
94
|
export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
60
95
|
/**
|
|
@@ -82,6 +117,56 @@ export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
|
82
117
|
*/
|
|
83
118
|
readonly customOptions?: TCustomOptions;
|
|
84
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Login request for the application mode
|
|
122
|
+
*/
|
|
123
|
+
export type LoginRequest = {
|
|
124
|
+
/**
|
|
125
|
+
* Identifier of the application you are using
|
|
126
|
+
*
|
|
127
|
+
* Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
|
|
128
|
+
*/
|
|
129
|
+
readonly appId: string_app_id | null;
|
|
130
|
+
/**
|
|
131
|
+
* Username (for example email) of the user
|
|
132
|
+
*/
|
|
133
|
+
readonly username: string_email | string;
|
|
134
|
+
/**
|
|
135
|
+
* Password of the user
|
|
136
|
+
*/
|
|
137
|
+
readonly password: string_password;
|
|
138
|
+
/**
|
|
139
|
+
* Request object from express if you want to access some request data for example headers, IP address, etc.
|
|
140
|
+
*/
|
|
141
|
+
readonly rawRequest: Request;
|
|
142
|
+
/**
|
|
143
|
+
* Response object from express if you want to add some custom headers.
|
|
144
|
+
*
|
|
145
|
+
* Note: It is not recommended to use this object to send body of the response because it can confuse the client
|
|
146
|
+
*/
|
|
147
|
+
readonly rawResponse: Response;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Login response for the application mode
|
|
151
|
+
*/
|
|
152
|
+
export type LoginResponse<TCustomOptions> = {
|
|
153
|
+
/**
|
|
154
|
+
* Was the login successful
|
|
155
|
+
*/
|
|
156
|
+
readonly isSuccess: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Message to display to the user, this message is always displayed
|
|
159
|
+
*/
|
|
160
|
+
readonly message?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Optional error if the login was not successful
|
|
163
|
+
*/
|
|
164
|
+
readonly error?: AuthenticationError;
|
|
165
|
+
/**
|
|
166
|
+
* Identification of the user to be used in the future requests
|
|
167
|
+
*/
|
|
168
|
+
readonly identification?: Identification<TCustomOptions>;
|
|
169
|
+
};
|
|
85
170
|
/**
|
|
86
171
|
* TODO: Constrain anonymous mode for specific models / providers
|
|
87
172
|
*/
|
|
@@ -2,9 +2,9 @@ import type { PromptbookFetch } from '../../../execution/PromptbookFetch';
|
|
|
2
2
|
/**
|
|
3
3
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
5
|
+
* @public exported from `@promptbook/core`
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const promptbookFetch: PromptbookFetch;
|
|
8
8
|
/**
|
|
9
9
|
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
10
10
|
*/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PromptbookStorage } from '../_common/PromptbookStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Stores data in .env variables (Remove !!! nonce 1)
|
|
4
|
+
*
|
|
5
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file and also writes to `process.env`
|
|
6
|
+
*
|
|
7
|
+
* @private within the repository - for CLI utils
|
|
8
|
+
*/
|
|
9
|
+
export declare class $EnvStorage<TItem> implements PromptbookStorage<TItem> {
|
|
10
|
+
private envFilename;
|
|
11
|
+
private $provideOrCreateEnvFile;
|
|
12
|
+
private transformKey;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the number of key/value pairs currently present in the list associated with the object.
|
|
15
|
+
*/
|
|
16
|
+
get length(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
19
|
+
*/
|
|
20
|
+
clear(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
23
|
+
*/
|
|
24
|
+
getItem(key: string): Promise<TItem | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
27
|
+
*/
|
|
28
|
+
key(index: number): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
31
|
+
*/
|
|
32
|
+
setItem(key: string, value: TItem): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
35
|
+
*/
|
|
36
|
+
removeItem(key: string): void;
|
|
37
|
+
}
|
|
@@ -242,6 +242,12 @@ export type string_promptbook_documentation_url = `https://github.com/webgptorg/
|
|
|
242
242
|
* For example `"towns.cz"`
|
|
243
243
|
*/
|
|
244
244
|
export type string_domain = string;
|
|
245
|
+
/**
|
|
246
|
+
* Semantic helper
|
|
247
|
+
*
|
|
248
|
+
* For example `"https://*.pavolhejny.com/*"`
|
|
249
|
+
*/
|
|
250
|
+
export type string_origin = string;
|
|
245
251
|
/**
|
|
246
252
|
* Semantic helper
|
|
247
253
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.89.0-
|
|
3
|
+
"version": "0.89.0-13",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/openai.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.89.0-
|
|
50
|
+
"@promptbook/core": "0.89.0-13"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* @generated
|
|
25
25
|
* @see https://github.com/webgptorg/promptbook
|
|
26
26
|
*/
|
|
27
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
27
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-13';
|
|
28
28
|
/**
|
|
29
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -154,30 +154,42 @@
|
|
|
154
154
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
155
155
|
*/
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Represents the uncertain value
|
|
159
|
+
*
|
|
160
|
+
* @public exported from `@promptbook/core`
|
|
161
|
+
*/
|
|
162
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
163
|
+
/**
|
|
164
|
+
* Represents the uncertain value
|
|
165
|
+
*
|
|
166
|
+
* @public exported from `@promptbook/core`
|
|
167
|
+
*/
|
|
168
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
157
169
|
/**
|
|
158
170
|
* Represents the usage with no resources consumed
|
|
159
171
|
*
|
|
160
172
|
* @public exported from `@promptbook/core`
|
|
161
173
|
*/
|
|
162
174
|
$deepFreeze({
|
|
163
|
-
price:
|
|
175
|
+
price: ZERO_VALUE,
|
|
164
176
|
input: {
|
|
165
|
-
tokensCount:
|
|
166
|
-
charactersCount:
|
|
167
|
-
wordsCount:
|
|
168
|
-
sentencesCount:
|
|
169
|
-
linesCount:
|
|
170
|
-
paragraphsCount:
|
|
171
|
-
pagesCount:
|
|
177
|
+
tokensCount: ZERO_VALUE,
|
|
178
|
+
charactersCount: ZERO_VALUE,
|
|
179
|
+
wordsCount: ZERO_VALUE,
|
|
180
|
+
sentencesCount: ZERO_VALUE,
|
|
181
|
+
linesCount: ZERO_VALUE,
|
|
182
|
+
paragraphsCount: ZERO_VALUE,
|
|
183
|
+
pagesCount: ZERO_VALUE,
|
|
172
184
|
},
|
|
173
185
|
output: {
|
|
174
|
-
tokensCount:
|
|
175
|
-
charactersCount:
|
|
176
|
-
wordsCount:
|
|
177
|
-
sentencesCount:
|
|
178
|
-
linesCount:
|
|
179
|
-
paragraphsCount:
|
|
180
|
-
pagesCount:
|
|
186
|
+
tokensCount: ZERO_VALUE,
|
|
187
|
+
charactersCount: ZERO_VALUE,
|
|
188
|
+
wordsCount: ZERO_VALUE,
|
|
189
|
+
sentencesCount: ZERO_VALUE,
|
|
190
|
+
linesCount: ZERO_VALUE,
|
|
191
|
+
paragraphsCount: ZERO_VALUE,
|
|
192
|
+
pagesCount: ZERO_VALUE,
|
|
181
193
|
},
|
|
182
194
|
});
|
|
183
195
|
/**
|
|
@@ -186,24 +198,24 @@
|
|
|
186
198
|
* @public exported from `@promptbook/core`
|
|
187
199
|
*/
|
|
188
200
|
const UNCERTAIN_USAGE = $deepFreeze({
|
|
189
|
-
price:
|
|
201
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
190
202
|
input: {
|
|
191
|
-
tokensCount:
|
|
192
|
-
charactersCount:
|
|
193
|
-
wordsCount:
|
|
194
|
-
sentencesCount:
|
|
195
|
-
linesCount:
|
|
196
|
-
paragraphsCount:
|
|
197
|
-
pagesCount:
|
|
203
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
204
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
205
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
206
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
207
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
208
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
209
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
198
210
|
},
|
|
199
211
|
output: {
|
|
200
|
-
tokensCount:
|
|
201
|
-
charactersCount:
|
|
202
|
-
wordsCount:
|
|
203
|
-
sentencesCount:
|
|
204
|
-
linesCount:
|
|
205
|
-
paragraphsCount:
|
|
206
|
-
pagesCount:
|
|
212
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
213
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
214
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
215
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
216
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
217
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
218
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
207
219
|
},
|
|
208
220
|
});
|
|
209
221
|
/**
|
|
@@ -262,6 +274,7 @@
|
|
|
262
274
|
infinity: '(infinity; ∞)',
|
|
263
275
|
negativeInfinity: '(negative infinity; -∞)',
|
|
264
276
|
unserializable: '(unserializable value)',
|
|
277
|
+
circular: '(circular JSON)',
|
|
265
278
|
};
|
|
266
279
|
/**
|
|
267
280
|
* Small number limit
|
|
@@ -283,7 +296,7 @@
|
|
|
283
296
|
});
|
|
284
297
|
/**
|
|
285
298
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
286
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
299
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
287
300
|
*/
|
|
288
301
|
|
|
289
302
|
/**
|
|
@@ -369,6 +382,56 @@
|
|
|
369
382
|
}
|
|
370
383
|
}
|
|
371
384
|
|
|
385
|
+
/**
|
|
386
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
387
|
+
*
|
|
388
|
+
* @public exported from `@promptbook/core`
|
|
389
|
+
*/
|
|
390
|
+
class WrappedError extends Error {
|
|
391
|
+
constructor(whatWasThrown) {
|
|
392
|
+
const tag = `[🤮]`;
|
|
393
|
+
console.error(tag, whatWasThrown);
|
|
394
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
395
|
+
${ /* Fixing tests !!! block(valueToString(whatWasThrown)) */block(`non-Error object was thrown`)}
|
|
396
|
+
|
|
397
|
+
Note: Look for ${tag} in the console for more details
|
|
398
|
+
!!! Note: \`WrappedError\` indicates that somewhere in the code non-Error object was thrown and it was wrapped
|
|
399
|
+
|
|
400
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
401
|
+
|
|
402
|
+
`));
|
|
403
|
+
this.name = 'WrappedError';
|
|
404
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* !!!@@@
|
|
410
|
+
*
|
|
411
|
+
* @param whatWasThrown !!!@@@
|
|
412
|
+
* @returns !!!@@@
|
|
413
|
+
*
|
|
414
|
+
* @private within the repository
|
|
415
|
+
*/
|
|
416
|
+
function assertsError(whatWasThrown) {
|
|
417
|
+
// Case 1: !!!@@@
|
|
418
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
419
|
+
const wrappedError = whatWasThrown;
|
|
420
|
+
throw wrappedError;
|
|
421
|
+
}
|
|
422
|
+
// Case 2: !!!@@@
|
|
423
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
424
|
+
const unexpectedError = whatWasThrown;
|
|
425
|
+
throw unexpectedError;
|
|
426
|
+
}
|
|
427
|
+
// Case 3: !!!@@@
|
|
428
|
+
if (whatWasThrown instanceof Error) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
// Case 4: !!!@@@
|
|
432
|
+
throw new WrappedError(whatWasThrown);
|
|
433
|
+
}
|
|
434
|
+
|
|
372
435
|
/**
|
|
373
436
|
* Checks if the value is [🚉] serializable as JSON
|
|
374
437
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -460,9 +523,7 @@
|
|
|
460
523
|
JSON.stringify(value); // <- TODO: [0]
|
|
461
524
|
}
|
|
462
525
|
catch (error) {
|
|
463
|
-
|
|
464
|
-
throw error;
|
|
465
|
-
}
|
|
526
|
+
assertsError(error);
|
|
466
527
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
467
528
|
\`${name}\` is not serializable
|
|
468
529
|
|
|
@@ -684,13 +745,19 @@
|
|
|
684
745
|
return value.toISOString();
|
|
685
746
|
}
|
|
686
747
|
else {
|
|
687
|
-
|
|
748
|
+
try {
|
|
749
|
+
return JSON.stringify(value);
|
|
750
|
+
}
|
|
751
|
+
catch (error) {
|
|
752
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
753
|
+
return VALUE_STRINGS.circular;
|
|
754
|
+
}
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
688
757
|
}
|
|
689
758
|
}
|
|
690
759
|
catch (error) {
|
|
691
|
-
|
|
692
|
-
throw error;
|
|
693
|
-
}
|
|
760
|
+
assertsError(error);
|
|
694
761
|
console.error(error);
|
|
695
762
|
return VALUE_STRINGS.unserializable;
|
|
696
763
|
}
|
|
@@ -1146,7 +1213,7 @@
|
|
|
1146
1213
|
* Helper of usage compute
|
|
1147
1214
|
*
|
|
1148
1215
|
* @param content the content of prompt or response
|
|
1149
|
-
* @returns part of
|
|
1216
|
+
* @returns part of UsageCounts
|
|
1150
1217
|
*
|
|
1151
1218
|
* @private internal utility of LlmExecutionTools
|
|
1152
1219
|
*/
|
|
@@ -1170,7 +1237,7 @@
|
|
|
1170
1237
|
*/
|
|
1171
1238
|
function uncertainNumber(value) {
|
|
1172
1239
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
1173
|
-
return
|
|
1240
|
+
return UNCERTAIN_ZERO_VALUE;
|
|
1174
1241
|
}
|
|
1175
1242
|
return { value };
|
|
1176
1243
|
}
|
|
@@ -1689,15 +1756,18 @@
|
|
|
1689
1756
|
}
|
|
1690
1757
|
return this.client;
|
|
1691
1758
|
}
|
|
1759
|
+
/*
|
|
1760
|
+
Note: Commenting this out to avoid circular dependency
|
|
1692
1761
|
/**
|
|
1693
1762
|
* Create (sub)tools for calling OpenAI API Assistants
|
|
1694
1763
|
*
|
|
1695
1764
|
* @param assistantId Which assistant to use
|
|
1696
1765
|
* @returns Tools for calling OpenAI API Assistants with same token
|
|
1697
|
-
|
|
1698
|
-
createAssistantSubtools(assistantId) {
|
|
1766
|
+
* /
|
|
1767
|
+
public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
|
|
1699
1768
|
return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
|
|
1700
1769
|
}
|
|
1770
|
+
*/
|
|
1701
1771
|
/**
|
|
1702
1772
|
* Check the `options` passed to `constructor`
|
|
1703
1773
|
*/
|
|
@@ -1773,6 +1843,7 @@
|
|
|
1773
1843
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1774
1844
|
}
|
|
1775
1845
|
const rawResponse = await client.chat.completions.create(rawRequest).catch((error) => {
|
|
1846
|
+
assertsError(error);
|
|
1776
1847
|
if (this.options.isVerbose) {
|
|
1777
1848
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
1778
1849
|
}
|
|
@@ -1849,6 +1920,7 @@
|
|
|
1849
1920
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1850
1921
|
}
|
|
1851
1922
|
const rawResponse = await client.completions.create(rawRequest).catch((error) => {
|
|
1923
|
+
assertsError(error);
|
|
1852
1924
|
if (this.options.isVerbose) {
|
|
1853
1925
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
1854
1926
|
}
|
|
@@ -1912,6 +1984,7 @@
|
|
|
1912
1984
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1913
1985
|
}
|
|
1914
1986
|
const rawResponse = await client.embeddings.create(rawRequest).catch((error) => {
|
|
1987
|
+
assertsError(error);
|
|
1915
1988
|
if (this.options.isVerbose) {
|
|
1916
1989
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
1917
1990
|
}
|