@promptbook/ollama 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.
Files changed (24) hide show
  1. package/esm/index.es.js +80 -39
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +15 -13
  4. package/esm/typings/src/_packages/types.index.d.ts +3 -3
  5. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +1 -1
  6. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +14 -1
  7. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +13 -0
  8. package/esm/typings/src/book-components/Chat/save/_common/getChatSaveFormatDefinitions.d.ts +8 -0
  9. package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +6 -0
  10. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
  11. package/esm/typings/src/book-components/Chat/save/index.d.ts +39 -0
  12. package/esm/typings/src/book-components/Chat/save/json/jsonSaveFormatDefinition.d.ts +12 -0
  13. package/esm/typings/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +12 -0
  14. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +12 -0
  15. package/esm/typings/src/book-components/Chat/save/text/txtSaveFormatDefinition.d.ts +12 -0
  16. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +31 -5
  17. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +3 -3
  18. package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +3 -0
  19. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +4 -0
  20. package/esm/typings/src/version.d.ts +1 -1
  21. package/package.json +2 -2
  22. package/umd/index.umd.js +80 -39
  23. package/umd/index.umd.js.map +1 -1
  24. package/esm/typings/src/book-components/Chat/save/savePlugins.d.ts +0 -105
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Registry of all built-in chat save plugins
3
+ *
4
+ * @public exported from `@promptbook/components`
5
+ */
6
+ export declare const CHAT_SAVE_FORMATS: readonly [{
7
+ readonly formatName: "json";
8
+ readonly label: "JSON (full)";
9
+ readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
10
+ readonly mimeType: "application/json";
11
+ readonly fileExtension: "json";
12
+ }, {
13
+ readonly formatName: "txt";
14
+ readonly label: "Plain Text";
15
+ readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
16
+ readonly mimeType: "text/plain";
17
+ readonly fileExtension: "txt";
18
+ }, {
19
+ readonly formatName: "md";
20
+ readonly label: "Markdown";
21
+ readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
22
+ readonly mimeType: "text/markdown";
23
+ readonly fileExtension: "md";
24
+ }, {
25
+ readonly formatName: "html";
26
+ readonly label: "HTML";
27
+ readonly getContent: (messages: import("../types/ChatMessage").ChatMessage[]) => string;
28
+ readonly mimeType: "text/html";
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";
36
+ }];
37
+ /**
38
+ * Note: [💞] Ignore a discrepancy between file name and entity name
39
+ */
@@ -0,0 +1,12 @@
1
+ /**
2
+ * JSON export plugin (full metadata)
3
+ *
4
+ * @public exported from `@promptbook/components`
5
+ */
6
+ export declare const jsonSaveFormatDefinition: {
7
+ readonly formatName: "json";
8
+ readonly label: "JSON (full)";
9
+ readonly getContent: (messages: import("../../types/ChatMessage").ChatMessage[]) => string;
10
+ readonly mimeType: "application/json";
11
+ readonly fileExtension: "json";
12
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Markdown export plugin
3
+ *
4
+ * @public exported from `@promptbook/components`
5
+ */
6
+ export declare const mdSaveFormatDefinition: {
7
+ readonly formatName: "md";
8
+ readonly label: "Markdown";
9
+ readonly getContent: (messages: import("../../types/ChatMessage").ChatMessage[]) => string;
10
+ readonly mimeType: "text/markdown";
11
+ readonly fileExtension: "md";
12
+ };
@@ -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
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Plain text export plugin (messages only)
3
+ *
4
+ * @public exported from `@promptbook/components`
5
+ */
6
+ export declare const txtSaveFormatDefinition: {
7
+ readonly formatName: "txt";
8
+ readonly label: "Plain Text";
9
+ readonly getContent: (messages: import("../../types/ChatMessage").ChatMessage[]) => string;
10
+ readonly mimeType: "text/plain";
11
+ readonly fileExtension: "txt";
12
+ };
@@ -1,16 +1,42 @@
1
- import type { string_markdown } from '../../../types/typeAliases';
2
- import type { string_name } from '../../../types/typeAliases';
1
+ import type { id, string_markdown } from '../../../types/typeAliases';
3
2
  /**
4
3
  * A message in the chat
5
4
  *
6
5
  * @public exported from `@promptbook/components`
7
6
  */
8
7
  export type ChatMessage = {
9
- id: string;
10
- date: Date;
11
- from: string_name;
8
+ /**
9
+ * Unique identifier of the message
10
+ */
11
+ id: id;
12
+ /**
13
+ * Date when the message was created
14
+ */
15
+ date?: Date;
16
+ /**
17
+ * The name of the participant who sent the message
18
+ */
19
+ from: id;
20
+ /**
21
+ * The content of the message with optional markdown formatting
22
+ */
12
23
  content: string_markdown;
24
+ /**
25
+ * Whether the message is complete (for example, if it's still being generated by an AI)
26
+ *
27
+ * @default true
28
+ */
13
29
  isComplete?: boolean;
30
+ /**
31
+ * @@@
32
+ */
14
33
  expectedAnswer?: string;
34
+ /**
35
+ * @@@
36
+ */
15
37
  isVoiceCall?: boolean;
16
38
  };
39
+ /**
40
+ * TODO: Delete `expectedAnswer` from ChatMessage
41
+ * TODO: Rename `date` into `created`+`modified`
42
+ */
@@ -1,4 +1,4 @@
1
- import type { string_color, string_name, string_person_fullname, string_url_image } from '../../../types/typeAliases';
1
+ import type { id, string_color, string_person_fullname, string_url_image } from '../../../types/typeAliases';
2
2
  import { Color } from '../../../utils/color/Color';
3
3
  /**
4
4
  * A participant in the chat
@@ -9,11 +9,11 @@ export type ChatParticipant = {
9
9
  /**
10
10
  * Identifies the participant by their name, same as `message.from`
11
11
  */
12
- name: string_name;
12
+ name: id;
13
13
  /**
14
14
  * Full name of the participant
15
15
  */
16
- fullname: string_person_fullname;
16
+ fullname?: string_person_fullname;
17
17
  /**
18
18
  * Am I the participant? (i.e. is this the user)
19
19
  */
@@ -7,3 +7,6 @@ import type { ExportFormat } from './ExportFormat';
7
7
  * @private utility of `<Chat/>` component
8
8
  */
9
9
  export declare function exportChatHistory(messages: ChatMessage[], format: ExportFormat, headerMarkdown?: string, participants?: ReadonlyArray<ChatParticipant>): Promise<void>;
10
+ /**
11
+ * TODO: !!!! Delete this parallel chat history export
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-1`).
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/ollama",
3
- "version": "0.102.0-2",
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,
@@ -94,7 +94,7 @@
94
94
  "module": "./esm/index.es.js",
95
95
  "typings": "./esm/typings/src/_packages/ollama.index.d.ts",
96
96
  "peerDependencies": {
97
- "@promptbook/core": "0.102.0-2"
97
+ "@promptbook/core": "0.102.0-4"
98
98
  },
99
99
  "dependencies": {
100
100
  "bottleneck": "^2.19.5",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-2';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-4';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2308,16 +2308,22 @@
2308
2308
  * Calls OpenAI compatible API to use a embedding model
2309
2309
  */
2310
2310
  async callEmbeddingModel(prompt) {
2311
+ return this.callEmbeddingModelWithRetry(prompt, prompt.modelRequirements);
2312
+ }
2313
+ /**
2314
+ * Internal method that handles parameter retry for embedding model calls
2315
+ */
2316
+ async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
2311
2317
  if (this.options.isVerbose) {
2312
- console.info(`🖋 ${this.title} embedding call`, { prompt });
2318
+ console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
2313
2319
  }
2314
- const { content, parameters, modelRequirements } = prompt;
2320
+ const { content, parameters } = prompt;
2315
2321
  const client = await this.getClient();
2316
2322
  // TODO: [☂] Use here more modelRequirements
2317
- if (modelRequirements.modelVariant !== 'EMBEDDING') {
2323
+ if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
2318
2324
  throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
2319
2325
  }
2320
- const modelName = modelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
2326
+ const modelName = currentModelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
2321
2327
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
2322
2328
  const rawRequest = {
2323
2329
  input: rawPromptContent,
@@ -2327,44 +2333,79 @@
2327
2333
  if (this.options.isVerbose) {
2328
2334
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2329
2335
  }
2330
- const rawResponse = await this.limiter
2331
- .schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
2332
- .catch((error) => {
2333
- assertsError(error);
2336
+ try {
2337
+ const rawResponse = await this.limiter
2338
+ .schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
2339
+ .catch((error) => {
2340
+ assertsError(error);
2341
+ if (this.options.isVerbose) {
2342
+ console.info(colors__default["default"].bgRed('error'), error);
2343
+ }
2344
+ throw error;
2345
+ });
2334
2346
  if (this.options.isVerbose) {
2335
- console.info(colors__default["default"].bgRed('error'), error);
2347
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2336
2348
  }
2337
- throw error;
2338
- });
2339
- if (this.options.isVerbose) {
2340
- console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2349
+ const complete = $getCurrentDate();
2350
+ if (rawResponse.data.length !== 1) {
2351
+ throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
2352
+ }
2353
+ const resultContent = rawResponse.data[0].embedding;
2354
+ const usage = this.computeUsage(content || '', '',
2355
+ // <- Note: Embedding does not have result content
2356
+ rawResponse);
2357
+ return exportJson({
2358
+ name: 'promptResult',
2359
+ message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
2360
+ order: [],
2361
+ value: {
2362
+ content: resultContent,
2363
+ modelName: rawResponse.model || modelName,
2364
+ timing: {
2365
+ start,
2366
+ complete,
2367
+ },
2368
+ usage,
2369
+ rawPromptContent,
2370
+ rawRequest,
2371
+ rawResponse,
2372
+ // <- [🗯]
2373
+ },
2374
+ });
2341
2375
  }
2342
- const complete = $getCurrentDate();
2343
- if (rawResponse.data.length !== 1) {
2344
- throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
2376
+ catch (error) {
2377
+ assertsError(error);
2378
+ // Check if this is an unsupported parameter error
2379
+ if (!isUnsupportedParameterError(error)) {
2380
+ throw error;
2381
+ }
2382
+ // Parse which parameter is unsupported
2383
+ const unsupportedParameter = parseUnsupportedParameterError(error.message);
2384
+ if (!unsupportedParameter) {
2385
+ if (this.options.isVerbose) {
2386
+ console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
2387
+ }
2388
+ throw error;
2389
+ }
2390
+ // Create a unique key for this model + parameter combination to prevent infinite loops
2391
+ const retryKey = `${modelName}-${unsupportedParameter}`;
2392
+ if (this.retriedUnsupportedParameters.has(retryKey)) {
2393
+ // Already retried this parameter, throw the error
2394
+ if (this.options.isVerbose) {
2395
+ console.warn(colors__default["default"].bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2396
+ }
2397
+ throw error;
2398
+ }
2399
+ // Mark this parameter as retried
2400
+ this.retriedUnsupportedParameters.add(retryKey);
2401
+ // Log warning in verbose mode
2402
+ if (this.options.isVerbose) {
2403
+ console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2404
+ }
2405
+ // Remove the unsupported parameter and retry
2406
+ const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2407
+ return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
2345
2408
  }
2346
- const resultContent = rawResponse.data[0].embedding;
2347
- const usage = this.computeUsage(content || '', '',
2348
- // <- Note: Embedding does not have result content
2349
- rawResponse);
2350
- return exportJson({
2351
- name: 'promptResult',
2352
- message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
2353
- order: [],
2354
- value: {
2355
- content: resultContent,
2356
- modelName: rawResponse.model || modelName,
2357
- timing: {
2358
- start,
2359
- complete,
2360
- },
2361
- usage,
2362
- rawPromptContent,
2363
- rawRequest,
2364
- rawResponse,
2365
- // <- [🗯]
2366
- },
2367
- });
2368
2409
  }
2369
2410
  // <- Note: [🤖] callXxxModel
2370
2411
  /**