@promptbook/wizard 0.102.0-2 → 0.102.0-4
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 +80 -39
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +15 -13
- package/esm/typings/src/_packages/types.index.d.ts +3 -3
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +14 -1
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/save/_common/getChatSaveFormatDefinitions.d.ts +8 -0
- package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/save/index.d.ts +39 -0
- package/esm/typings/src/book-components/Chat/save/json/jsonSaveFormatDefinition.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/save/text/txtSaveFormatDefinition.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +31 -5
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +3 -3
- package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +4 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +80 -39
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-components/Chat/save/savePlugins.d.ts +0 -105
package/esm/index.es.js
CHANGED
@@ -36,7 +36,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
36
36
|
* @generated
|
37
37
|
* @see https://github.com/webgptorg/promptbook
|
38
38
|
*/
|
39
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-
|
39
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-4';
|
40
40
|
/**
|
41
41
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
42
42
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -5001,16 +5001,22 @@ class OpenAiCompatibleExecutionTools {
|
|
5001
5001
|
* Calls OpenAI compatible API to use a embedding model
|
5002
5002
|
*/
|
5003
5003
|
async callEmbeddingModel(prompt) {
|
5004
|
+
return this.callEmbeddingModelWithRetry(prompt, prompt.modelRequirements);
|
5005
|
+
}
|
5006
|
+
/**
|
5007
|
+
* Internal method that handles parameter retry for embedding model calls
|
5008
|
+
*/
|
5009
|
+
async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
|
5004
5010
|
if (this.options.isVerbose) {
|
5005
|
-
console.info(`🖋 ${this.title} embedding call`, { prompt });
|
5011
|
+
console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
|
5006
5012
|
}
|
5007
|
-
const { content, parameters
|
5013
|
+
const { content, parameters } = prompt;
|
5008
5014
|
const client = await this.getClient();
|
5009
5015
|
// TODO: [☂] Use here more modelRequirements
|
5010
|
-
if (
|
5016
|
+
if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
|
5011
5017
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
5012
5018
|
}
|
5013
|
-
const modelName =
|
5019
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
|
5014
5020
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
5015
5021
|
const rawRequest = {
|
5016
5022
|
input: rawPromptContent,
|
@@ -5020,44 +5026,79 @@ class OpenAiCompatibleExecutionTools {
|
|
5020
5026
|
if (this.options.isVerbose) {
|
5021
5027
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
5022
5028
|
}
|
5023
|
-
|
5024
|
-
|
5025
|
-
|
5026
|
-
|
5029
|
+
try {
|
5030
|
+
const rawResponse = await this.limiter
|
5031
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
|
5032
|
+
.catch((error) => {
|
5033
|
+
assertsError(error);
|
5034
|
+
if (this.options.isVerbose) {
|
5035
|
+
console.info(colors.bgRed('error'), error);
|
5036
|
+
}
|
5037
|
+
throw error;
|
5038
|
+
});
|
5027
5039
|
if (this.options.isVerbose) {
|
5028
|
-
console.info(colors.
|
5040
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
5029
5041
|
}
|
5030
|
-
|
5031
|
-
|
5032
|
-
|
5033
|
-
|
5042
|
+
const complete = $getCurrentDate();
|
5043
|
+
if (rawResponse.data.length !== 1) {
|
5044
|
+
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
5045
|
+
}
|
5046
|
+
const resultContent = rawResponse.data[0].embedding;
|
5047
|
+
const usage = this.computeUsage(content || '', '',
|
5048
|
+
// <- Note: Embedding does not have result content
|
5049
|
+
rawResponse);
|
5050
|
+
return exportJson({
|
5051
|
+
name: 'promptResult',
|
5052
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
5053
|
+
order: [],
|
5054
|
+
value: {
|
5055
|
+
content: resultContent,
|
5056
|
+
modelName: rawResponse.model || modelName,
|
5057
|
+
timing: {
|
5058
|
+
start,
|
5059
|
+
complete,
|
5060
|
+
},
|
5061
|
+
usage,
|
5062
|
+
rawPromptContent,
|
5063
|
+
rawRequest,
|
5064
|
+
rawResponse,
|
5065
|
+
// <- [🗯]
|
5066
|
+
},
|
5067
|
+
});
|
5034
5068
|
}
|
5035
|
-
|
5036
|
-
|
5037
|
-
|
5069
|
+
catch (error) {
|
5070
|
+
assertsError(error);
|
5071
|
+
// Check if this is an unsupported parameter error
|
5072
|
+
if (!isUnsupportedParameterError(error)) {
|
5073
|
+
throw error;
|
5074
|
+
}
|
5075
|
+
// Parse which parameter is unsupported
|
5076
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
5077
|
+
if (!unsupportedParameter) {
|
5078
|
+
if (this.options.isVerbose) {
|
5079
|
+
console.warn(colors.bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
5080
|
+
}
|
5081
|
+
throw error;
|
5082
|
+
}
|
5083
|
+
// Create a unique key for this model + parameter combination to prevent infinite loops
|
5084
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
5085
|
+
if (this.retriedUnsupportedParameters.has(retryKey)) {
|
5086
|
+
// Already retried this parameter, throw the error
|
5087
|
+
if (this.options.isVerbose) {
|
5088
|
+
console.warn(colors.bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
|
5089
|
+
}
|
5090
|
+
throw error;
|
5091
|
+
}
|
5092
|
+
// Mark this parameter as retried
|
5093
|
+
this.retriedUnsupportedParameters.add(retryKey);
|
5094
|
+
// Log warning in verbose mode
|
5095
|
+
if (this.options.isVerbose) {
|
5096
|
+
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
5097
|
+
}
|
5098
|
+
// Remove the unsupported parameter and retry
|
5099
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
5100
|
+
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
|
5038
5101
|
}
|
5039
|
-
const resultContent = rawResponse.data[0].embedding;
|
5040
|
-
const usage = this.computeUsage(content || '', '',
|
5041
|
-
// <- Note: Embedding does not have result content
|
5042
|
-
rawResponse);
|
5043
|
-
return exportJson({
|
5044
|
-
name: 'promptResult',
|
5045
|
-
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
5046
|
-
order: [],
|
5047
|
-
value: {
|
5048
|
-
content: resultContent,
|
5049
|
-
modelName: rawResponse.model || modelName,
|
5050
|
-
timing: {
|
5051
|
-
start,
|
5052
|
-
complete,
|
5053
|
-
},
|
5054
|
-
usage,
|
5055
|
-
rawPromptContent,
|
5056
|
-
rawRequest,
|
5057
|
-
rawResponse,
|
5058
|
-
// <- [🗯]
|
5059
|
-
},
|
5060
|
-
});
|
5061
5102
|
}
|
5062
5103
|
// <- Note: [🤖] callXxxModel
|
5063
5104
|
/**
|