@promptbook/google
Advanced tools
Comparing version 0.79.0 to 0.80.0-0
@@ -16,3 +16,3 @@ import colors from 'colors'; | ||
*/ | ||
var PROMPTBOOK_ENGINE_VERSION = '0.78.4'; | ||
var PROMPTBOOK_ENGINE_VERSION = '0.79.0'; | ||
/** | ||
@@ -168,3 +168,3 @@ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine | ||
/** | ||
* @@@ | ||
* Freezes the given object and all its nested objects recursively | ||
* | ||
@@ -199,3 +199,4 @@ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object | ||
} | ||
return Object.freeze(objectValue); | ||
Object.freeze(objectValue); | ||
return objectValue; | ||
} | ||
@@ -301,20 +302,2 @@ /** | ||
var LOOP_LIMIT = 1000; | ||
/** | ||
* Nonce which is used for replacing things in strings | ||
* | ||
* @private within the repository | ||
*/ | ||
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW'; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE; | ||
// <- TODO: [๐งโโ๏ธ] | ||
@@ -333,3 +316,2 @@ /** | ||
/** | ||
* TODO: Extract `constants.ts` from `config.ts` | ||
* Note: [๐] Ignore a discrepancy between file name and entity name | ||
@@ -340,16 +322,12 @@ * TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteUrl and path into single value | ||
/** | ||
* This error type indicates that some limit was reached | ||
* Orders JSON object by keys | ||
* | ||
* @public exported from `@promptbook/core` | ||
* @returns The same type of object as the input re-ordered | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
var LimitReachedError = /** @class */ (function (_super) { | ||
__extends(LimitReachedError, _super); | ||
function LimitReachedError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'LimitReachedError'; | ||
Object.setPrototypeOf(_this, LimitReachedError.prototype); | ||
return _this; | ||
} | ||
return LimitReachedError; | ||
}(Error)); | ||
function orderJson(options) { | ||
var value = options.value, order = options.order; | ||
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value); | ||
return orderedValue; | ||
} | ||
@@ -391,81 +369,2 @@ /** | ||
/** | ||
* Replaces parameters in template with values from parameters object | ||
* | ||
* @param template the template with parameters in {curly} braces | ||
* @param parameters the object with parameters | ||
* @returns the template with replaced parameters | ||
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function replaceParameters(template, parameters) { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1]; | ||
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) { | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value")); | ||
} | ||
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) { | ||
// TODO: [๐ต] | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use")); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
var replacedTemplates = template; | ||
var match; | ||
var loopLimit = LOOP_LIMIT; | ||
var _loop_1 = function () { | ||
if (loopLimit-- < 0) { | ||
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`'); | ||
} | ||
var precol = match.groups.precol; | ||
var parameterName = match.groups.parameterName; | ||
if (parameterName === '') { | ||
return "continue"; | ||
} | ||
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) { | ||
throw new PipelineExecutionError('Parameter is already opened or not closed'); | ||
} | ||
if (parameters[parameterName] === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
var parameterValue = parameters[parameterName]; | ||
if (parameterValue === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
parameterValue = parameterValue.toString(); | ||
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) { | ||
parameterValue = parameterValue | ||
.split('\n') | ||
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); }) | ||
.join('\n'); | ||
} | ||
replacedTemplates = | ||
replacedTemplates.substring(0, match.index + precol.length) + | ||
parameterValue + | ||
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2); | ||
}; | ||
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */ | ||
.exec(replacedTemplates))) { | ||
_loop_1(); | ||
} | ||
// [๐ซ] Check if there are parameters that are not closed properly | ||
if (/{\w+$/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not closed'); | ||
} | ||
// [๐ซ] Check if there are parameters that are not opened properly | ||
if (/^\w+}/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not opened'); | ||
} | ||
return replacedTemplates; | ||
} | ||
/** | ||
* Checks if the value is [๐] serializable as JSON | ||
@@ -490,4 +389,5 @@ * If not, throws an UnexpectedError with a rich error message and tracking | ||
*/ | ||
function checkSerializableAsJson(name, value) { | ||
function checkSerializableAsJson(options) { | ||
var e_1, _a; | ||
var value = options.value, name = options.name, message = options.message; | ||
if (value === undefined) { | ||
@@ -516,3 +416,3 @@ throw new UnexpectedError("".concat(name, " is undefined")); | ||
for (var i = 0; i < value.length; i++) { | ||
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]); | ||
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message }); | ||
} | ||
@@ -522,3 +422,3 @@ } | ||
if (value instanceof Date) { | ||
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n "))); | ||
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
@@ -535,3 +435,3 @@ else if (value instanceof Map) { | ||
else if (value instanceof Error) { | ||
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n "))); | ||
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); })); | ||
} | ||
@@ -546,3 +446,3 @@ else { | ||
} | ||
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue); | ||
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message }); | ||
} | ||
@@ -564,3 +464,3 @@ } | ||
} | ||
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); })); | ||
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
@@ -590,7 +490,7 @@ /* | ||
else { | ||
throw new UnexpectedError("".concat(name, " is unknown")); | ||
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
} | ||
/** | ||
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name` | ||
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue` | ||
* TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks | ||
@@ -602,17 +502,55 @@ * Note: [๐ ] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message | ||
* @@@ | ||
* @@@ | ||
* | ||
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function deepClone(objectValue) { | ||
return JSON.parse(JSON.stringify(objectValue)); | ||
/* | ||
!!!!!!!! | ||
TODO: [๐ง ] Is there a better implementation? | ||
> const propertyNames = Object.getOwnPropertyNames(objectValue); | ||
> for (const propertyName of propertyNames) { | ||
> const value = (objectValue as really_any)[propertyName]; | ||
> if (value && typeof value === 'object') { | ||
> deepClone(value); | ||
> } | ||
> } | ||
> return Object.assign({}, objectValue); | ||
*/ | ||
} | ||
/** | ||
* TODO: [๐ง ] Is there a way how to meaningfully test this utility | ||
*/ | ||
/** | ||
* Utility to export a JSON object from a function | ||
* | ||
* @param name - Name of the object for debugging purposes | ||
* @param objectValue - Object to be deeply frozen | ||
* @returns The same object as the input, but deeply frozen | ||
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations | ||
* 1) Checks if the value is serializable as JSON | ||
* 2) Makes a deep clone of the object | ||
* 2) Orders the object properties | ||
* 2) Deeply freezes the cloned object | ||
* | ||
* Note: This function does not mutates the given object | ||
* | ||
* @returns The same type of object as the input but read-only and re-ordered | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function $asDeeplyFrozenSerializableJson(name, objectValue) { | ||
checkSerializableAsJson(name, objectValue); | ||
return $deepFreeze(objectValue); | ||
function exportJson(options) { | ||
var name = options.name, value = options.value, order = options.order, message = options.message; | ||
checkSerializableAsJson({ name: name, value: value, message: message }); | ||
var orderedValue = | ||
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite." | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
order === undefined | ||
? deepClone(value) | ||
: orderJson({ | ||
value: value, | ||
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON | ||
order: order, | ||
}); | ||
$deepFreeze(orderedValue); | ||
return orderedValue; | ||
} | ||
/** | ||
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name` | ||
* TODO: [๐ง ] Is there a way how to meaningfully test this utility | ||
@@ -622,2 +560,139 @@ */ | ||
/** | ||
* Nonce which is used for replacing things in strings | ||
* | ||
* @private within the repository | ||
*/ | ||
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW'; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE; | ||
/** | ||
* The names of the parameters that are reserved for special purposes | ||
* | ||
* @public exported from `@promptbook/core` | ||
*/ | ||
exportJson({ | ||
name: 'RESERVED_PARAMETER_NAMES', | ||
message: "The names of the parameters that are reserved for special purposes", | ||
value: [ | ||
'content', | ||
'context', | ||
'knowledge', | ||
'examples', | ||
'modelName', | ||
'currentDate', | ||
// <- TODO: list here all command names | ||
// <- TODO: Add more like 'date', 'modelName',... | ||
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter | ||
], | ||
}); | ||
/** | ||
* Note: [๐] Ignore a discrepancy between file name and entity name | ||
*/ | ||
/** | ||
* This error type indicates that some limit was reached | ||
* | ||
* @public exported from `@promptbook/core` | ||
*/ | ||
var LimitReachedError = /** @class */ (function (_super) { | ||
__extends(LimitReachedError, _super); | ||
function LimitReachedError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'LimitReachedError'; | ||
Object.setPrototypeOf(_this, LimitReachedError.prototype); | ||
return _this; | ||
} | ||
return LimitReachedError; | ||
}(Error)); | ||
/** | ||
* Replaces parameters in template with values from parameters object | ||
* | ||
* @param template the template with parameters in {curly} braces | ||
* @param parameters the object with parameters | ||
* @returns the template with replaced parameters | ||
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function replaceParameters(template, parameters) { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1]; | ||
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) { | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value")); | ||
} | ||
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) { | ||
// TODO: [๐ต] | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use")); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
var replacedTemplates = template; | ||
var match; | ||
var loopLimit = LOOP_LIMIT; | ||
var _loop_1 = function () { | ||
if (loopLimit-- < 0) { | ||
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`'); | ||
} | ||
var precol = match.groups.precol; | ||
var parameterName = match.groups.parameterName; | ||
if (parameterName === '') { | ||
return "continue"; | ||
} | ||
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) { | ||
throw new PipelineExecutionError('Parameter is already opened or not closed'); | ||
} | ||
if (parameters[parameterName] === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
var parameterValue = parameters[parameterName]; | ||
if (parameterValue === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
parameterValue = parameterValue.toString(); | ||
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) { | ||
parameterValue = parameterValue | ||
.split('\n') | ||
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); }) | ||
.join('\n'); | ||
} | ||
replacedTemplates = | ||
replacedTemplates.substring(0, match.index + precol.length) + | ||
parameterValue + | ||
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2); | ||
}; | ||
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */ | ||
.exec(replacedTemplates))) { | ||
_loop_1(); | ||
} | ||
// [๐ซ] Check if there are parameters that are not closed properly | ||
if (/{\w+$/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not closed'); | ||
} | ||
// [๐ซ] Check if there are parameters that are not opened properly | ||
if (/^\w+}/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not opened'); | ||
} | ||
return replacedTemplates; | ||
} | ||
/** | ||
* Function `asSerializable` will convert values which are not serializable to serializable values | ||
@@ -701,3 +776,3 @@ * It walks deeply through the object and converts all values | ||
if (!modelName) { | ||
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n ")); | ||
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n\n ")); | ||
} | ||
@@ -765,14 +840,18 @@ return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))]; | ||
usage = UNCERTAIN_USAGE; | ||
return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', { | ||
content: rawResponse.text, | ||
modelName: modelName, | ||
timing: { | ||
start: start, | ||
complete: complete, | ||
return [2 /*return*/, exportJson({ | ||
name: 'promptResult', | ||
message: "Result of `createExecutionToolsFromVercelProvider.callChatModel`", | ||
value: { | ||
content: rawResponse.text, | ||
modelName: modelName, | ||
timing: { | ||
start: start, | ||
complete: complete, | ||
}, | ||
usage: usage, | ||
rawPromptContent: rawPromptContent, | ||
rawRequest: rawRequest, | ||
rawResponse: asSerializable(rawResponse), | ||
// <- [๐ฏ] | ||
}, | ||
usage: usage, | ||
rawPromptContent: rawPromptContent, | ||
rawRequest: rawRequest, | ||
rawResponse: asSerializable(rawResponse), | ||
// <- [๐ฏ] | ||
})]; | ||
@@ -779,0 +858,0 @@ } |
@@ -19,6 +19,6 @@ declare const _default: ({ | ||
}[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
knowledgeSources: never[]; | ||
knowledgePieces: never[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
sourceFile: string; | ||
@@ -49,6 +49,6 @@ } | { | ||
}[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
knowledgeSources: never[]; | ||
knowledgePieces: never[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
sourceFile: string; | ||
@@ -74,8 +74,8 @@ } | { | ||
}[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
knowledgeSources: never[]; | ||
knowledgePieces: never[]; | ||
personas: never[]; | ||
preparations: never[]; | ||
sourceFile: string; | ||
})[]; | ||
export default _default; |
@@ -24,3 +24,2 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version'; | ||
import { DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME } from '../config'; | ||
import { RESERVED_PARAMETER_NAMES } from '../config'; | ||
import { DEFAULT_REMOTE_URL } from '../config'; | ||
@@ -32,2 +31,4 @@ import { DEFAULT_REMOTE_URL_PATH } from '../config'; | ||
import { DEFAULT_IS_AUTO_INSTALLED } from '../config'; | ||
import { ORDER_OF_PIPELINE_JSON } from '../constants'; | ||
import { RESERVED_PARAMETER_NAMES } from '../constants'; | ||
import { pipelineJsonToString } from '../conversion/pipelineJsonToString'; | ||
@@ -146,3 +147,2 @@ import { pipelineStringToJson } from '../conversion/pipelineStringToJson'; | ||
export { DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME }; | ||
export { RESERVED_PARAMETER_NAMES }; | ||
export { DEFAULT_REMOTE_URL }; | ||
@@ -154,2 +154,4 @@ export { DEFAULT_REMOTE_URL_PATH }; | ||
export { DEFAULT_IS_AUTO_INSTALLED }; | ||
export { ORDER_OF_PIPELINE_JSON }; | ||
export { RESERVED_PARAMETER_NAMES }; | ||
export { pipelineJsonToString }; | ||
@@ -156,0 +158,0 @@ export { pipelineStringToJson }; |
@@ -49,2 +49,4 @@ import type { PipelineCollection } from '../collection/PipelineCollection'; | ||
import type { string_formfactor_name } from '../formfactors/_common/string_formfactor_name'; | ||
import type { AsyncHighLevelAbstraction } from '../high-level-abstractions/_common/HighLevelAbstraction'; | ||
import type { CommonHighLevelAbstraction } from '../high-level-abstractions/_common/HighLevelAbstraction'; | ||
import type { LlmToolsConfiguration } from '../llm-providers/_common/register/LlmToolsConfiguration'; | ||
@@ -257,5 +259,8 @@ import type { LlmToolsMetadata } from '../llm-providers/_common/register/LlmToolsMetadata'; | ||
import type { string_snake_case } from '../utils/normalization/normalizeTo_snake_case'; | ||
import type { OrderJsonOptions } from '../utils/normalization/orderJson'; | ||
import type { empty_object } from '../utils/organization/empty_object'; | ||
import type { really_any } from '../utils/organization/really_any'; | ||
import type { TODO_any } from '../utils/organization/TODO_any'; | ||
import type { CheckSerializableAsJsonOptions } from '../utils/serialization/checkSerializableAsJson'; | ||
import type { ExportJsonOptions } from '../utils/serialization/exportJson'; | ||
import type { string_promptbook_version } from '../version'; | ||
@@ -310,2 +315,4 @@ export type { PipelineCollection }; | ||
export type { string_formfactor_name }; | ||
export type { AsyncHighLevelAbstraction }; | ||
export type { CommonHighLevelAbstraction }; | ||
export type { LlmToolsConfiguration }; | ||
@@ -518,5 +525,8 @@ export type { LlmToolsMetadata }; | ||
export type { string_snake_case }; | ||
export type { OrderJsonOptions }; | ||
export type { empty_object }; | ||
export type { really_any }; | ||
export type { TODO_any }; | ||
export type { CheckSerializableAsJsonOptions }; | ||
export type { ExportJsonOptions }; | ||
export type { string_promptbook_version }; |
@@ -41,2 +41,3 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version'; | ||
import { normalizeWhitespaces } from '../utils/normalization/normalizeWhitespaces'; | ||
import { orderJson } from '../utils/normalization/orderJson'; | ||
import { parseKeywords } from '../utils/normalization/parseKeywords'; | ||
@@ -58,2 +59,3 @@ import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString'; | ||
import { deepClone } from '../utils/serialization/deepClone'; | ||
import { exportJson } from '../utils/serialization/exportJson'; | ||
import { isSerializableAsJson } from '../utils/serialization/isSerializableAsJson'; | ||
@@ -116,2 +118,3 @@ import { difference } from '../utils/sets/difference'; | ||
export { normalizeWhitespaces }; | ||
export { orderJson }; | ||
export { parseKeywords }; | ||
@@ -133,2 +136,3 @@ export { parseKeywordsFromString }; | ||
export { deepClone }; | ||
export { exportJson }; | ||
export { isSerializableAsJson }; | ||
@@ -135,0 +139,0 @@ export { difference }; |
@@ -68,2 +68,3 @@ import type { SetOptional, WritableDeep } from 'type-fest'; | ||
* Note: This is used in `pipelineJsonToString` utility | ||
* @deprecated TODO: [๐ฅ][๐ง ] Backup original files in `PipelineJson` same as in Promptbook.studio | ||
*/ | ||
@@ -98,2 +99,3 @@ stringify(command: TCommand): string_markdown_text; | ||
* Note: This is used in `pipelineJsonToString` utility | ||
* @deprecated TODO: [๐ฅ][๐ง ] Backup original files in `PipelineJson` same as in Promptbook.studio | ||
*/ | ||
@@ -188,2 +190,3 @@ takeFromPipelineJson(pipelineJson: PipelineJson): ReadonlyArray<TCommand>; | ||
* TODO: [โ๏ธ] Add order here | ||
* TODO: [๐ง ][๐ฑ] Maybe make some common abstraction between `HighLevelAbstraction` and `CommandParser` | ||
*/ |
@@ -166,26 +166,2 @@ import type { CsvSettings } from './formats/csv/CsvSettings'; | ||
/** | ||
* Nonce which is used for replacing things in strings | ||
* | ||
* @private within the repository | ||
*/ | ||
export declare const REPLACING_NONCE = "u$k42k%!V2zo34w7Fu#@QUHYPW"; | ||
/** | ||
* The names of the parameters that are reserved for special purposes | ||
* | ||
* @public exported from `@promptbook/core` | ||
*/ | ||
export declare const RESERVED_PARAMETER_NAMES: readonly ["content", "context", "knowledge", "examples", "modelName", "currentDate"]; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
export declare const RESERVED_PARAMETER_MISSING_VALUE: string; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
export declare const RESERVED_PARAMETER_RESTRICTED: string; | ||
/** | ||
* The thresholds for the relative time in the `moment` NPM package. | ||
@@ -250,5 +226,4 @@ * | ||
/** | ||
* TODO: Extract `constants.ts` from `config.ts` | ||
* Note: [๐] Ignore a discrepancy between file name and entity name | ||
* TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteUrl and path into single value | ||
*/ |
@@ -6,2 +6,3 @@ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson'; | ||
* | ||
* @deprecated TODO: [๐ฅ][๐ง ] Backup original files in `PipelineJson` same as in Promptbook.studio | ||
* @param pipelineJson Promptbook in JSON format (.book.json) | ||
@@ -8,0 +9,0 @@ * @returns Promptbook in string format (.book.md) |
@@ -21,2 +21,3 @@ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson'; | ||
/** | ||
* TODO: [๐ง ] Maybe more things here can be refactored as high-level abstractions | ||
* TODO: [main] !!!! Warn if used only sync version | ||
@@ -23,0 +24,0 @@ * TODO: [๐] Report here line/column of error |
@@ -57,3 +57,3 @@ import type { AvailableModel } from '../../execution/AvailableModel'; | ||
/** | ||
* TODO: Maybe use `$asDeeplyFrozenSerializableJson` | ||
* TODO: Maybe use `$exportJson` | ||
* TODO: [๐ง ][๐] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'` | ||
@@ -60,0 +60,0 @@ * TODO: [๐] Allow to list compatible models with each variant |
@@ -14,3 +14,3 @@ import type { IDestroyable } from 'destroyable'; | ||
/** | ||
* TODO: Maybe use `$asDeeplyFrozenSerializableJson` | ||
* TODO: Maybe use `$exportJson` | ||
* TODO: [๐ง ][๐] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'` | ||
@@ -17,0 +17,0 @@ * TODO: [โ] Expose the collection to be able to connect to same collection via createCollectionFromUrl |
@@ -25,2 +25,3 @@ import type { ExecutionTools } from '../execution/ExecutionTools'; | ||
/** | ||
* TODO: [๐] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions | ||
* TODO: [๐ง ] Add context to each task (if missing) | ||
@@ -27,0 +28,0 @@ * TODO: [๐ง ] What is better name `prepareTask` or `prepareTaskAndParameters` |
import type { TupleToUnion } from 'type-fest'; | ||
import { RESERVED_PARAMETER_NAMES } from '../config'; | ||
import { RESERVED_PARAMETER_NAMES } from '../constants'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Semantic helper |
import type { ReadonlyDeep } from 'type-fest'; | ||
/** | ||
* @@@ | ||
* Freezes the given object and all its nested objects recursively | ||
* | ||
@@ -5,0 +5,0 @@ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object |
import type { string_name } from '../../types/typeAliases'; | ||
import type { really_unknown } from '../organization/really_unknown'; | ||
/** | ||
* Options for the `checkSerializableAsJson` function | ||
*/ | ||
export type CheckSerializableAsJsonOptions = { | ||
/** | ||
* Value to be checked | ||
*/ | ||
value: really_unknown; | ||
/** | ||
* Semantic name of the value for debugging purposes | ||
*/ | ||
name?: string_name; | ||
/** | ||
* Message alongside the value for debugging purposes | ||
*/ | ||
message?: string; | ||
}; | ||
/** | ||
* Checks if the value is [๐] serializable as JSON | ||
@@ -22,7 +40,7 @@ * If not, throws an UnexpectedError with a rich error message and tracking | ||
*/ | ||
export declare function checkSerializableAsJson(name: string_name, value: unknown): void; | ||
export declare function checkSerializableAsJson(options: CheckSerializableAsJsonOptions): void; | ||
/** | ||
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name` | ||
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue` | ||
* TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks | ||
* Note: [๐ ] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message | ||
*/ |
@@ -0,1 +1,2 @@ | ||
import { JsonValue } from 'type-fest'; | ||
/** | ||
@@ -20,3 +21,3 @@ * Tests if the value is [๐] serializable as JSON | ||
*/ | ||
export declare function isSerializableAsJson(value: unknown): boolean; | ||
export declare function isSerializableAsJson(value: unknown): value is JsonValue; | ||
/** | ||
@@ -23,0 +24,0 @@ * TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks |
{ | ||
"name": "@promptbook/google", | ||
"version": "0.79.0", | ||
"version": "0.80.0-0", | ||
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin", | ||
@@ -57,3 +57,3 @@ "--note-0": " <- [๐]", | ||
"peerDependencies": { | ||
"@promptbook/core": "0.79.0" | ||
"@promptbook/core": "0.80.0-0" | ||
}, | ||
@@ -60,0 +60,0 @@ "dependencies": { |
@@ -26,2 +26,6 @@ <!-- โ ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten --> | ||
<blockquote style="color: #ff8811"> | ||
<b>โ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>. | ||
</blockquote> | ||
## ๐ฆ Package `@promptbook/google` | ||
@@ -28,0 +32,0 @@ |
@@ -24,3 +24,3 @@ (function (global, factory) { | ||
*/ | ||
var PROMPTBOOK_ENGINE_VERSION = '0.78.4'; | ||
var PROMPTBOOK_ENGINE_VERSION = '0.79.0'; | ||
/** | ||
@@ -176,3 +176,3 @@ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine | ||
/** | ||
* @@@ | ||
* Freezes the given object and all its nested objects recursively | ||
* | ||
@@ -207,3 +207,4 @@ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object | ||
} | ||
return Object.freeze(objectValue); | ||
Object.freeze(objectValue); | ||
return objectValue; | ||
} | ||
@@ -309,20 +310,2 @@ /** | ||
var LOOP_LIMIT = 1000; | ||
/** | ||
* Nonce which is used for replacing things in strings | ||
* | ||
* @private within the repository | ||
*/ | ||
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW'; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE; | ||
// <- TODO: [๐งโโ๏ธ] | ||
@@ -341,3 +324,2 @@ /** | ||
/** | ||
* TODO: Extract `constants.ts` from `config.ts` | ||
* Note: [๐] Ignore a discrepancy between file name and entity name | ||
@@ -348,16 +330,12 @@ * TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteUrl and path into single value | ||
/** | ||
* This error type indicates that some limit was reached | ||
* Orders JSON object by keys | ||
* | ||
* @public exported from `@promptbook/core` | ||
* @returns The same type of object as the input re-ordered | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
var LimitReachedError = /** @class */ (function (_super) { | ||
__extends(LimitReachedError, _super); | ||
function LimitReachedError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'LimitReachedError'; | ||
Object.setPrototypeOf(_this, LimitReachedError.prototype); | ||
return _this; | ||
} | ||
return LimitReachedError; | ||
}(Error)); | ||
function orderJson(options) { | ||
var value = options.value, order = options.order; | ||
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value); | ||
return orderedValue; | ||
} | ||
@@ -399,81 +377,2 @@ /** | ||
/** | ||
* Replaces parameters in template with values from parameters object | ||
* | ||
* @param template the template with parameters in {curly} braces | ||
* @param parameters the object with parameters | ||
* @returns the template with replaced parameters | ||
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function replaceParameters(template, parameters) { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1]; | ||
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) { | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value")); | ||
} | ||
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) { | ||
// TODO: [๐ต] | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use")); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
var replacedTemplates = template; | ||
var match; | ||
var loopLimit = LOOP_LIMIT; | ||
var _loop_1 = function () { | ||
if (loopLimit-- < 0) { | ||
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`'); | ||
} | ||
var precol = match.groups.precol; | ||
var parameterName = match.groups.parameterName; | ||
if (parameterName === '') { | ||
return "continue"; | ||
} | ||
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) { | ||
throw new PipelineExecutionError('Parameter is already opened or not closed'); | ||
} | ||
if (parameters[parameterName] === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
var parameterValue = parameters[parameterName]; | ||
if (parameterValue === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
parameterValue = parameterValue.toString(); | ||
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) { | ||
parameterValue = parameterValue | ||
.split('\n') | ||
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); }) | ||
.join('\n'); | ||
} | ||
replacedTemplates = | ||
replacedTemplates.substring(0, match.index + precol.length) + | ||
parameterValue + | ||
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2); | ||
}; | ||
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */ | ||
.exec(replacedTemplates))) { | ||
_loop_1(); | ||
} | ||
// [๐ซ] Check if there are parameters that are not closed properly | ||
if (/{\w+$/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not closed'); | ||
} | ||
// [๐ซ] Check if there are parameters that are not opened properly | ||
if (/^\w+}/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not opened'); | ||
} | ||
return replacedTemplates; | ||
} | ||
/** | ||
* Checks if the value is [๐] serializable as JSON | ||
@@ -498,4 +397,5 @@ * If not, throws an UnexpectedError with a rich error message and tracking | ||
*/ | ||
function checkSerializableAsJson(name, value) { | ||
function checkSerializableAsJson(options) { | ||
var e_1, _a; | ||
var value = options.value, name = options.name, message = options.message; | ||
if (value === undefined) { | ||
@@ -524,3 +424,3 @@ throw new UnexpectedError("".concat(name, " is undefined")); | ||
for (var i = 0; i < value.length; i++) { | ||
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]); | ||
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message }); | ||
} | ||
@@ -530,3 +430,3 @@ } | ||
if (value instanceof Date) { | ||
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n "))); | ||
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
@@ -543,3 +443,3 @@ else if (value instanceof Map) { | ||
else if (value instanceof Error) { | ||
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n "))); | ||
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); })); | ||
} | ||
@@ -554,3 +454,3 @@ else { | ||
} | ||
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue); | ||
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message }); | ||
} | ||
@@ -572,3 +472,3 @@ } | ||
} | ||
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); })); | ||
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
@@ -598,7 +498,7 @@ /* | ||
else { | ||
throw new UnexpectedError("".concat(name, " is unknown")); | ||
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); })); | ||
} | ||
} | ||
/** | ||
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name` | ||
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue` | ||
* TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks | ||
@@ -610,17 +510,55 @@ * Note: [๐ ] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message | ||
* @@@ | ||
* @@@ | ||
* | ||
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function deepClone(objectValue) { | ||
return JSON.parse(JSON.stringify(objectValue)); | ||
/* | ||
!!!!!!!! | ||
TODO: [๐ง ] Is there a better implementation? | ||
> const propertyNames = Object.getOwnPropertyNames(objectValue); | ||
> for (const propertyName of propertyNames) { | ||
> const value = (objectValue as really_any)[propertyName]; | ||
> if (value && typeof value === 'object') { | ||
> deepClone(value); | ||
> } | ||
> } | ||
> return Object.assign({}, objectValue); | ||
*/ | ||
} | ||
/** | ||
* TODO: [๐ง ] Is there a way how to meaningfully test this utility | ||
*/ | ||
/** | ||
* Utility to export a JSON object from a function | ||
* | ||
* @param name - Name of the object for debugging purposes | ||
* @param objectValue - Object to be deeply frozen | ||
* @returns The same object as the input, but deeply frozen | ||
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations | ||
* 1) Checks if the value is serializable as JSON | ||
* 2) Makes a deep clone of the object | ||
* 2) Orders the object properties | ||
* 2) Deeply freezes the cloned object | ||
* | ||
* Note: This function does not mutates the given object | ||
* | ||
* @returns The same type of object as the input but read-only and re-ordered | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function $asDeeplyFrozenSerializableJson(name, objectValue) { | ||
checkSerializableAsJson(name, objectValue); | ||
return $deepFreeze(objectValue); | ||
function exportJson(options) { | ||
var name = options.name, value = options.value, order = options.order, message = options.message; | ||
checkSerializableAsJson({ name: name, value: value, message: message }); | ||
var orderedValue = | ||
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite." | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
order === undefined | ||
? deepClone(value) | ||
: orderJson({ | ||
value: value, | ||
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON | ||
order: order, | ||
}); | ||
$deepFreeze(orderedValue); | ||
return orderedValue; | ||
} | ||
/** | ||
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name` | ||
* TODO: [๐ง ] Is there a way how to meaningfully test this utility | ||
@@ -630,2 +568,139 @@ */ | ||
/** | ||
* Nonce which is used for replacing things in strings | ||
* | ||
* @private within the repository | ||
*/ | ||
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW'; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE; | ||
/** | ||
* @@@ | ||
* | ||
* @private within the repository | ||
*/ | ||
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE; | ||
/** | ||
* The names of the parameters that are reserved for special purposes | ||
* | ||
* @public exported from `@promptbook/core` | ||
*/ | ||
exportJson({ | ||
name: 'RESERVED_PARAMETER_NAMES', | ||
message: "The names of the parameters that are reserved for special purposes", | ||
value: [ | ||
'content', | ||
'context', | ||
'knowledge', | ||
'examples', | ||
'modelName', | ||
'currentDate', | ||
// <- TODO: list here all command names | ||
// <- TODO: Add more like 'date', 'modelName',... | ||
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter | ||
], | ||
}); | ||
/** | ||
* Note: [๐] Ignore a discrepancy between file name and entity name | ||
*/ | ||
/** | ||
* This error type indicates that some limit was reached | ||
* | ||
* @public exported from `@promptbook/core` | ||
*/ | ||
var LimitReachedError = /** @class */ (function (_super) { | ||
__extends(LimitReachedError, _super); | ||
function LimitReachedError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = 'LimitReachedError'; | ||
Object.setPrototypeOf(_this, LimitReachedError.prototype); | ||
return _this; | ||
} | ||
return LimitReachedError; | ||
}(Error)); | ||
/** | ||
* Replaces parameters in template with values from parameters object | ||
* | ||
* @param template the template with parameters in {curly} braces | ||
* @param parameters the object with parameters | ||
* @returns the template with replaced parameters | ||
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened | ||
* @public exported from `@promptbook/utils` | ||
*/ | ||
function replaceParameters(template, parameters) { | ||
var e_1, _a; | ||
try { | ||
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1]; | ||
if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) { | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value")); | ||
} | ||
else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) { | ||
// TODO: [๐ต] | ||
throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use")); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
var replacedTemplates = template; | ||
var match; | ||
var loopLimit = LOOP_LIMIT; | ||
var _loop_1 = function () { | ||
if (loopLimit-- < 0) { | ||
throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`'); | ||
} | ||
var precol = match.groups.precol; | ||
var parameterName = match.groups.parameterName; | ||
if (parameterName === '') { | ||
return "continue"; | ||
} | ||
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) { | ||
throw new PipelineExecutionError('Parameter is already opened or not closed'); | ||
} | ||
if (parameters[parameterName] === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
var parameterValue = parameters[parameterName]; | ||
if (parameterValue === undefined) { | ||
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined")); | ||
} | ||
parameterValue = parameterValue.toString(); | ||
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) { | ||
parameterValue = parameterValue | ||
.split('\n') | ||
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); }) | ||
.join('\n'); | ||
} | ||
replacedTemplates = | ||
replacedTemplates.substring(0, match.index + precol.length) + | ||
parameterValue + | ||
replacedTemplates.substring(match.index + precol.length + parameterName.length + 2); | ||
}; | ||
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */ | ||
.exec(replacedTemplates))) { | ||
_loop_1(); | ||
} | ||
// [๐ซ] Check if there are parameters that are not closed properly | ||
if (/{\w+$/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not closed'); | ||
} | ||
// [๐ซ] Check if there are parameters that are not opened properly | ||
if (/^\w+}/.test(replacedTemplates)) { | ||
throw new PipelineExecutionError('Parameter is not opened'); | ||
} | ||
return replacedTemplates; | ||
} | ||
/** | ||
* Function `asSerializable` will convert values which are not serializable to serializable values | ||
@@ -709,3 +784,3 @@ * It walks deeply through the object and converts all values | ||
if (!modelName) { | ||
throw new PipelineExecutionError(spaceTrim__default["default"]("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n ")); | ||
throw new PipelineExecutionError(spaceTrim__default["default"]("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n\n ")); | ||
} | ||
@@ -773,14 +848,18 @@ return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))]; | ||
usage = UNCERTAIN_USAGE; | ||
return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', { | ||
content: rawResponse.text, | ||
modelName: modelName, | ||
timing: { | ||
start: start, | ||
complete: complete, | ||
return [2 /*return*/, exportJson({ | ||
name: 'promptResult', | ||
message: "Result of `createExecutionToolsFromVercelProvider.callChatModel`", | ||
value: { | ||
content: rawResponse.text, | ||
modelName: modelName, | ||
timing: { | ||
start: start, | ||
complete: complete, | ||
}, | ||
usage: usage, | ||
rawPromptContent: rawPromptContent, | ||
rawRequest: rawRequest, | ||
rawResponse: asSerializable(rawResponse), | ||
// <- [๐ฏ] | ||
}, | ||
usage: usage, | ||
rawPromptContent: rawPromptContent, | ||
rawRequest: rawRequest, | ||
rawResponse: asSerializable(rawResponse), | ||
// <- [๐ฏ] | ||
})]; | ||
@@ -787,0 +866,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
715394
631
13960
586