@promptbook/wizard 0.102.0-3 → 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.
@@ -33,6 +33,7 @@ import { htmlSaveFormatDefinition } from '../book-components/Chat/save/html/html
33
33
  import { CHAT_SAVE_FORMATS } from '../book-components/Chat/save/index';
34
34
  import { jsonSaveFormatDefinition } from '../book-components/Chat/save/json/jsonSaveFormatDefinition';
35
35
  import { mdSaveFormatDefinition } from '../book-components/Chat/save/markdown/mdSaveFormatDefinition';
36
+ import { pdfSaveFormatDefinition } from '../book-components/Chat/save/pdf/pdfSaveFormatDefinition';
36
37
  import { txtSaveFormatDefinition } from '../book-components/Chat/save/text/txtSaveFormatDefinition';
37
38
  import type { ChatMessage } from '../book-components/Chat/types/ChatMessage';
38
39
  import type { ChatParticipant } from '../book-components/Chat/types/ChatParticipant';
@@ -83,6 +84,7 @@ export { htmlSaveFormatDefinition };
83
84
  export { CHAT_SAVE_FORMATS };
84
85
  export { jsonSaveFormatDefinition };
85
86
  export { mdSaveFormatDefinition };
87
+ export { pdfSaveFormatDefinition };
86
88
  export { txtSaveFormatDefinition };
87
89
  export type { ChatMessage };
88
90
  export type { ChatParticipant };
@@ -27,6 +27,12 @@ export declare const CHAT_SAVE_FORMATS: readonly [{
27
27
  readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
28
28
  readonly mimeType: "text/html";
29
29
  readonly fileExtension: "html";
30
+ }, {
31
+ readonly formatName: "pdf";
32
+ readonly label: "PDF";
33
+ readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
34
+ readonly mimeType: "application/pdf";
35
+ readonly fileExtension: "pdf";
30
36
  }];
31
37
  /**
32
38
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -0,0 +1,12 @@
1
+ /**
2
+ * PDF export plugin
3
+ *
4
+ * @public exported from `@promptbook/components`
5
+ */
6
+ export declare const pdfSaveFormatDefinition: {
7
+ readonly formatName: "pdf";
8
+ readonly label: "PDF";
9
+ readonly getContent: (messages: import("../../types/ChatMessage").ChatMessage[]) => string;
10
+ readonly mimeType: "application/pdf";
11
+ readonly fileExtension: "pdf";
12
+ };
@@ -63,6 +63,10 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
63
63
  * Calls OpenAI compatible API to use a embedding model
64
64
  */
65
65
  callEmbeddingModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<EmbeddingPromptResult>;
66
+ /**
67
+ * Internal method that handles parameter retry for embedding model calls
68
+ */
69
+ private callEmbeddingModelWithRetry;
66
70
  /**
67
71
  * Get the model that should be used as default
68
72
  */
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.102.0-2`).
18
+ * It follows semantic versioning (e.g., `0.102.0-3`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/wizard",
3
- "version": "0.102.0-3",
3
+ "version": "0.102.0-4",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/wizard.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.102.0-3"
98
+ "@promptbook/core": "0.102.0-4"
99
99
  },
100
100
  "dependencies": {
101
101
  "@ai-sdk/deepseek": "0.1.6",
package/umd/index.umd.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-3';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-4';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5013,16 +5013,22 @@
5013
5013
  * Calls OpenAI compatible API to use a embedding model
5014
5014
  */
5015
5015
  async callEmbeddingModel(prompt) {
5016
+ return this.callEmbeddingModelWithRetry(prompt, prompt.modelRequirements);
5017
+ }
5018
+ /**
5019
+ * Internal method that handles parameter retry for embedding model calls
5020
+ */
5021
+ async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
5016
5022
  if (this.options.isVerbose) {
5017
- console.info(`🖋 ${this.title} embedding call`, { prompt });
5023
+ console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
5018
5024
  }
5019
- const { content, parameters, modelRequirements } = prompt;
5025
+ const { content, parameters } = prompt;
5020
5026
  const client = await this.getClient();
5021
5027
  // TODO: [☂] Use here more modelRequirements
5022
- if (modelRequirements.modelVariant !== 'EMBEDDING') {
5028
+ if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
5023
5029
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
5024
5030
  }
5025
- const modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
5031
+ const modelName = currentModelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
5026
5032
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
5027
5033
  const rawRequest = {
5028
5034
  input: rawPromptContent,
@@ -5032,44 +5038,79 @@
5032
5038
  if (this.options.isVerbose) {
5033
5039
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
5034
5040
  }
5035
- const rawResponse = await this.limiter
5036
- .schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
5037
- .catch((error) => {
5038
- assertsError(error);
5041
+ try {
5042
+ const rawResponse = await this.limiter
5043
+ .schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
5044
+ .catch((error) => {
5045
+ assertsError(error);
5046
+ if (this.options.isVerbose) {
5047
+ console.info(colors__default["default"].bgRed('error'), error);
5048
+ }
5049
+ throw error;
5050
+ });
5039
5051
  if (this.options.isVerbose) {
5040
- console.info(colors__default["default"].bgRed('error'), error);
5052
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
5041
5053
  }
5042
- throw error;
5043
- });
5044
- if (this.options.isVerbose) {
5045
- console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
5054
+ const complete = $getCurrentDate();
5055
+ if (rawResponse.data.length !== 1) {
5056
+ throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
5057
+ }
5058
+ const resultContent = rawResponse.data[0].embedding;
5059
+ const usage = this.computeUsage(content || '', '',
5060
+ // <- Note: Embedding does not have result content
5061
+ rawResponse);
5062
+ return exportJson({
5063
+ name: 'promptResult',
5064
+ message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
5065
+ order: [],
5066
+ value: {
5067
+ content: resultContent,
5068
+ modelName: rawResponse.model || modelName,
5069
+ timing: {
5070
+ start,
5071
+ complete,
5072
+ },
5073
+ usage,
5074
+ rawPromptContent,
5075
+ rawRequest,
5076
+ rawResponse,
5077
+ // <- [🗯]
5078
+ },
5079
+ });
5046
5080
  }
5047
- const complete = $getCurrentDate();
5048
- if (rawResponse.data.length !== 1) {
5049
- throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
5081
+ catch (error) {
5082
+ assertsError(error);
5083
+ // Check if this is an unsupported parameter error
5084
+ if (!isUnsupportedParameterError(error)) {
5085
+ throw error;
5086
+ }
5087
+ // Parse which parameter is unsupported
5088
+ const unsupportedParameter = parseUnsupportedParameterError(error.message);
5089
+ if (!unsupportedParameter) {
5090
+ if (this.options.isVerbose) {
5091
+ console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
5092
+ }
5093
+ throw error;
5094
+ }
5095
+ // Create a unique key for this model + parameter combination to prevent infinite loops
5096
+ const retryKey = `${modelName}-${unsupportedParameter}`;
5097
+ if (this.retriedUnsupportedParameters.has(retryKey)) {
5098
+ // Already retried this parameter, throw the error
5099
+ if (this.options.isVerbose) {
5100
+ console.warn(colors__default["default"].bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
5101
+ }
5102
+ throw error;
5103
+ }
5104
+ // Mark this parameter as retried
5105
+ this.retriedUnsupportedParameters.add(retryKey);
5106
+ // Log warning in verbose mode
5107
+ if (this.options.isVerbose) {
5108
+ console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
5109
+ }
5110
+ // Remove the unsupported parameter and retry
5111
+ const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
5112
+ return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
5050
5113
  }
5051
- const resultContent = rawResponse.data[0].embedding;
5052
- const usage = this.computeUsage(content || '', '',
5053
- // <- Note: Embedding does not have result content
5054
- rawResponse);
5055
- return exportJson({
5056
- name: 'promptResult',
5057
- message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
5058
- order: [],
5059
- value: {
5060
- content: resultContent,
5061
- modelName: rawResponse.model || modelName,
5062
- timing: {
5063
- start,
5064
- complete,
5065
- },
5066
- usage,
5067
- rawPromptContent,
5068
- rawRequest,
5069
- rawResponse,
5070
- // <- [🗯]
5071
- },
5072
- });
5073
5114
  }
5074
5115
  // <- Note: [🤖] callXxxModel
5075
5116
  /**