@promptbook/openai 0.102.0-5 → 0.102.0-7
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 +121 -56
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +81 -0
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +8 -6
- package/esm/typings/src/_packages/utils.index.d.ts +12 -14
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +1 -5
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +27 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +13 -6
- package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/MockedChat/MockedChat.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/MockedChat/constants.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/getChatSaveFormatDefinitions.d.ts +2 -2
- package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +1 -1
- package/esm/typings/src/execution/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -2
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/register-constructor.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -3
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +0 -4
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -4
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -1
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +6 -6
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -1
- package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -1
- package/esm/typings/src/utils/{trimCodeBlock.d.ts → markdown/trimCodeBlock.d.ts} +1 -1
- package/esm/typings/src/utils/{trimEndOfCodeBlock.d.ts → markdown/trimEndOfCodeBlock.d.ts} +1 -1
- package/esm/typings/src/utils/{$Register.d.ts → misc/$Register.d.ts} +2 -2
- package/esm/typings/src/utils/{$getCurrentDate.d.ts → misc/$getCurrentDate.d.ts} +1 -1
- package/esm/typings/src/utils/{arrayableToArray.d.ts → misc/arrayableToArray.d.ts} +1 -1
- package/esm/typings/src/utils/misc/debounce.d.ts +5 -0
- package/esm/typings/src/utils/{emojis.d.ts → misc/emojis.d.ts} +1 -1
- package/esm/typings/src/utils/misc/injectCssModuleIntoShadowRoot.d.ts +20 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +121 -56
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-components/BookEditor/injectCssModuleIntoShadowRoot.d.ts +0 -11
- package/esm/typings/src/book-components/BookEditor/utils.d.ts +0 -8
- /package/esm/typings/src/utils/{trimCodeBlock.test.d.ts → markdown/trimCodeBlock.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{trimEndOfCodeBlock.test.d.ts → markdown/trimEndOfCodeBlock.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{FromtoItems.d.ts → misc/FromtoItems.d.ts} +0 -0
- /package/esm/typings/src/utils/{arrayableToArray.test.d.ts → misc/arrayableToArray.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{parseNumber.d.ts → misc/parseNumber.d.ts} +0 -0
- /package/esm/typings/src/utils/{parseNumber.test.d.ts → misc/parseNumber.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeEmojis.d.ts → normalization/removeEmojis.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeEmojis.test.d.ts → normalization/removeEmojis.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeQuotes.d.ts → normalization/removeQuotes.d.ts} +0 -0
- /package/esm/typings/src/utils/{removeQuotes.test.d.ts → normalization/removeQuotes.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{unwrapResult.d.ts → normalization/unwrapResult.d.ts} +0 -0
- /package/esm/typings/src/utils/{unwrapResult.test.d.ts → normalization/unwrapResult.test.d.ts} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import spaceTrim from 'spacetrim';
|
|
2
2
|
import { extractBlock } from '../../postprocessing/utils/extractBlock';
|
|
3
3
|
import { prettifyMarkdown } from '../../utils/markdown/prettifyMarkdown';
|
|
4
|
+
import { trimCodeBlock } from '../../utils/markdown/trimCodeBlock';
|
|
5
|
+
import { trimEndOfCodeBlock } from '../../utils/markdown/trimEndOfCodeBlock';
|
|
4
6
|
import { capitalize } from '../../utils/normalization/capitalize';
|
|
5
7
|
import { decapitalize } from '../../utils/normalization/decapitalize';
|
|
6
8
|
import { nameToUriPart } from '../../utils/normalization/nameToUriPart';
|
|
7
9
|
import { nameToUriParts } from '../../utils/normalization/nameToUriParts';
|
|
8
10
|
import { normalizeToKebabCase } from '../../utils/normalization/normalize-to-kebab-case';
|
|
11
|
+
import { normalizeTo_camelCase } from '../../utils/normalization/normalizeTo_camelCase';
|
|
9
12
|
import { normalizeTo_PascalCase } from '../../utils/normalization/normalizeTo_PascalCase';
|
|
10
13
|
import { normalizeTo_SCREAMING_CASE } from '../../utils/normalization/normalizeTo_SCREAMING_CASE';
|
|
11
|
-
import { normalizeTo_camelCase } from '../../utils/normalization/normalizeTo_camelCase';
|
|
12
14
|
import { normalizeTo_snake_case } from '../../utils/normalization/normalizeTo_snake_case';
|
|
13
15
|
import { normalizeWhitespaces } from '../../utils/normalization/normalizeWhitespaces';
|
|
14
16
|
import { removeDiacritics } from '../../utils/normalization/removeDiacritics';
|
|
15
|
-
import { removeEmojis } from '../../utils/removeEmojis';
|
|
16
|
-
import { removeQuotes } from '../../utils/removeQuotes';
|
|
17
|
-
import {
|
|
18
|
-
import { trimEndOfCodeBlock } from '../../utils/trimEndOfCodeBlock';
|
|
19
|
-
import { unwrapResult } from '../../utils/unwrapResult';
|
|
17
|
+
import { removeEmojis } from '../../utils/normalization/removeEmojis';
|
|
18
|
+
import { removeQuotes } from '../../utils/normalization/removeQuotes';
|
|
19
|
+
import { unwrapResult } from '../../utils/normalization/unwrapResult';
|
|
20
20
|
/**
|
|
21
21
|
* Collection of utility functions that can be used for post-processing model outputs.
|
|
22
22
|
* These functions help transform, extract, or format the raw model responses.
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* Note: This is useful for post-processing of the result of the chat LLM model
|
|
6
6
|
* when the model wraps the result in the (markdown) code block.
|
|
7
7
|
*
|
|
8
|
-
* @public exported from `@promptbook/utils`
|
|
8
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
9
9
|
*/
|
|
10
10
|
export declare function trimCodeBlock(value: string): string;
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* Note: This is useful for post-processing of the result of the completion LLM model
|
|
5
5
|
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
6
6
|
*
|
|
7
|
-
* @public exported from `@promptbook/utils`
|
|
7
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function trimEndOfCodeBlock(value: string): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type IDestroyable } from 'destroyable';
|
|
2
|
-
import type { string_name } from '
|
|
3
|
-
import type { TODO_string } from '
|
|
2
|
+
import type { string_name } from '../../types/typeAliases';
|
|
3
|
+
import type { TODO_string } from '../organization/TODO_string';
|
|
4
4
|
/**
|
|
5
5
|
* Represents an entity in a global registry.
|
|
6
6
|
* Contains identifying information about the package and class.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { string_css_class } from '../../types/typeAliases';
|
|
2
|
+
export type InjectCssModuleIntoShadowRootOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* The shadow root where the styles should be injected
|
|
5
|
+
*/
|
|
6
|
+
shadowRoot: ShadowRoot;
|
|
7
|
+
/**
|
|
8
|
+
* The imported CSS module styles object
|
|
9
|
+
*/
|
|
10
|
+
styles: Record<string_css_class, string_css_class>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Inject the CSS module rules (derived from imported `styles`) into the provided shadow root.
|
|
14
|
+
* This allows CSS modules (which are normally emitted into the document head) to be
|
|
15
|
+
* available inside the component's shadow DOM.
|
|
16
|
+
*
|
|
17
|
+
* @public exported from `@promptbook/components`
|
|
18
|
+
* <- TODO: [🧠] Make `@promptbook/components-utils`
|
|
19
|
+
*/
|
|
20
|
+
export declare function injectCssModuleIntoShadowRoot(options: InjectCssModuleIntoShadowRootOptions): void;
|
|
@@ -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-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.102.0-6`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.102.0-
|
|
3
|
+
"version": "0.102.0-7",
|
|
4
4
|
"description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"module": "./esm/index.es.js",
|
|
103
103
|
"typings": "./esm/typings/src/_packages/openai.index.d.ts",
|
|
104
104
|
"peerDependencies": {
|
|
105
|
-
"@promptbook/core": "0.102.0-
|
|
105
|
+
"@promptbook/core": "0.102.0-7"
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
108
|
"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-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-7';
|
|
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
|
|
@@ -2010,6 +2010,7 @@
|
|
|
2010
2010
|
* @public exported from `@promptbook/openai`
|
|
2011
2011
|
*/
|
|
2012
2012
|
class OpenAiCompatibleExecutionTools {
|
|
2013
|
+
// Removed retriedUnsupportedParameters and attemptHistory instance fields
|
|
2013
2014
|
/**
|
|
2014
2015
|
* Creates OpenAI compatible Execution Tools.
|
|
2015
2016
|
*
|
|
@@ -2021,10 +2022,6 @@
|
|
|
2021
2022
|
* OpenAI API client.
|
|
2022
2023
|
*/
|
|
2023
2024
|
this.client = null;
|
|
2024
|
-
/**
|
|
2025
|
-
* Tracks models and parameters that have already been retried to prevent infinite loops
|
|
2026
|
-
*/
|
|
2027
|
-
this.retriedUnsupportedParameters = new Set();
|
|
2028
2025
|
// TODO: Allow configuring rate limits via options
|
|
2029
2026
|
this.limiter = new Bottleneck__default["default"]({
|
|
2030
2027
|
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
|
|
@@ -2086,12 +2083,16 @@
|
|
|
2086
2083
|
* Calls OpenAI compatible API to use a chat model.
|
|
2087
2084
|
*/
|
|
2088
2085
|
async callChatModel(prompt) {
|
|
2089
|
-
|
|
2086
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2087
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2088
|
+
// Use local Set for retried parameters to ensure independence and thread safety
|
|
2089
|
+
const retriedUnsupportedParameters = new Set();
|
|
2090
|
+
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2090
2091
|
}
|
|
2091
2092
|
/**
|
|
2092
2093
|
* Internal method that handles parameter retry for chat model calls
|
|
2093
2094
|
*/
|
|
2094
|
-
async callChatModelWithRetry(prompt, currentModelRequirements) {
|
|
2095
|
+
async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2095
2096
|
var _a;
|
|
2096
2097
|
if (this.options.isVerbose) {
|
|
2097
2098
|
console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
|
|
@@ -2198,6 +2199,17 @@
|
|
|
2198
2199
|
assertsError(error);
|
|
2199
2200
|
// Check if this is an unsupported parameter error
|
|
2200
2201
|
if (!isUnsupportedParameterError(error)) {
|
|
2202
|
+
// If we have attemptStack, include it in the error message
|
|
2203
|
+
if (attemptStack.length > 0) {
|
|
2204
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2205
|
+
attemptStack
|
|
2206
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2207
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2208
|
+
`, Error: ${a.errorMessage}` +
|
|
2209
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2210
|
+
.join('\n') +
|
|
2211
|
+
`\nFinal error: ${error.message}`);
|
|
2212
|
+
}
|
|
2201
2213
|
throw error;
|
|
2202
2214
|
}
|
|
2203
2215
|
// Parse which parameter is unsupported
|
|
@@ -2210,34 +2222,54 @@
|
|
|
2210
2222
|
}
|
|
2211
2223
|
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2212
2224
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2213
|
-
if (
|
|
2214
|
-
// Already retried this parameter, throw the error
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2225
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2226
|
+
// Already retried this parameter, throw the error with attemptStack
|
|
2227
|
+
attemptStack.push({
|
|
2228
|
+
modelName,
|
|
2229
|
+
unsupportedParameter,
|
|
2230
|
+
errorMessage: error.message,
|
|
2231
|
+
stripped: true,
|
|
2232
|
+
});
|
|
2233
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2234
|
+
attemptStack
|
|
2235
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2236
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2237
|
+
`, Error: ${a.errorMessage}` +
|
|
2238
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2239
|
+
.join('\n') +
|
|
2240
|
+
`\nFinal error: ${error.message}`);
|
|
2219
2241
|
}
|
|
2220
2242
|
// Mark this parameter as retried
|
|
2221
|
-
|
|
2243
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2222
2244
|
// Log warning in verbose mode
|
|
2223
2245
|
if (this.options.isVerbose) {
|
|
2224
2246
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2225
2247
|
}
|
|
2248
|
+
// Add to attemptStack
|
|
2249
|
+
attemptStack.push({
|
|
2250
|
+
modelName,
|
|
2251
|
+
unsupportedParameter,
|
|
2252
|
+
errorMessage: error.message,
|
|
2253
|
+
stripped: true,
|
|
2254
|
+
});
|
|
2226
2255
|
// Remove the unsupported parameter and retry
|
|
2227
2256
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2228
|
-
return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
|
|
2257
|
+
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2229
2258
|
}
|
|
2230
2259
|
}
|
|
2231
2260
|
/**
|
|
2232
2261
|
* Calls OpenAI API to use a complete model.
|
|
2233
2262
|
*/
|
|
2234
2263
|
async callCompletionModel(prompt) {
|
|
2235
|
-
|
|
2264
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2265
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2266
|
+
const retriedUnsupportedParameters = new Set();
|
|
2267
|
+
return this.callCompletionModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2236
2268
|
}
|
|
2237
2269
|
/**
|
|
2238
2270
|
* Internal method that handles parameter retry for completion model calls
|
|
2239
2271
|
*/
|
|
2240
|
-
async callCompletionModelWithRetry(prompt, currentModelRequirements) {
|
|
2272
|
+
async callCompletionModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2241
2273
|
var _a;
|
|
2242
2274
|
if (this.options.isVerbose) {
|
|
2243
2275
|
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
|
|
@@ -2253,8 +2285,6 @@
|
|
|
2253
2285
|
model: modelName,
|
|
2254
2286
|
max_tokens: currentModelRequirements.maxTokens,
|
|
2255
2287
|
temperature: currentModelRequirements.temperature,
|
|
2256
|
-
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
2257
|
-
// <- Note: [🧆]
|
|
2258
2288
|
};
|
|
2259
2289
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2260
2290
|
const rawRequest = {
|
|
@@ -2284,7 +2314,6 @@
|
|
|
2284
2314
|
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2285
2315
|
}
|
|
2286
2316
|
if (rawResponse.choices.length > 1) {
|
|
2287
|
-
// TODO: This should be maybe only warning
|
|
2288
2317
|
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2289
2318
|
}
|
|
2290
2319
|
const resultContent = rawResponse.choices[0].text;
|
|
@@ -2304,17 +2333,24 @@
|
|
|
2304
2333
|
rawPromptContent,
|
|
2305
2334
|
rawRequest,
|
|
2306
2335
|
rawResponse,
|
|
2307
|
-
// <- [🗯]
|
|
2308
2336
|
},
|
|
2309
2337
|
});
|
|
2310
2338
|
}
|
|
2311
2339
|
catch (error) {
|
|
2312
2340
|
assertsError(error);
|
|
2313
|
-
// Check if this is an unsupported parameter error
|
|
2314
2341
|
if (!isUnsupportedParameterError(error)) {
|
|
2342
|
+
if (attemptStack.length > 0) {
|
|
2343
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2344
|
+
attemptStack
|
|
2345
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2346
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2347
|
+
`, Error: ${a.errorMessage}` +
|
|
2348
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2349
|
+
.join('\n') +
|
|
2350
|
+
`\nFinal error: ${error.message}`);
|
|
2351
|
+
}
|
|
2315
2352
|
throw error;
|
|
2316
2353
|
}
|
|
2317
|
-
// Parse which parameter is unsupported
|
|
2318
2354
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2319
2355
|
if (!unsupportedParameter) {
|
|
2320
2356
|
if (this.options.isVerbose) {
|
|
@@ -2322,42 +2358,55 @@
|
|
|
2322
2358
|
}
|
|
2323
2359
|
throw error;
|
|
2324
2360
|
}
|
|
2325
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2326
2361
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2327
|
-
if (
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2362
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2363
|
+
attemptStack.push({
|
|
2364
|
+
modelName,
|
|
2365
|
+
unsupportedParameter,
|
|
2366
|
+
errorMessage: error.message,
|
|
2367
|
+
stripped: true,
|
|
2368
|
+
});
|
|
2369
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2370
|
+
attemptStack
|
|
2371
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2372
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2373
|
+
`, Error: ${a.errorMessage}` +
|
|
2374
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2375
|
+
.join('\n') +
|
|
2376
|
+
`\nFinal error: ${error.message}`);
|
|
2333
2377
|
}
|
|
2334
|
-
|
|
2335
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2336
|
-
// Log warning in verbose mode
|
|
2378
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2337
2379
|
if (this.options.isVerbose) {
|
|
2338
2380
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2339
2381
|
}
|
|
2340
|
-
|
|
2382
|
+
attemptStack.push({
|
|
2383
|
+
modelName,
|
|
2384
|
+
unsupportedParameter,
|
|
2385
|
+
errorMessage: error.message,
|
|
2386
|
+
stripped: true,
|
|
2387
|
+
});
|
|
2341
2388
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2342
|
-
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
|
|
2389
|
+
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2343
2390
|
}
|
|
2344
2391
|
}
|
|
2345
2392
|
/**
|
|
2346
2393
|
* Calls OpenAI compatible API to use a embedding model
|
|
2347
2394
|
*/
|
|
2348
2395
|
async callEmbeddingModel(prompt) {
|
|
2349
|
-
|
|
2396
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2397
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2398
|
+
const retriedUnsupportedParameters = new Set();
|
|
2399
|
+
return this.callEmbeddingModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2350
2400
|
}
|
|
2351
2401
|
/**
|
|
2352
2402
|
* Internal method that handles parameter retry for embedding model calls
|
|
2353
2403
|
*/
|
|
2354
|
-
async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
|
|
2404
|
+
async callEmbeddingModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2355
2405
|
if (this.options.isVerbose) {
|
|
2356
2406
|
console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
|
|
2357
2407
|
}
|
|
2358
2408
|
const { content, parameters } = prompt;
|
|
2359
2409
|
const client = await this.getClient();
|
|
2360
|
-
// TODO: [☂] Use here more modelRequirements
|
|
2361
2410
|
if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2362
2411
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
2363
2412
|
}
|
|
@@ -2389,9 +2438,7 @@
|
|
|
2389
2438
|
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2390
2439
|
}
|
|
2391
2440
|
const resultContent = rawResponse.data[0].embedding;
|
|
2392
|
-
const usage = this.computeUsage(content || '', '',
|
|
2393
|
-
// <- Note: Embedding does not have result content
|
|
2394
|
-
rawResponse);
|
|
2441
|
+
const usage = this.computeUsage(content || '', '', rawResponse);
|
|
2395
2442
|
return exportJson({
|
|
2396
2443
|
name: 'promptResult',
|
|
2397
2444
|
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
@@ -2407,17 +2454,24 @@
|
|
|
2407
2454
|
rawPromptContent,
|
|
2408
2455
|
rawRequest,
|
|
2409
2456
|
rawResponse,
|
|
2410
|
-
// <- [🗯]
|
|
2411
2457
|
},
|
|
2412
2458
|
});
|
|
2413
2459
|
}
|
|
2414
2460
|
catch (error) {
|
|
2415
2461
|
assertsError(error);
|
|
2416
|
-
// Check if this is an unsupported parameter error
|
|
2417
2462
|
if (!isUnsupportedParameterError(error)) {
|
|
2463
|
+
if (attemptStack.length > 0) {
|
|
2464
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2465
|
+
attemptStack
|
|
2466
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2467
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2468
|
+
`, Error: ${a.errorMessage}` +
|
|
2469
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2470
|
+
.join('\n') +
|
|
2471
|
+
`\nFinal error: ${error.message}`);
|
|
2472
|
+
}
|
|
2418
2473
|
throw error;
|
|
2419
2474
|
}
|
|
2420
|
-
// Parse which parameter is unsupported
|
|
2421
2475
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2422
2476
|
if (!unsupportedParameter) {
|
|
2423
2477
|
if (this.options.isVerbose) {
|
|
@@ -2425,24 +2479,35 @@
|
|
|
2425
2479
|
}
|
|
2426
2480
|
throw error;
|
|
2427
2481
|
}
|
|
2428
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2429
2482
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2430
|
-
if (
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2483
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2484
|
+
attemptStack.push({
|
|
2485
|
+
modelName,
|
|
2486
|
+
unsupportedParameter,
|
|
2487
|
+
errorMessage: error.message,
|
|
2488
|
+
stripped: true,
|
|
2489
|
+
});
|
|
2490
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2491
|
+
attemptStack
|
|
2492
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2493
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2494
|
+
`, Error: ${a.errorMessage}` +
|
|
2495
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2496
|
+
.join('\n') +
|
|
2497
|
+
`\nFinal error: ${error.message}`);
|
|
2436
2498
|
}
|
|
2437
|
-
|
|
2438
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2439
|
-
// Log warning in verbose mode
|
|
2499
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2440
2500
|
if (this.options.isVerbose) {
|
|
2441
2501
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2442
2502
|
}
|
|
2443
|
-
|
|
2503
|
+
attemptStack.push({
|
|
2504
|
+
modelName,
|
|
2505
|
+
unsupportedParameter,
|
|
2506
|
+
errorMessage: error.message,
|
|
2507
|
+
stripped: true,
|
|
2508
|
+
});
|
|
2444
2509
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2445
|
-
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
|
|
2510
|
+
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2446
2511
|
}
|
|
2447
2512
|
}
|
|
2448
2513
|
// <- Note: [🤖] callXxxModel
|