@promptbook/ollama 0.102.0-0 → 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 +42 -22
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -14
- 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/{AvatarProfile/AvatarProfile → Chat/MockedChat}/MockedChat.d.ts +26 -9
- package/esm/typings/src/book-components/Chat/MockedChat/constants.d.ts +42 -0
- 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/types/RemoteServerOptions.d.ts +6 -0
- 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/AvatarProfile/AvatarProfile/index.d.ts +0 -3
- package/esm/typings/src/book-components/BookEditor/injectCssModuleIntoShadowRoot.d.ts +0 -11
- package/esm/typings/src/book-components/Chat/utils/savePlugins.d.ts +0 -55
- /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/esm/index.es.js
CHANGED
|
@@ -18,7 +18,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
18
18
|
* @generated
|
|
19
19
|
* @see https://github.com/webgptorg/promptbook
|
|
20
20
|
*/
|
|
21
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-
|
|
21
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.102.0-10';
|
|
22
22
|
/**
|
|
23
23
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
24
24
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1974,6 +1974,7 @@ function isUnsupportedParameterError(error) {
|
|
|
1974
1974
|
* @public exported from `@promptbook/openai`
|
|
1975
1975
|
*/
|
|
1976
1976
|
class OpenAiCompatibleExecutionTools {
|
|
1977
|
+
// Removed retriedUnsupportedParameters and attemptHistory instance fields
|
|
1977
1978
|
/**
|
|
1978
1979
|
* Creates OpenAI compatible Execution Tools.
|
|
1979
1980
|
*
|
|
@@ -1985,10 +1986,6 @@ class OpenAiCompatibleExecutionTools {
|
|
|
1985
1986
|
* OpenAI API client.
|
|
1986
1987
|
*/
|
|
1987
1988
|
this.client = null;
|
|
1988
|
-
/**
|
|
1989
|
-
* Tracks models and parameters that have already been retried to prevent infinite loops
|
|
1990
|
-
*/
|
|
1991
|
-
this.retriedUnsupportedParameters = new Set();
|
|
1992
1989
|
// TODO: Allow configuring rate limits via options
|
|
1993
1990
|
this.limiter = new Bottleneck({
|
|
1994
1991
|
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
|
|
@@ -2050,12 +2047,16 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2050
2047
|
* Calls OpenAI compatible API to use a chat model.
|
|
2051
2048
|
*/
|
|
2052
2049
|
async callChatModel(prompt) {
|
|
2053
|
-
|
|
2050
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2051
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2052
|
+
// Use local Set for retried parameters to ensure independence and thread safety
|
|
2053
|
+
const retriedUnsupportedParameters = new Set();
|
|
2054
|
+
return this.callChatModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2054
2055
|
}
|
|
2055
2056
|
/**
|
|
2056
2057
|
* Internal method that handles parameter retry for chat model calls
|
|
2057
2058
|
*/
|
|
2058
|
-
async callChatModelWithRetry(prompt, currentModelRequirements) {
|
|
2059
|
+
async callChatModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2059
2060
|
var _a;
|
|
2060
2061
|
if (this.options.isVerbose) {
|
|
2061
2062
|
console.info(`💬 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
|
|
@@ -2082,6 +2083,14 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2082
2083
|
// <- TODO: [🚸] Not all models are compatible with JSON mode
|
|
2083
2084
|
// > 'response_format' of type 'json_object' is not supported with this model.
|
|
2084
2085
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2086
|
+
// Convert thread to OpenAI format if present
|
|
2087
|
+
let threadMessages = [];
|
|
2088
|
+
if ('thread' in prompt && Array.isArray(prompt.thread)) {
|
|
2089
|
+
threadMessages = prompt.thread.map((msg) => ({
|
|
2090
|
+
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
2091
|
+
content: msg.content,
|
|
2092
|
+
}));
|
|
2093
|
+
}
|
|
2085
2094
|
const rawRequest = {
|
|
2086
2095
|
...modelSettings,
|
|
2087
2096
|
messages: [
|
|
@@ -2093,6 +2102,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2093
2102
|
content: currentModelRequirements.systemMessage,
|
|
2094
2103
|
},
|
|
2095
2104
|
]),
|
|
2105
|
+
...threadMessages,
|
|
2096
2106
|
{
|
|
2097
2107
|
role: 'user',
|
|
2098
2108
|
content: rawPromptContent,
|
|
@@ -2153,6 +2163,17 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2153
2163
|
assertsError(error);
|
|
2154
2164
|
// Check if this is an unsupported parameter error
|
|
2155
2165
|
if (!isUnsupportedParameterError(error)) {
|
|
2166
|
+
// If we have attemptStack, include it in the error message
|
|
2167
|
+
if (attemptStack.length > 0) {
|
|
2168
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2169
|
+
attemptStack
|
|
2170
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2171
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2172
|
+
`, Error: ${a.errorMessage}` +
|
|
2173
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2174
|
+
.join('\n') +
|
|
2175
|
+
`\nFinal error: ${error.message}`);
|
|
2176
|
+
}
|
|
2156
2177
|
throw error;
|
|
2157
2178
|
}
|
|
2158
2179
|
// Parse which parameter is unsupported
|
|
@@ -2165,34 +2186,54 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2165
2186
|
}
|
|
2166
2187
|
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2167
2188
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2168
|
-
if (
|
|
2169
|
-
// Already retried this parameter, throw the error
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2189
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2190
|
+
// Already retried this parameter, throw the error with attemptStack
|
|
2191
|
+
attemptStack.push({
|
|
2192
|
+
modelName,
|
|
2193
|
+
unsupportedParameter,
|
|
2194
|
+
errorMessage: error.message,
|
|
2195
|
+
stripped: true,
|
|
2196
|
+
});
|
|
2197
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2198
|
+
attemptStack
|
|
2199
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2200
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2201
|
+
`, Error: ${a.errorMessage}` +
|
|
2202
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2203
|
+
.join('\n') +
|
|
2204
|
+
`\nFinal error: ${error.message}`);
|
|
2174
2205
|
}
|
|
2175
2206
|
// Mark this parameter as retried
|
|
2176
|
-
|
|
2207
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2177
2208
|
// Log warning in verbose mode
|
|
2178
2209
|
if (this.options.isVerbose) {
|
|
2179
2210
|
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2180
2211
|
}
|
|
2212
|
+
// Add to attemptStack
|
|
2213
|
+
attemptStack.push({
|
|
2214
|
+
modelName,
|
|
2215
|
+
unsupportedParameter,
|
|
2216
|
+
errorMessage: error.message,
|
|
2217
|
+
stripped: true,
|
|
2218
|
+
});
|
|
2181
2219
|
// Remove the unsupported parameter and retry
|
|
2182
2220
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2183
|
-
return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
|
|
2221
|
+
return this.callChatModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2184
2222
|
}
|
|
2185
2223
|
}
|
|
2186
2224
|
/**
|
|
2187
2225
|
* Calls OpenAI API to use a complete model.
|
|
2188
2226
|
*/
|
|
2189
2227
|
async callCompletionModel(prompt) {
|
|
2190
|
-
|
|
2228
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2229
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2230
|
+
const retriedUnsupportedParameters = new Set();
|
|
2231
|
+
return this.callCompletionModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2191
2232
|
}
|
|
2192
2233
|
/**
|
|
2193
2234
|
* Internal method that handles parameter retry for completion model calls
|
|
2194
2235
|
*/
|
|
2195
|
-
async callCompletionModelWithRetry(prompt, currentModelRequirements) {
|
|
2236
|
+
async callCompletionModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2196
2237
|
var _a;
|
|
2197
2238
|
if (this.options.isVerbose) {
|
|
2198
2239
|
console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
|
|
@@ -2208,8 +2249,6 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2208
2249
|
model: modelName,
|
|
2209
2250
|
max_tokens: currentModelRequirements.maxTokens,
|
|
2210
2251
|
temperature: currentModelRequirements.temperature,
|
|
2211
|
-
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
2212
|
-
// <- Note: [🧆]
|
|
2213
2252
|
};
|
|
2214
2253
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2215
2254
|
const rawRequest = {
|
|
@@ -2239,7 +2278,6 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2239
2278
|
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
2240
2279
|
}
|
|
2241
2280
|
if (rawResponse.choices.length > 1) {
|
|
2242
|
-
// TODO: This should be maybe only warning
|
|
2243
2281
|
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
2244
2282
|
}
|
|
2245
2283
|
const resultContent = rawResponse.choices[0].text;
|
|
@@ -2259,17 +2297,24 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2259
2297
|
rawPromptContent,
|
|
2260
2298
|
rawRequest,
|
|
2261
2299
|
rawResponse,
|
|
2262
|
-
// <- [🗯]
|
|
2263
2300
|
},
|
|
2264
2301
|
});
|
|
2265
2302
|
}
|
|
2266
2303
|
catch (error) {
|
|
2267
2304
|
assertsError(error);
|
|
2268
|
-
// Check if this is an unsupported parameter error
|
|
2269
2305
|
if (!isUnsupportedParameterError(error)) {
|
|
2306
|
+
if (attemptStack.length > 0) {
|
|
2307
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2308
|
+
attemptStack
|
|
2309
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2310
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2311
|
+
`, Error: ${a.errorMessage}` +
|
|
2312
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2313
|
+
.join('\n') +
|
|
2314
|
+
`\nFinal error: ${error.message}`);
|
|
2315
|
+
}
|
|
2270
2316
|
throw error;
|
|
2271
2317
|
}
|
|
2272
|
-
// Parse which parameter is unsupported
|
|
2273
2318
|
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2274
2319
|
if (!unsupportedParameter) {
|
|
2275
2320
|
if (this.options.isVerbose) {
|
|
@@ -2277,40 +2322,59 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2277
2322
|
}
|
|
2278
2323
|
throw error;
|
|
2279
2324
|
}
|
|
2280
|
-
// Create a unique key for this model + parameter combination to prevent infinite loops
|
|
2281
2325
|
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2282
|
-
if (
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2326
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2327
|
+
attemptStack.push({
|
|
2328
|
+
modelName,
|
|
2329
|
+
unsupportedParameter,
|
|
2330
|
+
errorMessage: error.message,
|
|
2331
|
+
stripped: true,
|
|
2332
|
+
});
|
|
2333
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2334
|
+
attemptStack
|
|
2335
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2336
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2337
|
+
`, Error: ${a.errorMessage}` +
|
|
2338
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2339
|
+
.join('\n') +
|
|
2340
|
+
`\nFinal error: ${error.message}`);
|
|
2288
2341
|
}
|
|
2289
|
-
|
|
2290
|
-
this.retriedUnsupportedParameters.add(retryKey);
|
|
2291
|
-
// Log warning in verbose mode
|
|
2342
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2292
2343
|
if (this.options.isVerbose) {
|
|
2293
2344
|
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2294
2345
|
}
|
|
2295
|
-
|
|
2346
|
+
attemptStack.push({
|
|
2347
|
+
modelName,
|
|
2348
|
+
unsupportedParameter,
|
|
2349
|
+
errorMessage: error.message,
|
|
2350
|
+
stripped: true,
|
|
2351
|
+
});
|
|
2296
2352
|
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2297
|
-
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
|
|
2353
|
+
return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2298
2354
|
}
|
|
2299
2355
|
}
|
|
2300
2356
|
/**
|
|
2301
2357
|
* Calls OpenAI compatible API to use a embedding model
|
|
2302
2358
|
*/
|
|
2303
2359
|
async callEmbeddingModel(prompt) {
|
|
2360
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
2361
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
2362
|
+
const retriedUnsupportedParameters = new Set();
|
|
2363
|
+
return this.callEmbeddingModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Internal method that handles parameter retry for embedding model calls
|
|
2367
|
+
*/
|
|
2368
|
+
async callEmbeddingModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
2304
2369
|
if (this.options.isVerbose) {
|
|
2305
|
-
console.info(`🖋 ${this.title} embedding call`, { prompt });
|
|
2370
|
+
console.info(`🖋 ${this.title} embedding call`, { prompt, currentModelRequirements });
|
|
2306
2371
|
}
|
|
2307
|
-
const { content, parameters
|
|
2372
|
+
const { content, parameters } = prompt;
|
|
2308
2373
|
const client = await this.getClient();
|
|
2309
|
-
|
|
2310
|
-
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2374
|
+
if (currentModelRequirements.modelVariant !== 'EMBEDDING') {
|
|
2311
2375
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
2312
2376
|
}
|
|
2313
|
-
const modelName =
|
|
2377
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultEmbeddingModel().modelName;
|
|
2314
2378
|
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
2315
2379
|
const rawRequest = {
|
|
2316
2380
|
input: rawPromptContent,
|
|
@@ -2320,44 +2384,95 @@ class OpenAiCompatibleExecutionTools {
|
|
|
2320
2384
|
if (this.options.isVerbose) {
|
|
2321
2385
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
2322
2386
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2387
|
+
try {
|
|
2388
|
+
const rawResponse = await this.limiter
|
|
2389
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
|
|
2390
|
+
.catch((error) => {
|
|
2391
|
+
assertsError(error);
|
|
2392
|
+
if (this.options.isVerbose) {
|
|
2393
|
+
console.info(colors.bgRed('error'), error);
|
|
2394
|
+
}
|
|
2395
|
+
throw error;
|
|
2396
|
+
});
|
|
2327
2397
|
if (this.options.isVerbose) {
|
|
2328
|
-
console.info(colors.
|
|
2398
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
2329
2399
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2400
|
+
const complete = $getCurrentDate();
|
|
2401
|
+
if (rawResponse.data.length !== 1) {
|
|
2402
|
+
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2403
|
+
}
|
|
2404
|
+
const resultContent = rawResponse.data[0].embedding;
|
|
2405
|
+
const usage = this.computeUsage(content || '', '', rawResponse);
|
|
2406
|
+
return exportJson({
|
|
2407
|
+
name: 'promptResult',
|
|
2408
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
2409
|
+
order: [],
|
|
2410
|
+
value: {
|
|
2411
|
+
content: resultContent,
|
|
2412
|
+
modelName: rawResponse.model || modelName,
|
|
2413
|
+
timing: {
|
|
2414
|
+
start,
|
|
2415
|
+
complete,
|
|
2416
|
+
},
|
|
2417
|
+
usage,
|
|
2418
|
+
rawPromptContent,
|
|
2419
|
+
rawRequest,
|
|
2420
|
+
rawResponse,
|
|
2421
|
+
},
|
|
2422
|
+
});
|
|
2334
2423
|
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2424
|
+
catch (error) {
|
|
2425
|
+
assertsError(error);
|
|
2426
|
+
if (!isUnsupportedParameterError(error)) {
|
|
2427
|
+
if (attemptStack.length > 0) {
|
|
2428
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2429
|
+
attemptStack
|
|
2430
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2431
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2432
|
+
`, Error: ${a.errorMessage}` +
|
|
2433
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2434
|
+
.join('\n') +
|
|
2435
|
+
`\nFinal error: ${error.message}`);
|
|
2436
|
+
}
|
|
2437
|
+
throw error;
|
|
2438
|
+
}
|
|
2439
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
2440
|
+
if (!unsupportedParameter) {
|
|
2441
|
+
if (this.options.isVerbose) {
|
|
2442
|
+
console.warn(colors.bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
2443
|
+
}
|
|
2444
|
+
throw error;
|
|
2445
|
+
}
|
|
2446
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
2447
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
2448
|
+
attemptStack.push({
|
|
2449
|
+
modelName,
|
|
2450
|
+
unsupportedParameter,
|
|
2451
|
+
errorMessage: error.message,
|
|
2452
|
+
stripped: true,
|
|
2453
|
+
});
|
|
2454
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
2455
|
+
attemptStack
|
|
2456
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
2457
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
2458
|
+
`, Error: ${a.errorMessage}` +
|
|
2459
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
2460
|
+
.join('\n') +
|
|
2461
|
+
`\nFinal error: ${error.message}`);
|
|
2462
|
+
}
|
|
2463
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
2464
|
+
if (this.options.isVerbose) {
|
|
2465
|
+
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
2466
|
+
}
|
|
2467
|
+
attemptStack.push({
|
|
2468
|
+
modelName,
|
|
2469
|
+
unsupportedParameter,
|
|
2470
|
+
errorMessage: error.message,
|
|
2471
|
+
stripped: true,
|
|
2472
|
+
});
|
|
2473
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
2474
|
+
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
2338
2475
|
}
|
|
2339
|
-
const resultContent = rawResponse.data[0].embedding;
|
|
2340
|
-
const usage = this.computeUsage(content || '', '',
|
|
2341
|
-
// <- Note: Embedding does not have result content
|
|
2342
|
-
rawResponse);
|
|
2343
|
-
return exportJson({
|
|
2344
|
-
name: 'promptResult',
|
|
2345
|
-
message: `Result of \`OpenAiCompatibleExecutionTools.callEmbeddingModel\``,
|
|
2346
|
-
order: [],
|
|
2347
|
-
value: {
|
|
2348
|
-
content: resultContent,
|
|
2349
|
-
modelName: rawResponse.model || modelName,
|
|
2350
|
-
timing: {
|
|
2351
|
-
start,
|
|
2352
|
-
complete,
|
|
2353
|
-
},
|
|
2354
|
-
usage,
|
|
2355
|
-
rawPromptContent,
|
|
2356
|
-
rawRequest,
|
|
2357
|
-
rawResponse,
|
|
2358
|
-
// <- [🗯]
|
|
2359
|
-
},
|
|
2360
|
-
});
|
|
2361
2476
|
}
|
|
2362
2477
|
// <- Note: [🤖] callXxxModel
|
|
2363
2478
|
/**
|