@promptbook/ollama 0.102.0-1 → 0.102.0-10
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 +189 -74
- 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 +21 -13
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +13 -9
- 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 +35 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +29 -7
- package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +19 -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 +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/book-components/icons/AttachmentIcon.d.ts +11 -0
- package/esm/typings/src/book-components/icons/CloseIcon.d.ts +11 -0
- 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 +5 -5
- 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/remote-server/ui/ServerApp.d.ts +13 -0
- package/esm/typings/src/remote-server/ui/renderServerIndexHtml.d.ts +7 -0
- package/esm/typings/src/remote-server/ui/types.d.ts +16 -0
- 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/types/Prompt.d.ts +5 -0
- 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/prettifyMarkdown.d.ts +2 -0
- 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 +189 -74
- 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/Chat/save/savePlugins.d.ts +0 -105
- /package/esm/typings/src/{utils/arrayableToArray.test.d.ts → book-2.0/agent-source/createAgentModelRequirementsWithCommitments.delete.test.d.ts} +0 -0
- /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/{markdown/prettifyMarkdown.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
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-10';
|
|
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 });
|
|
@@ -2089,6 +2090,14 @@
|
|
|
2089
2090
|
// <- TODO: [🚸] Not all models are compatible with JSON mode
|
|
2090
2091
|
// > 'response_format' of type 'json_object' is not supported with this model.
|
|
2091
2092
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2093
|
+
// Convert thread to OpenAI format if present
|
|
2094
|
+
let threadMessages = [];
|
|
2095
|
+
if ('thread' in prompt && Array.isArray(prompt.thread)) {
|
|
2096
|
+
threadMessages = prompt.thread.map((msg) => ({
|
|
2097
|
+
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
2098
|
+
content: msg.content,
|
|
2099
|
+
}));
|
|
2100
|
+
}
|
|
2092
2101
|
const rawRequest = {
|
|
2093
2102
|
...modelSettings,
|
|
2094
2103
|
messages: [
|
|
@@ -2100,6 +2109,7 @@
|
|
|
2100
2109
|
content: currentModelRequirements.systemMessage,
|
|
2101
2110
|
},
|
|
2102
2111
|
]),
|
|
2112
|
+
...threadMessages,
|
|
2103
2113
|
{
|
|
2104
2114
|
role: 'user',
|
|
2105
2115
|
content: rawPromptContent,
|
|
@@ -2160,6 +2170,17 @@
|
|
|
2160
2170
|
assertsError(error);
|
|
2161
2171
|
// Check if this is an unsupported parameter error
|
|
2162
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
|
+
}
|
|
2163
2184
|
throw error;
|
|
2164
2185
|
}
|
|
2165
2186
|
// Parse which parameter is unsupported
|
|
@@ -2172,34 +2193,54 @@
|
|
|
2172
2193
|
}
|
|
2173
2194
|
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2174
2195
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2175
|
-
if (
|
|
2176
|
-
// Already retried this parameter, throw the error
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
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}`);
|
|
2181
2212
|
}
|
|
2182
2213
|
// Mark this parameter as retried
|
|
2183
|
-
|
|
2214
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2184
2215
|
// Log warning in verbose mode
|
|
2185
2216
|
if (this.options.isVerbose) {
|
|
2186
2217
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2187
2218
|
}
|
|
2219
|
+
// Add to attemptStack
|
|
2220
|
+
attemptStack.push({
|
|
2221
|
+
modelName,
|
|
2222
|
+
unsupportedParameter,
|
|
2223
|
+
errorMessage: error.message,
|
|
2224
|
+
stripped: true,
|
|
2225
|
+
});
|
|
2188
2226
|
// Remove the unsupported parameter and retry
|
|
2189
2227
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2190
|
-
return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
|
|
2228
|
+
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2191
2229
|
}
|
|
2192
2230
|
}
|
|
2193
2231
|
/**
|
|
2194
2232
|
* Calls OpenAI API to use a complete model.
|
|
2195
2233
|
*/
|
|
2196
2234
|
async callCompletionModel(prompt) {
|
|
2197
|
-
|
|
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);
|
|
2198
2239
|
}
|
|
2199
2240
|
/**
|
|
2200
2241
|
* Internal method that handles parameter retry for completion model calls
|
|
2201
2242
|
*/
|
|
2202
|
-
async callCompletionModelWithRetry(prompt, currentModelRequirements) {
|
|
2243
|
+
async callCompletionModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2203
2244
|
var _a;
|
|
2204
2245
|
if (this.options.isVerbose) {
|
|
2205
2246
|
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
|
|
@@ -2215,8 +2256,6 @@
|
|
|
2215
2256
|
model: modelName,
|
|
2216
2257
|
max_tokens: currentModelRequirements.maxTokens,
|
|
2217
2258
|
temperature: currentModelRequirements.temperature,
|
|
2218
|
-
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
2219
|
-
// <- Note: [🧆]
|
|
2220
2259
|
};
|
|
2221
2260
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2222
2261
|
const rawRequest = {
|
|
@@ -2246,7 +2285,6 @@
|
|
|
2246
2285
|
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2247
2286
|
}
|
|
2248
2287
|
if (rawResponse.choices.length > 1) {
|
|
2249
|
-
// TODO: This should be maybe only warning
|
|
2250
2288
|
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2251
2289
|
}
|
|
2252
2290
|
const resultContent = rawResponse.choices[0].text;
|
|
@@ -2266,17 +2304,24 @@
|
|
|
2266
2304
|
rawPromptContent,
|
|
2267
2305
|
rawRequest,
|
|
2268
2306
|
rawResponse,
|
|
2269
|
-
// <- [🗯]
|
|
2270
2307
|
},
|
|
2271
2308
|
});
|
|
2272
2309
|
}
|
|
2273
2310
|
catch (error) {
|
|
2274
2311
|
assertsError(error);
|
|
2275
|
-
// Check if this is an unsupported parameter error
|
|
2276
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
|
+
}
|
|
2277
2323
|
throw error;
|
|
2278
2324
|
}
|
|
2279
|
-
// Parse which parameter is unsupported
|
|
2280
2325
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2281
2326
|
if (!unsupportedParameter) {
|
|
2282
2327
|
if (this.options.isVerbose) {
|
|
@@ -2284,40 +2329,59 @@
|
|
|
2284
2329
|
}
|
|
2285
2330
|
throw error;
|
|
2286
2331
|
}
|
|
2287
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2288
2332
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2289
|
-
if (
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
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}`);
|
|
2295
2348
|
}
|
|
2296
|
-
|
|
2297
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2298
|
-
// Log warning in verbose mode
|
|
2349
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2299
2350
|
if (this.options.isVerbose) {
|
|
2300
2351
|
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2301
2352
|
}
|
|
2302
|
-
|
|
2353
|
+
attemptStack.push({
|
|
2354
|
+
modelName,
|
|
2355
|
+
unsupportedParameter,
|
|
2356
|
+
errorMessage: error.message,
|
|
2357
|
+
stripped: true,
|
|
2358
|
+
});
|
|
2303
2359
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2304
|
-
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
|
|
2360
|
+
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2305
2361
|
}
|
|
2306
2362
|
}
|
|
2307
2363
|
/**
|
|
2308
2364
|
* Calls OpenAI compatible API to use a embedding model
|
|
2309
2365
|
*/
|
|
2310
2366
|
async callEmbeddingModel(prompt) {
|
|
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);
|
|
2371
|
+
}
|
|
2372
|
+
/**
|
|
2373
|
+
* Internal method that handles parameter retry for embedding model calls
|
|
2374
|
+
*/
|
|
2375
|
+
async callEmbeddingModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2311
2376
|
if (this.options.isVerbose) {
|
|
2312
|
-
console.info(`🖋 ${this.title} embedding call`, { prompt });
|
|
2377
|
+
console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
|
|
2313
2378
|
}
|
|
2314
|
-
const { content, parameters
|
|
2379
|
+
const { content, parameters } = prompt;
|
|
2315
2380
|
const client = await this.getClient();
|
|
2316
|
-
|
|
2317
|
-
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2381
|
+
if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2318
2382
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
2319
2383
|
}
|
|
2320
|
-
const modelName =
|
|
2384
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
|
|
2321
2385
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2322
2386
|
const rawRequest = {
|
|
2323
2387
|
input: rawPromptContent,
|
|
@@ -2327,44 +2391,95 @@
|
|
|
2327
2391
|
if (this.options.isVerbose) {
|
|
2328
2392
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
2329
2393
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2394
|
+
try {
|
|
2395
|
+
const rawResponse = await this.limiter
|
|
2396
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
|
|
2397
|
+
.catch((error) => {
|
|
2398
|
+
assertsError(error);
|
|
2399
|
+
if (this.options.isVerbose) {
|
|
2400
|
+
console.info(colors__default["default"].bgRed('error'), error);
|
|
2401
|
+
}
|
|
2402
|
+
throw error;
|
|
2403
|
+
});
|
|
2334
2404
|
if (this.options.isVerbose) {
|
|
2335
|
-
console.info(colors__default["default"].
|
|
2405
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
2336
2406
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2407
|
+
const complete = $getCurrentDate();
|
|
2408
|
+
if (rawResponse.data.length !== 1) {
|
|
2409
|
+
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2410
|
+
}
|
|
2411
|
+
const resultContent = rawResponse.data[0].embedding;
|
|
2412
|
+
const usage = this.computeUsage(content || '', '', rawResponse);
|
|
2413
|
+
return exportJson({
|
|
2414
|
+
name: 'promptResult',
|
|
2415
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
2416
|
+
order: [],
|
|
2417
|
+
value: {
|
|
2418
|
+
content: resultContent,
|
|
2419
|
+
modelName: rawResponse.model || modelName,
|
|
2420
|
+
timing: {
|
|
2421
|
+
start,
|
|
2422
|
+
complete,
|
|
2423
|
+
},
|
|
2424
|
+
usage,
|
|
2425
|
+
rawPromptContent,
|
|
2426
|
+
rawRequest,
|
|
2427
|
+
rawResponse,
|
|
2428
|
+
},
|
|
2429
|
+
});
|
|
2341
2430
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2431
|
+
catch (error) {
|
|
2432
|
+
assertsError(error);
|
|
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
|
+
}
|
|
2444
|
+
throw error;
|
|
2445
|
+
}
|
|
2446
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2447
|
+
if (!unsupportedParameter) {
|
|
2448
|
+
if (this.options.isVerbose) {
|
|
2449
|
+
console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
2450
|
+
}
|
|
2451
|
+
throw error;
|
|
2452
|
+
}
|
|
2453
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
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}`);
|
|
2469
|
+
}
|
|
2470
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2471
|
+
if (this.options.isVerbose) {
|
|
2472
|
+
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2473
|
+
}
|
|
2474
|
+
attemptStack.push({
|
|
2475
|
+
modelName,
|
|
2476
|
+
unsupportedParameter,
|
|
2477
|
+
errorMessage: error.message,
|
|
2478
|
+
stripped: true,
|
|
2479
|
+
});
|
|
2480
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2481
|
+
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2345
2482
|
}
|
|
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
2483
|
}
|
|
2369
2484
|
// <- Note: [🤖] callXxxModel
|
|
2370
2485
|
/**
|