@promptbook/ollama 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
|
@@ -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/ollama",
|
|
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,
|
|
@@ -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-
|
|
97
|
+
"@promptbook/core": "0.102.0-7"
|
|
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-
|
|
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
|
|
@@ -1981,6 +1981,7 @@
|
|
|
1981
1981
|
* @public exported from `@promptbook/openai`
|
|
1982
1982
|
*/
|
|
1983
1983
|
class OpenAiCompatibleExecutionTools {
|
|
1984
|
+
// Removed retriedUnsupportedParameters and attemptHistory instance fields
|
|
1984
1985
|
/**
|
|
1985
1986
|
* Creates OpenAI compatible Execution Tools.
|
|
1986
1987
|
*
|
|
@@ -1992,10 +1993,6 @@
|
|
|
1992
1993
|
* OpenAI API client.
|
|
1993
1994
|
*/
|
|
1994
1995
|
this.client = null;
|
|
1995
|
-
/**
|
|
1996
|
-
* Tracks models and parameters that have already been retried to prevent infinite loops
|
|
1997
|
-
*/
|
|
1998
|
-
this.retriedUnsupportedParameters = new Set();
|
|
1999
1996
|
// TODO: Allow configuring rate limits via options
|
|
2000
1997
|
this.limiter = new Bottleneck__default["default"]({
|
|
2001
1998
|
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
|
|
@@ -2057,12 +2054,16 @@
|
|
|
2057
2054
|
* Calls OpenAI compatible API to use a chat model.
|
|
2058
2055
|
*/
|
|
2059
2056
|
async callChatModel(prompt) {
|
|
2060
|
-
|
|
2057
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2058
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2059
|
+
// Use local Set for retried parameters to ensure independence and thread safety
|
|
2060
|
+
const retriedUnsupportedParameters = new Set();
|
|
2061
|
+
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2061
2062
|
}
|
|
2062
2063
|
/**
|
|
2063
2064
|
* Internal method that handles parameter retry for chat model calls
|
|
2064
2065
|
*/
|
|
2065
|
-
async callChatModelWithRetry(prompt, currentModelRequirements) {
|
|
2066
|
+
async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2066
2067
|
var _a;
|
|
2067
2068
|
if (this.options.isVerbose) {
|
|
2068
2069
|
console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
|
|
@@ -2169,6 +2170,17 @@
|
|
|
2169
2170
|
assertsError(error);
|
|
2170
2171
|
// Check if this is an unsupported parameter error
|
|
2171
2172
|
if (!isUnsupportedParameterError(error)) {
|
|
2173
|
+
// If we have attemptStack, include it in the error message
|
|
2174
|
+
if (attemptStack.length > 0) {
|
|
2175
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2176
|
+
attemptStack
|
|
2177
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2178
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2179
|
+
`, Error: ${a.errorMessage}` +
|
|
2180
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2181
|
+
.join('\n') +
|
|
2182
|
+
`\nFinal error: ${error.message}`);
|
|
2183
|
+
}
|
|
2172
2184
|
throw error;
|
|
2173
2185
|
}
|
|
2174
2186
|
// Parse which parameter is unsupported
|
|
@@ -2181,34 +2193,54 @@
|
|
|
2181
2193
|
}
|
|
2182
2194
|
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2183
2195
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2184
|
-
if (
|
|
2185
|
-
// Already retried this parameter, throw the error
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2196
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2197
|
+
// Already retried this parameter, throw the error with attemptStack
|
|
2198
|
+
attemptStack.push({
|
|
2199
|
+
modelName,
|
|
2200
|
+
unsupportedParameter,
|
|
2201
|
+
errorMessage: error.message,
|
|
2202
|
+
stripped: true,
|
|
2203
|
+
});
|
|
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}`);
|
|
2190
2212
|
}
|
|
2191
2213
|
// Mark this parameter as retried
|
|
2192
|
-
|
|
2214
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2193
2215
|
// Log warning in verbose mode
|
|
2194
2216
|
if (this.options.isVerbose) {
|
|
2195
2217
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2196
2218
|
}
|
|
2219
|
+
// Add to attemptStack
|
|
2220
|
+
attemptStack.push({
|
|
2221
|
+
modelName,
|
|
2222
|
+
unsupportedParameter,
|
|
2223
|
+
errorMessage: error.message,
|
|
2224
|
+
stripped: true,
|
|
2225
|
+
});
|
|
2197
2226
|
// Remove the unsupported parameter and retry
|
|
2198
2227
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2199
|
-
return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
|
|
2228
|
+
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2200
2229
|
}
|
|
2201
2230
|
}
|
|
2202
2231
|
/**
|
|
2203
2232
|
* Calls OpenAI API to use a complete model.
|
|
2204
2233
|
*/
|
|
2205
2234
|
async callCompletionModel(prompt) {
|
|
2206
|
-
|
|
2235
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2236
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2237
|
+
const retriedUnsupportedParameters = new Set();
|
|
2238
|
+
return this.callCompletionModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2207
2239
|
}
|
|
2208
2240
|
/**
|
|
2209
2241
|
* Internal method that handles parameter retry for completion model calls
|
|
2210
2242
|
*/
|
|
2211
|
-
async callCompletionModelWithRetry(prompt, currentModelRequirements) {
|
|
2243
|
+
async callCompletionModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2212
2244
|
var _a;
|
|
2213
2245
|
if (this.options.isVerbose) {
|
|
2214
2246
|
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
|
|
@@ -2224,8 +2256,6 @@
|
|
|
2224
2256
|
model: modelName,
|
|
2225
2257
|
max_tokens: currentModelRequirements.maxTokens,
|
|
2226
2258
|
temperature: currentModelRequirements.temperature,
|
|
2227
|
-
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
2228
|
-
// <- Note: [🧆]
|
|
2229
2259
|
};
|
|
2230
2260
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2231
2261
|
const rawRequest = {
|
|
@@ -2255,7 +2285,6 @@
|
|
|
2255
2285
|
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2256
2286
|
}
|
|
2257
2287
|
if (rawResponse.choices.length > 1) {
|
|
2258
|
-
// TODO: This should be maybe only warning
|
|
2259
2288
|
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2260
2289
|
}
|
|
2261
2290
|
const resultContent = rawResponse.choices[0].text;
|
|
@@ -2275,17 +2304,24 @@
|
|
|
2275
2304
|
rawPromptContent,
|
|
2276
2305
|
rawRequest,
|
|
2277
2306
|
rawResponse,
|
|
2278
|
-
// <- [🗯]
|
|
2279
2307
|
},
|
|
2280
2308
|
});
|
|
2281
2309
|
}
|
|
2282
2310
|
catch (error) {
|
|
2283
2311
|
assertsError(error);
|
|
2284
|
-
// Check if this is an unsupported parameter error
|
|
2285
2312
|
if (!isUnsupportedParameterError(error)) {
|
|
2313
|
+
if (attemptStack.length > 0) {
|
|
2314
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2315
|
+
attemptStack
|
|
2316
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2317
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2318
|
+
`, Error: ${a.errorMessage}` +
|
|
2319
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2320
|
+
.join('\n') +
|
|
2321
|
+
`\nFinal error: ${error.message}`);
|
|
2322
|
+
}
|
|
2286
2323
|
throw error;
|
|
2287
2324
|
}
|
|
2288
|
-
// Parse which parameter is unsupported
|
|
2289
2325
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2290
2326
|
if (!unsupportedParameter) {
|
|
2291
2327
|
if (this.options.isVerbose) {
|
|
@@ -2293,42 +2329,55 @@
|
|
|
2293
2329
|
}
|
|
2294
2330
|
throw error;
|
|
2295
2331
|
}
|
|
2296
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2297
2332
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2298
|
-
if (
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2333
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2334
|
+
attemptStack.push({
|
|
2335
|
+
modelName,
|
|
2336
|
+
unsupportedParameter,
|
|
2337
|
+
errorMessage: error.message,
|
|
2338
|
+
stripped: true,
|
|
2339
|
+
});
|
|
2340
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2341
|
+
attemptStack
|
|
2342
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2343
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2344
|
+
`, Error: ${a.errorMessage}` +
|
|
2345
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2346
|
+
.join('\n') +
|
|
2347
|
+
`\nFinal error: ${error.message}`);
|
|
2304
2348
|
}
|
|
2305
|
-
|
|
2306
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2307
|
-
// Log warning in verbose mode
|
|
2349
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2308
2350
|
if (this.options.isVerbose) {
|
|
2309
2351
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2310
2352
|
}
|
|
2311
|
-
|
|
2353
|
+
attemptStack.push({
|
|
2354
|
+
modelName,
|
|
2355
|
+
unsupportedParameter,
|
|
2356
|
+
errorMessage: error.message,
|
|
2357
|
+
stripped: true,
|
|
2358
|
+
});
|
|
2312
2359
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2313
|
-
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
|
|
2360
|
+
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2314
2361
|
}
|
|
2315
2362
|
}
|
|
2316
2363
|
/**
|
|
2317
2364
|
* Calls OpenAI compatible API to use a embedding model
|
|
2318
2365
|
*/
|
|
2319
2366
|
async callEmbeddingModel(prompt) {
|
|
2320
|
-
|
|
2367
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2368
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2369
|
+
const retriedUnsupportedParameters = new Set();
|
|
2370
|
+
return this.callEmbeddingModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2321
2371
|
}
|
|
2322
2372
|
/**
|
|
2323
2373
|
* Internal method that handles parameter retry for embedding model calls
|
|
2324
2374
|
*/
|
|
2325
|
-
async callEmbeddingModelWithRetry(prompt, currentModelRequirements) {
|
|
2375
|
+
async callEmbeddingModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2326
2376
|
if (this.options.isVerbose) {
|
|
2327
2377
|
console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
|
|
2328
2378
|
}
|
|
2329
2379
|
const { content, parameters } = prompt;
|
|
2330
2380
|
const client = await this.getClient();
|
|
2331
|
-
// TODO: [☂] Use here more modelRequirements
|
|
2332
2381
|
if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2333
2382
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
2334
2383
|
}
|
|
@@ -2360,9 +2409,7 @@
|
|
|
2360
2409
|
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2361
2410
|
}
|
|
2362
2411
|
const resultContent = rawResponse.data[0].embedding;
|
|
2363
|
-
const usage = this.computeUsage(content || '', '',
|
|
2364
|
-
// <- Note: Embedding does not have result content
|
|
2365
|
-
rawResponse);
|
|
2412
|
+
const usage = this.computeUsage(content || '', '', rawResponse);
|
|
2366
2413
|
return exportJson({
|
|
2367
2414
|
name: 'promptResult',
|
|
2368
2415
|
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
@@ -2378,17 +2425,24 @@
|
|
|
2378
2425
|
rawPromptContent,
|
|
2379
2426
|
rawRequest,
|
|
2380
2427
|
rawResponse,
|
|
2381
|
-
// <- [🗯]
|
|
2382
2428
|
},
|
|
2383
2429
|
});
|
|
2384
2430
|
}
|
|
2385
2431
|
catch (error) {
|
|
2386
2432
|
assertsError(error);
|
|
2387
|
-
// Check if this is an unsupported parameter error
|
|
2388
2433
|
if (!isUnsupportedParameterError(error)) {
|
|
2434
|
+
if (attemptStack.length > 0) {
|
|
2435
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2436
|
+
attemptStack
|
|
2437
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2438
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2439
|
+
`, Error: ${a.errorMessage}` +
|
|
2440
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2441
|
+
.join('\n') +
|
|
2442
|
+
`\nFinal error: ${error.message}`);
|
|
2443
|
+
}
|
|
2389
2444
|
throw error;
|
|
2390
2445
|
}
|
|
2391
|
-
// Parse which parameter is unsupported
|
|
2392
2446
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2393
2447
|
if (!unsupportedParameter) {
|
|
2394
2448
|
if (this.options.isVerbose) {
|
|
@@ -2396,24 +2450,35 @@
|
|
|
2396
2450
|
}
|
|
2397
2451
|
throw error;
|
|
2398
2452
|
}
|
|
2399
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2400
2453
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2401
|
-
if (
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2454
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2455
|
+
attemptStack.push({
|
|
2456
|
+
modelName,
|
|
2457
|
+
unsupportedParameter,
|
|
2458
|
+
errorMessage: error.message,
|
|
2459
|
+
stripped: true,
|
|
2460
|
+
});
|
|
2461
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2462
|
+
attemptStack
|
|
2463
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2464
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2465
|
+
`, Error: ${a.errorMessage}` +
|
|
2466
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2467
|
+
.join('\n') +
|
|
2468
|
+
`\nFinal error: ${error.message}`);
|
|
2407
2469
|
}
|
|
2408
|
-
|
|
2409
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2410
|
-
// Log warning in verbose mode
|
|
2470
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2411
2471
|
if (this.options.isVerbose) {
|
|
2412
2472
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2413
2473
|
}
|
|
2414
|
-
|
|
2474
|
+
attemptStack.push({
|
|
2475
|
+
modelName,
|
|
2476
|
+
unsupportedParameter,
|
|
2477
|
+
errorMessage: error.message,
|
|
2478
|
+
stripped: true,
|
|
2479
|
+
});
|
|
2415
2480
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2416
|
-
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements);
|
|
2481
|
+
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2417
2482
|
}
|
|
2418
2483
|
}
|
|
2419
2484
|
// <- Note: [🤖] callXxxModel
|