@promptbook/anthropic-claude 0.66.0 → 0.67.0-0
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 +355 -72
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -4
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/_packages/utils.index.d.ts +14 -8
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
- package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
- package/esm/typings/src/errors/index.d.ts +27 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
- package/esm/typings/src/execution/PromptResult.d.ts +5 -4
- package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +359 -76
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
1
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
3
|
import colors from 'colors';
|
|
3
|
-
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
4
4
|
import { io } from 'socket.io-client';
|
|
5
5
|
|
|
6
6
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
7
7
|
/**
|
|
8
8
|
* The version of the Promptbook library
|
|
9
9
|
*/
|
|
10
|
-
var PROMPTBOOK_VERSION = '0.66.0
|
|
10
|
+
var PROMPTBOOK_VERSION = '0.66.0';
|
|
11
11
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
12
12
|
|
|
13
13
|
/*! *****************************************************************************
|
|
@@ -119,6 +119,199 @@ function __read(o, n) {
|
|
|
119
119
|
return ar;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @@@
|
|
124
|
+
*
|
|
125
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
126
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
127
|
+
*
|
|
128
|
+
* @returns The same object as the input, but deeply frozen
|
|
129
|
+
* @public exported from `@promptbook/utils`
|
|
130
|
+
*/
|
|
131
|
+
function $deepFreeze(objectValue) {
|
|
132
|
+
var e_1, _a;
|
|
133
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
134
|
+
try {
|
|
135
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
136
|
+
var propertyName = propertyNames_1_1.value;
|
|
137
|
+
var value = objectValue[propertyName];
|
|
138
|
+
if (value && typeof value === 'object') {
|
|
139
|
+
$deepFreeze(value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
144
|
+
finally {
|
|
145
|
+
try {
|
|
146
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
147
|
+
}
|
|
148
|
+
finally { if (e_1) throw e_1.error; }
|
|
149
|
+
}
|
|
150
|
+
return Object.freeze(objectValue);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
158
|
+
*
|
|
159
|
+
* @public exported from `@promptbook/core`
|
|
160
|
+
*/
|
|
161
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
162
|
+
__extends(UnexpectedError, _super);
|
|
163
|
+
function UnexpectedError(message) {
|
|
164
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
165
|
+
_this.name = 'UnexpectedError';
|
|
166
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
167
|
+
return _this;
|
|
168
|
+
}
|
|
169
|
+
return UnexpectedError;
|
|
170
|
+
}(Error));
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
174
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
175
|
+
*
|
|
176
|
+
* - Almost all primitives are serializable BUT:
|
|
177
|
+
* - `undefined` is not serializable
|
|
178
|
+
* - `NaN` is not serializable
|
|
179
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
180
|
+
* - Functions are not serializable
|
|
181
|
+
* - Circular references are not serializable
|
|
182
|
+
* - `Date` objects are not serializable
|
|
183
|
+
* - `Map` and `Set` objects are not serializable
|
|
184
|
+
* - `RegExp` objects are not serializable
|
|
185
|
+
* - `Error` objects are not serializable
|
|
186
|
+
* - `Symbol` objects are not serializable
|
|
187
|
+
* - And much more...
|
|
188
|
+
*
|
|
189
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
190
|
+
* @public exported from `@promptbook/utils`
|
|
191
|
+
*/
|
|
192
|
+
function checkSerializableAsJson(name, value) {
|
|
193
|
+
var e_1, _a;
|
|
194
|
+
if (value === undefined) {
|
|
195
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
196
|
+
}
|
|
197
|
+
else if (value === null) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
else if (typeof value === 'boolean') {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
else if (typeof value === 'string') {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
else if (typeof value === 'symbol') {
|
|
210
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
211
|
+
}
|
|
212
|
+
else if (typeof value === 'function') {
|
|
213
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
214
|
+
}
|
|
215
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
216
|
+
for (var i = 0; i < value.length; i++) {
|
|
217
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else if (typeof value === 'object') {
|
|
221
|
+
if (value instanceof Date) {
|
|
222
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
223
|
+
}
|
|
224
|
+
else if (value instanceof Map) {
|
|
225
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
226
|
+
}
|
|
227
|
+
else if (value instanceof Set) {
|
|
228
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
229
|
+
}
|
|
230
|
+
else if (value instanceof RegExp) {
|
|
231
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
232
|
+
}
|
|
233
|
+
else if (value instanceof Error) {
|
|
234
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
try {
|
|
238
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
239
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
240
|
+
if (subValue === undefined) {
|
|
241
|
+
// Note: undefined in object is serializable - it is just omited
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
248
|
+
finally {
|
|
249
|
+
try {
|
|
250
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
251
|
+
}
|
|
252
|
+
finally { if (e_1) throw e_1.error; }
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (!(error instanceof Error)) {
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
262
|
+
}
|
|
263
|
+
/*
|
|
264
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
265
|
+
const seen = new Set();
|
|
266
|
+
const stack = [{ value }];
|
|
267
|
+
while (stack.length > 0) {
|
|
268
|
+
const { value } = stack.pop()!;
|
|
269
|
+
if (typeof value === 'object' && value !== null) {
|
|
270
|
+
if (seen.has(value)) {
|
|
271
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
272
|
+
}
|
|
273
|
+
seen.add(value);
|
|
274
|
+
if (Array.isArray(value)) {
|
|
275
|
+
stack.push(...value.map((value) => ({ value })));
|
|
276
|
+
} else {
|
|
277
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
*/
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
291
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
292
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @@@
|
|
297
|
+
* @@@
|
|
298
|
+
*
|
|
299
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
300
|
+
*
|
|
301
|
+
* @param name - Name of the object for debugging purposes
|
|
302
|
+
* @param objectValue - Object to be deeply frozen
|
|
303
|
+
* @returns The same object as the input, but deeply frozen
|
|
304
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
305
|
+
*/
|
|
306
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
307
|
+
checkSerializableAsJson(name, objectValue);
|
|
308
|
+
return $deepFreeze(objectValue);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
312
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
313
|
+
*/
|
|
314
|
+
|
|
122
315
|
/**
|
|
123
316
|
* Function computeUsage will create price per one token based on the string value found on openai page
|
|
124
317
|
*
|
|
@@ -137,7 +330,7 @@ function computeUsage(value) {
|
|
|
137
330
|
* @see https://docs.anthropic.com/en/docs/models-overview
|
|
138
331
|
* @public exported from `@promptbook/anthropic-claude`
|
|
139
332
|
*/
|
|
140
|
-
var ANTHROPIC_CLAUDE_MODELS = [
|
|
333
|
+
var ANTHROPIC_CLAUDE_MODELS = $asDeeplyFrozenSerializableJson('ANTHROPIC_CLAUDE_MODELS', [
|
|
141
334
|
{
|
|
142
335
|
modelVariant: 'CHAT',
|
|
143
336
|
modelTitle: 'Claude 3.5 Sonnet',
|
|
@@ -202,7 +395,7 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
202
395
|
},
|
|
203
396
|
},
|
|
204
397
|
// TODO: !!! Claude 1 and 2 has also completion versions - ask Hoagy
|
|
205
|
-
];
|
|
398
|
+
]);
|
|
206
399
|
/**
|
|
207
400
|
* Note: [🤖] Add models of new variant
|
|
208
401
|
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
@@ -227,22 +420,6 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
227
420
|
return PipelineExecutionError;
|
|
228
421
|
}(Error));
|
|
229
422
|
|
|
230
|
-
/**
|
|
231
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
232
|
-
*
|
|
233
|
-
* @public exported from `@promptbook/core`
|
|
234
|
-
*/
|
|
235
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
236
|
-
__extends(UnexpectedError, _super);
|
|
237
|
-
function UnexpectedError(message) {
|
|
238
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
239
|
-
_this.name = 'UnexpectedError';
|
|
240
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
241
|
-
return _this;
|
|
242
|
-
}
|
|
243
|
-
return UnexpectedError;
|
|
244
|
-
}(Error));
|
|
245
|
-
|
|
246
423
|
/**
|
|
247
424
|
* Get current date in ISO 8601 format
|
|
248
425
|
*
|
|
@@ -252,40 +429,6 @@ function getCurrentIsoDate() {
|
|
|
252
429
|
return new Date().toISOString();
|
|
253
430
|
}
|
|
254
431
|
|
|
255
|
-
/**
|
|
256
|
-
* @@@
|
|
257
|
-
*
|
|
258
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
259
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
260
|
-
*
|
|
261
|
-
* @returns The same object as the input, but deeply frozen
|
|
262
|
-
* @public exported from `@promptbook/utils`
|
|
263
|
-
*/
|
|
264
|
-
function $deepFreeze(objectValue) {
|
|
265
|
-
var e_1, _a;
|
|
266
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
267
|
-
try {
|
|
268
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
269
|
-
var propertyName = propertyNames_1_1.value;
|
|
270
|
-
var value = objectValue[propertyName];
|
|
271
|
-
if (value && typeof value === 'object') {
|
|
272
|
-
$deepFreeze(value);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
277
|
-
finally {
|
|
278
|
-
try {
|
|
279
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
280
|
-
}
|
|
281
|
-
finally { if (e_1) throw e_1.error; }
|
|
282
|
-
}
|
|
283
|
-
return Object.freeze(objectValue);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
432
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
290
433
|
/**
|
|
291
434
|
* The maximum number of iterations for a loops
|
|
@@ -304,7 +447,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
304
447
|
*
|
|
305
448
|
* @public exported from `@promptbook/core`
|
|
306
449
|
*/
|
|
307
|
-
$
|
|
450
|
+
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
308
451
|
'content',
|
|
309
452
|
'context',
|
|
310
453
|
'knowledge',
|
|
@@ -964,7 +1107,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
964
1107
|
// eslint-disable-next-line prefer-const
|
|
965
1108
|
complete = getCurrentIsoDate();
|
|
966
1109
|
usage = computeAnthropicClaudeUsage(content, '', rawResponse);
|
|
967
|
-
return [2 /*return*/, {
|
|
1110
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools ChatPromptResult', {
|
|
968
1111
|
content: resultContent,
|
|
969
1112
|
modelName: rawResponse.model,
|
|
970
1113
|
timing: {
|
|
@@ -976,7 +1119,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
976
1119
|
rawRequest: rawRequest,
|
|
977
1120
|
rawResponse: rawResponse,
|
|
978
1121
|
// <- [🗯]
|
|
979
|
-
}];
|
|
1122
|
+
})];
|
|
980
1123
|
}
|
|
981
1124
|
});
|
|
982
1125
|
});
|
|
@@ -985,7 +1128,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
985
1128
|
TODO: [👏]
|
|
986
1129
|
public async callCompletionModel(
|
|
987
1130
|
prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
|
|
988
|
-
): Promise<
|
|
1131
|
+
): Promise<CompletionPromptResult> {
|
|
989
1132
|
|
|
990
1133
|
if (this.options.isVerbose) {
|
|
991
1134
|
console.info('🖋 Anthropic Claude callCompletionModel call');
|
|
@@ -1038,7 +1181,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1038
1181
|
|
|
1039
1182
|
|
|
1040
1183
|
|
|
1041
|
-
return {
|
|
1184
|
+
return $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools CompletionPromptResult',{
|
|
1042
1185
|
content: resultContent,
|
|
1043
1186
|
modelName: rawResponse.model || model,
|
|
1044
1187
|
timing: {
|
|
@@ -1048,7 +1191,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1048
1191
|
usage,
|
|
1049
1192
|
rawResponse,
|
|
1050
1193
|
// <- [🗯]
|
|
1051
|
-
};
|
|
1194
|
+
});
|
|
1052
1195
|
}
|
|
1053
1196
|
*/
|
|
1054
1197
|
// <- Note: [🤖] callXxxModel
|
|
@@ -1088,6 +1231,150 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
1088
1231
|
* TODO: [📅] Maybe instead of `RemoteLlmExecutionToolsOptions` use `proxyWithAnonymousRemoteServer` (if implemented)
|
|
1089
1232
|
*/
|
|
1090
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1236
|
+
*
|
|
1237
|
+
* @public exported from `@promptbook/core`
|
|
1238
|
+
*/
|
|
1239
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
1240
|
+
__extends(CollectionError, _super);
|
|
1241
|
+
function CollectionError(message) {
|
|
1242
|
+
var _this = _super.call(this, message) || this;
|
|
1243
|
+
_this.name = 'CollectionError';
|
|
1244
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1245
|
+
return _this;
|
|
1246
|
+
}
|
|
1247
|
+
return CollectionError;
|
|
1248
|
+
}(Error));
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1252
|
+
*
|
|
1253
|
+
* @public exported from `@promptbook/core`
|
|
1254
|
+
*/
|
|
1255
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
1256
|
+
__extends(EnvironmentMismatchError, _super);
|
|
1257
|
+
function EnvironmentMismatchError(message) {
|
|
1258
|
+
var _this = _super.call(this, message) || this;
|
|
1259
|
+
_this.name = 'EnvironmentMismatchError';
|
|
1260
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
1261
|
+
return _this;
|
|
1262
|
+
}
|
|
1263
|
+
return EnvironmentMismatchError;
|
|
1264
|
+
}(Error));
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* This error indicates that promptbook not found in the collection
|
|
1268
|
+
*
|
|
1269
|
+
* @public exported from `@promptbook/core`
|
|
1270
|
+
*/
|
|
1271
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
1272
|
+
__extends(NotFoundError, _super);
|
|
1273
|
+
function NotFoundError(message) {
|
|
1274
|
+
var _this = _super.call(this, message) || this;
|
|
1275
|
+
_this.name = 'NotFoundError';
|
|
1276
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1277
|
+
return _this;
|
|
1278
|
+
}
|
|
1279
|
+
return NotFoundError;
|
|
1280
|
+
}(Error));
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
1284
|
+
*
|
|
1285
|
+
* @public exported from `@promptbook/core`
|
|
1286
|
+
*/
|
|
1287
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1288
|
+
__extends(NotYetImplementedError, _super);
|
|
1289
|
+
function NotYetImplementedError(message) {
|
|
1290
|
+
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1291
|
+
_this.name = 'NotYetImplementedError';
|
|
1292
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1293
|
+
return _this;
|
|
1294
|
+
}
|
|
1295
|
+
return NotYetImplementedError;
|
|
1296
|
+
}(Error));
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
1300
|
+
*
|
|
1301
|
+
* @public exported from `@promptbook/core`
|
|
1302
|
+
*/
|
|
1303
|
+
var ParsingError = /** @class */ (function (_super) {
|
|
1304
|
+
__extends(ParsingError, _super);
|
|
1305
|
+
function ParsingError(message) {
|
|
1306
|
+
var _this = _super.call(this, message) || this;
|
|
1307
|
+
_this.name = 'ParsingError';
|
|
1308
|
+
Object.setPrototypeOf(_this, ParsingError.prototype);
|
|
1309
|
+
return _this;
|
|
1310
|
+
}
|
|
1311
|
+
return ParsingError;
|
|
1312
|
+
}(Error));
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
1316
|
+
*
|
|
1317
|
+
* @public exported from `@promptbook/core`
|
|
1318
|
+
*/
|
|
1319
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
1320
|
+
__extends(PipelineLogicError, _super);
|
|
1321
|
+
function PipelineLogicError(message) {
|
|
1322
|
+
var _this = _super.call(this, message) || this;
|
|
1323
|
+
_this.name = 'PipelineLogicError';
|
|
1324
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
1325
|
+
return _this;
|
|
1326
|
+
}
|
|
1327
|
+
return PipelineLogicError;
|
|
1328
|
+
}(Error));
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
1332
|
+
*
|
|
1333
|
+
* @public exported from `@promptbook/core`
|
|
1334
|
+
*/
|
|
1335
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
1336
|
+
__extends(PipelineUrlError, _super);
|
|
1337
|
+
function PipelineUrlError(message) {
|
|
1338
|
+
var _this = _super.call(this, message) || this;
|
|
1339
|
+
_this.name = 'PipelineUrlError';
|
|
1340
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
1341
|
+
return _this;
|
|
1342
|
+
}
|
|
1343
|
+
return PipelineUrlError;
|
|
1344
|
+
}(Error));
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Index of all custom errors
|
|
1348
|
+
*
|
|
1349
|
+
* @public exported from `@promptbook/core`
|
|
1350
|
+
*/
|
|
1351
|
+
var ERRORS = {
|
|
1352
|
+
CollectionError: CollectionError,
|
|
1353
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
1354
|
+
LimitReachedError: LimitReachedError,
|
|
1355
|
+
NotFoundError: NotFoundError,
|
|
1356
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
1357
|
+
ParsingError: ParsingError,
|
|
1358
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
1359
|
+
PipelineLogicError: PipelineLogicError,
|
|
1360
|
+
PipelineUrlError: PipelineUrlError,
|
|
1361
|
+
UnexpectedError: UnexpectedError,
|
|
1362
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Deserializes the error object
|
|
1367
|
+
*
|
|
1368
|
+
* @public exported from `@promptbook/utils`
|
|
1369
|
+
*/
|
|
1370
|
+
function deserializeError(error) {
|
|
1371
|
+
if (error.name === 'Error') {
|
|
1372
|
+
return new Error(error.message);
|
|
1373
|
+
}
|
|
1374
|
+
var CustomError = ERRORS[error.name];
|
|
1375
|
+
return new CustomError(error.message);
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1091
1378
|
/**
|
|
1092
1379
|
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
1093
1380
|
*
|
|
@@ -1148,13 +1435,13 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
1148
1435
|
socket.emit('listModels-request', {
|
|
1149
1436
|
isAnonymous: true,
|
|
1150
1437
|
llmToolsConfiguration: this.options.llmToolsConfiguration,
|
|
1151
|
-
});
|
|
1438
|
+
} /* <- TODO: [🤛] */);
|
|
1152
1439
|
}
|
|
1153
1440
|
else {
|
|
1154
1441
|
socket.emit('listModels-request', {
|
|
1155
1442
|
isAnonymous: false,
|
|
1156
1443
|
clientId: this.options.clientId,
|
|
1157
|
-
});
|
|
1444
|
+
} /* <- TODO: [🤛] */);
|
|
1158
1445
|
}
|
|
1159
1446
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
1160
1447
|
socket.on('listModels-response', function (response) {
|
|
@@ -1162,7 +1449,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
1162
1449
|
socket.disconnect();
|
|
1163
1450
|
});
|
|
1164
1451
|
socket.on('error', function (error) {
|
|
1165
|
-
reject(
|
|
1452
|
+
reject(deserializeError(error));
|
|
1166
1453
|
socket.disconnect();
|
|
1167
1454
|
});
|
|
1168
1455
|
})];
|
|
@@ -1241,16 +1528,14 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
1241
1528
|
isAnonymous: true,
|
|
1242
1529
|
llmToolsConfiguration: this.options.llmToolsConfiguration,
|
|
1243
1530
|
prompt: prompt,
|
|
1244
|
-
|
|
1245
|
-
});
|
|
1531
|
+
} /* <- TODO: [🤛] */);
|
|
1246
1532
|
}
|
|
1247
1533
|
else {
|
|
1248
1534
|
socket.emit('prompt-request', {
|
|
1249
1535
|
isAnonymous: false,
|
|
1250
1536
|
clientId: this.options.clientId,
|
|
1251
1537
|
prompt: prompt,
|
|
1252
|
-
|
|
1253
|
-
});
|
|
1538
|
+
} /* <- TODO: [🤛] */);
|
|
1254
1539
|
}
|
|
1255
1540
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
1256
1541
|
socket.on('prompt-response', function (response) {
|
|
@@ -1258,7 +1543,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
1258
1543
|
socket.disconnect();
|
|
1259
1544
|
});
|
|
1260
1545
|
socket.on('error', function (error) {
|
|
1261
|
-
reject(
|
|
1546
|
+
reject(deserializeError(error));
|
|
1262
1547
|
socket.disconnect();
|
|
1263
1548
|
});
|
|
1264
1549
|
})];
|
|
@@ -1273,6 +1558,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
1273
1558
|
return RemoteLlmExecutionTools;
|
|
1274
1559
|
}());
|
|
1275
1560
|
/**
|
|
1561
|
+
* TODO: Maybe use `$asDeeplyFrozenSerializableJson`
|
|
1276
1562
|
* TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
|
|
1277
1563
|
* TODO: [🍓] Allow to list compatible models with each variant
|
|
1278
1564
|
* TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
|
|
@@ -1314,14 +1600,11 @@ var createAnthropicClaudeExecutionTools = Object.assign(function (options) {
|
|
|
1314
1600
|
*
|
|
1315
1601
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
1316
1602
|
*
|
|
1317
|
-
*
|
|
1603
|
+
* @private internal function of `$Register`
|
|
1318
1604
|
*/
|
|
1319
1605
|
function $getGlobalScope() {
|
|
1320
1606
|
return Function('return this')();
|
|
1321
1607
|
}
|
|
1322
|
-
/***
|
|
1323
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
1324
|
-
*/
|
|
1325
1608
|
|
|
1326
1609
|
/**
|
|
1327
1610
|
* Register is @@@
|