@promptbook/ollama 0.101.0-9 → 0.102.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/esm/index.es.js +259 -105
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +30 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +12 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +12 -0
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +11 -4
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +3 -0
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +4 -22
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.d.ts +1 -26
  10. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +0 -12
  11. package/esm/typings/src/book-2.0/commitments/DELETE/DELETE.d.ts +0 -24
  12. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +0 -12
  13. package/esm/typings/src/book-2.0/commitments/GOAL/GOAL.d.ts +0 -12
  14. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -6
  15. package/esm/typings/src/book-2.0/commitments/MEMORY/MEMORY.d.ts +0 -12
  16. package/esm/typings/src/book-2.0/commitments/MESSAGE/MESSAGE.d.ts +0 -12
  17. package/esm/typings/src/book-2.0/commitments/META/META.d.ts +0 -6
  18. package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +0 -6
  19. package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +0 -6
  20. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +23 -14
  21. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +2 -14
  22. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +0 -12
  23. package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +0 -12
  24. package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +0 -12
  25. package/esm/typings/src/book-2.0/commitments/SCENARIO/SCENARIO.d.ts +0 -12
  26. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +0 -12
  27. package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +1 -1
  28. package/esm/typings/src/book-2.0/commitments/index.d.ts +1 -1
  29. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +3 -0
  30. package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +5 -2
  31. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +3 -0
  32. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/MockedChat.d.ts +18 -1
  33. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +8 -0
  34. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +2 -15
  35. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +5 -1
  36. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +9 -0
  37. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +13 -0
  38. package/esm/typings/src/book-components/Chat/hooks/index.d.ts +2 -0
  39. package/esm/typings/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +41 -0
  40. package/esm/typings/src/book-components/Chat/hooks/useSendMessageToLlmChat.d.ts +44 -0
  41. package/esm/typings/src/book-components/Chat/utils/parseMessageButtons.d.ts +22 -0
  42. package/esm/typings/src/book-components/Chat/utils/savePlugins.d.ts +55 -0
  43. package/esm/typings/src/book-components/icons/PauseIcon.d.ts +8 -0
  44. package/esm/typings/src/book-components/icons/PlayIcon.d.ts +8 -0
  45. package/esm/typings/src/execution/PromptResult.d.ts +2 -4
  46. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -2
  47. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +1 -3
  48. package/esm/typings/src/formats/csv/CsvFormatError.d.ts +1 -1
  49. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  50. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  51. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -2
  52. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +8 -2
  53. package/esm/typings/src/llm-providers/_common/utils/removeUnsupportedModelRequirements.d.ts +25 -0
  54. package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +7 -18
  55. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +11 -0
  56. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +2 -1
  57. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +58 -0
  58. package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +29 -0
  59. package/esm/typings/src/llm-providers/agent/playground/playground.d.ts +8 -0
  60. package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +11 -0
  61. package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +13 -0
  62. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -8
  63. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -5
  64. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -0
  65. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +4 -10
  66. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +4 -6
  67. package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +3 -3
  68. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +16 -8
  69. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -8
  70. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +5 -14
  71. package/esm/typings/src/personas/preparePersona.d.ts +1 -0
  72. package/esm/typings/src/remote-server/openapi-types.d.ts +31 -31
  73. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -2
  74. package/esm/typings/src/types/ModelRequirements.d.ts +2 -4
  75. package/esm/typings/src/utils/color/utils/colorSaturation.d.ts +1 -1
  76. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +1 -1
  77. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +0 -1
  78. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +2 -2
  79. package/esm/typings/src/version.d.ts +1 -1
  80. package/package.json +2 -2
  81. package/umd/index.umd.js +259 -105
  82. package/umd/index.umd.js.map +1 -1
  83. package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +0 -17
  84. package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +0 -12
  85. package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +0 -16
  86. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +0 -10
  87. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +0 -10
  88. package/esm/typings/src/llm-providers/_common/profiles/llmProviderProfiles.d.ts +0 -81
  89. /package/esm/typings/src/llm-providers/_common/{profiles/test/llmProviderProfiles.test.d.ts → utils/removeUnsupportedModelRequirements.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.101.0-9';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-0';
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
@@ -1126,7 +1126,7 @@
1126
1126
  modelVariant: 'CHAT',
1127
1127
  modelTitle: 'gpt-5-mini',
1128
1128
  modelName: 'gpt-5-mini',
1129
- modelDescription: "A faster, cost-efficient version of GPT-5 for well-defined tasks with 200K context window. Maintains core GPT-5 capabilities while offering 5x faster inference and significantly lower costs. Features enhanced instruction following and reduced latency for production applications requiring quick responses with high quality.",
1129
+ modelDescription: 'A faster, cost-efficient version of GPT-5 for well-defined tasks with 200K context window. Maintains core GPT-5 capabilities while offering 5x faster inference and significantly lower costs. Features enhanced instruction following and reduced latency for production applications requiring quick responses with high quality.',
1130
1130
  pricing: {
1131
1131
  prompt: pricing(`$0.25 / 1M tokens`),
1132
1132
  output: pricing(`$2.00 / 1M tokens`),
@@ -1138,7 +1138,7 @@
1138
1138
  modelVariant: 'CHAT',
1139
1139
  modelTitle: 'gpt-5-nano',
1140
1140
  modelName: 'gpt-5-nano',
1141
- modelDescription: "The fastest, most cost-efficient version of GPT-5 with 200K context window. Optimized for summarization, classification, and simple reasoning tasks. Features 10x faster inference than base GPT-5 while maintaining good quality for straightforward applications. Ideal for high-volume, cost-sensitive deployments.",
1141
+ modelDescription: 'The fastest, most cost-efficient version of GPT-5 with 200K context window. Optimized for summarization, classification, and simple reasoning tasks. Features 10x faster inference than base GPT-5 while maintaining good quality for straightforward applications. Ideal for high-volume, cost-sensitive deployments.',
1142
1142
  pricing: {
1143
1143
  prompt: pricing(`$0.05 / 1M tokens`),
1144
1144
  output: pricing(`$0.40 / 1M tokens`),
@@ -1150,7 +1150,7 @@
1150
1150
  modelVariant: 'CHAT',
1151
1151
  modelTitle: 'gpt-4.1',
1152
1152
  modelName: 'gpt-4.1',
1153
- modelDescription: "Smartest non-reasoning model with 128K context window. Enhanced version of GPT-4 with improved instruction following, better factual accuracy, and reduced hallucinations. Features advanced function calling capabilities and superior performance on coding tasks. Ideal for applications requiring high intelligence without reasoning overhead.",
1153
+ modelDescription: 'Smartest non-reasoning model with 128K context window. Enhanced version of GPT-4 with improved instruction following, better factual accuracy, and reduced hallucinations. Features advanced function calling capabilities and superior performance on coding tasks. Ideal for applications requiring high intelligence without reasoning overhead.',
1154
1154
  pricing: {
1155
1155
  prompt: pricing(`$3.00 / 1M tokens`),
1156
1156
  output: pricing(`$12.00 / 1M tokens`),
@@ -1162,7 +1162,7 @@
1162
1162
  modelVariant: 'CHAT',
1163
1163
  modelTitle: 'gpt-4.1-mini',
1164
1164
  modelName: 'gpt-4.1-mini',
1165
- modelDescription: "Smaller, faster version of GPT-4.1 with 128K context window. Balances intelligence and efficiency with 3x faster inference than base GPT-4.1. Maintains strong capabilities across text generation, reasoning, and coding while offering better cost-performance ratio for most applications.",
1165
+ modelDescription: 'Smaller, faster version of GPT-4.1 with 128K context window. Balances intelligence and efficiency with 3x faster inference than base GPT-4.1. Maintains strong capabilities across text generation, reasoning, and coding while offering better cost-performance ratio for most applications.',
1166
1166
  pricing: {
1167
1167
  prompt: pricing(`$0.80 / 1M tokens`),
1168
1168
  output: pricing(`$3.20 / 1M tokens`),
@@ -1174,7 +1174,7 @@
1174
1174
  modelVariant: 'CHAT',
1175
1175
  modelTitle: 'gpt-4.1-nano',
1176
1176
  modelName: 'gpt-4.1-nano',
1177
- modelDescription: "Fastest, most cost-efficient version of GPT-4.1 with 128K context window. Optimized for high-throughput applications requiring good quality at minimal cost. Features 5x faster inference than GPT-4.1 while maintaining adequate performance for most general-purpose tasks.",
1177
+ modelDescription: 'Fastest, most cost-efficient version of GPT-4.1 with 128K context window. Optimized for high-throughput applications requiring good quality at minimal cost. Features 5x faster inference than GPT-4.1 while maintaining adequate performance for most general-purpose tasks.',
1178
1178
  pricing: {
1179
1179
  prompt: pricing(`$0.20 / 1M tokens`),
1180
1180
  output: pricing(`$0.80 / 1M tokens`),
@@ -1186,7 +1186,7 @@
1186
1186
  modelVariant: 'CHAT',
1187
1187
  modelTitle: 'o3',
1188
1188
  modelName: 'o3',
1189
- modelDescription: "Advanced reasoning model with 128K context window specializing in complex logical, mathematical, and analytical tasks. Successor to o1 with enhanced step-by-step problem-solving capabilities and superior performance on STEM-focused problems. Ideal for professional applications requiring deep analytical thinking and precise reasoning.",
1189
+ modelDescription: 'Advanced reasoning model with 128K context window specializing in complex logical, mathematical, and analytical tasks. Successor to o1 with enhanced step-by-step problem-solving capabilities and superior performance on STEM-focused problems. Ideal for professional applications requiring deep analytical thinking and precise reasoning.',
1190
1190
  pricing: {
1191
1191
  prompt: pricing(`$15.00 / 1M tokens`),
1192
1192
  output: pricing(`$60.00 / 1M tokens`),
@@ -1198,7 +1198,7 @@
1198
1198
  modelVariant: 'CHAT',
1199
1199
  modelTitle: 'o3-pro',
1200
1200
  modelName: 'o3-pro',
1201
- modelDescription: "Enhanced version of o3 with more compute allocated for better responses on the most challenging problems. Features extended reasoning time and improved accuracy on complex analytical tasks. Designed for applications where maximum reasoning quality is more important than response speed.",
1201
+ modelDescription: 'Enhanced version of o3 with more compute allocated for better responses on the most challenging problems. Features extended reasoning time and improved accuracy on complex analytical tasks. Designed for applications where maximum reasoning quality is more important than response speed.',
1202
1202
  pricing: {
1203
1203
  prompt: pricing(`$30.00 / 1M tokens`),
1204
1204
  output: pricing(`$120.00 / 1M tokens`),
@@ -1210,7 +1210,7 @@
1210
1210
  modelVariant: 'CHAT',
1211
1211
  modelTitle: 'o4-mini',
1212
1212
  modelName: 'o4-mini',
1213
- modelDescription: "Fast, cost-efficient reasoning model with 128K context window. Successor to o1-mini with improved analytical capabilities while maintaining speed advantages. Features enhanced mathematical reasoning and logical problem-solving at significantly lower cost than full reasoning models.",
1213
+ modelDescription: 'Fast, cost-efficient reasoning model with 128K context window. Successor to o1-mini with improved analytical capabilities while maintaining speed advantages. Features enhanced mathematical reasoning and logical problem-solving at significantly lower cost than full reasoning models.',
1214
1214
  pricing: {
1215
1215
  prompt: pricing(`$4.00 / 1M tokens`),
1216
1216
  output: pricing(`$16.00 / 1M tokens`),
@@ -1222,7 +1222,7 @@
1222
1222
  modelVariant: 'CHAT',
1223
1223
  modelTitle: 'o3-deep-research',
1224
1224
  modelName: 'o3-deep-research',
1225
- modelDescription: "Most powerful deep research model with 128K context window. Specialized for comprehensive research tasks, literature analysis, and complex information synthesis. Features advanced citation capabilities and enhanced factual accuracy for academic and professional research applications.",
1225
+ modelDescription: 'Most powerful deep research model with 128K context window. Specialized for comprehensive research tasks, literature analysis, and complex information synthesis. Features advanced citation capabilities and enhanced factual accuracy for academic and professional research applications.',
1226
1226
  pricing: {
1227
1227
  prompt: pricing(`$25.00 / 1M tokens`),
1228
1228
  output: pricing(`$100.00 / 1M tokens`),
@@ -1234,7 +1234,7 @@
1234
1234
  modelVariant: 'CHAT',
1235
1235
  modelTitle: 'o4-mini-deep-research',
1236
1236
  modelName: 'o4-mini-deep-research',
1237
- modelDescription: "Faster, more affordable deep research model with 128K context window. Balances research capabilities with cost efficiency, offering good performance on literature review, fact-checking, and information synthesis tasks at a more accessible price point.",
1237
+ modelDescription: 'Faster, more affordable deep research model with 128K context window. Balances research capabilities with cost efficiency, offering good performance on literature review, fact-checking, and information synthesis tasks at a more accessible price point.',
1238
1238
  pricing: {
1239
1239
  prompt: pricing(`$12.00 / 1M tokens`),
1240
1240
  output: pricing(`$48.00 / 1M tokens`),
@@ -1919,6 +1919,62 @@
1919
1919
  return replacedTemplates;
1920
1920
  }
1921
1921
 
1922
+ /**
1923
+ * Parses an OpenAI error message to identify which parameter is unsupported
1924
+ *
1925
+ * @param errorMessage The error message from OpenAI API
1926
+ * @returns The parameter name that is unsupported, or null if not an unsupported parameter error
1927
+ * @private utility of LLM Tools
1928
+ */
1929
+ function parseUnsupportedParameterError(errorMessage) {
1930
+ // Pattern to match "Unsupported value: 'parameter' does not support ..."
1931
+ const unsupportedValueMatch = errorMessage.match(/Unsupported value:\s*'([^']+)'\s*does not support/i);
1932
+ if (unsupportedValueMatch === null || unsupportedValueMatch === void 0 ? void 0 : unsupportedValueMatch[1]) {
1933
+ return unsupportedValueMatch[1];
1934
+ }
1935
+ // Pattern to match "'parameter' of type ... is not supported with this model"
1936
+ const parameterTypeMatch = errorMessage.match(/'([^']+)'\s*of type.*is not supported with this model/i);
1937
+ if (parameterTypeMatch === null || parameterTypeMatch === void 0 ? void 0 : parameterTypeMatch[1]) {
1938
+ return parameterTypeMatch[1];
1939
+ }
1940
+ return null;
1941
+ }
1942
+ /**
1943
+ * Creates a copy of model requirements with the specified parameter removed
1944
+ *
1945
+ * @param modelRequirements Original model requirements
1946
+ * @param unsupportedParameter The parameter to remove
1947
+ * @returns New model requirements without the unsupported parameter
1948
+ * @private utility of LLM Tools
1949
+ */
1950
+ function removeUnsupportedModelRequirement(modelRequirements, unsupportedParameter) {
1951
+ const newRequirements = { ...modelRequirements };
1952
+ // Map of parameter names that might appear in error messages to ModelRequirements properties
1953
+ const parameterMap = {
1954
+ temperature: 'temperature',
1955
+ max_tokens: 'maxTokens',
1956
+ maxTokens: 'maxTokens',
1957
+ seed: 'seed',
1958
+ };
1959
+ const propertyToRemove = parameterMap[unsupportedParameter];
1960
+ if (propertyToRemove && propertyToRemove in newRequirements) {
1961
+ delete newRequirements[propertyToRemove];
1962
+ }
1963
+ return newRequirements;
1964
+ }
1965
+ /**
1966
+ * Checks if an error is an "Unsupported value" error from OpenAI
1967
+ * @param error The error to check
1968
+ * @returns true if this is an unsupported parameter error
1969
+ * @private utility of LLM Tools
1970
+ */
1971
+ function isUnsupportedParameterError(error) {
1972
+ const errorMessage = error.message.toLowerCase();
1973
+ return (errorMessage.includes('unsupported value:') ||
1974
+ errorMessage.includes('is not supported with this model') ||
1975
+ errorMessage.includes('does not support'));
1976
+ }
1977
+
1922
1978
  /**
1923
1979
  * Execution Tools for calling OpenAI API or other OpenAI compatible provider
1924
1980
  *
@@ -1936,6 +1992,10 @@
1936
1992
  * OpenAI API client.
1937
1993
  */
1938
1994
  this.client = null;
1995
+ /**
1996
+ * Tracks models and parameters that have already been retried to prevent infinite loops
1997
+ */
1998
+ this.retriedUnsupportedParameters = new Set();
1939
1999
  // TODO: Allow configuring rate limits via options
1940
2000
  this.limiter = new Bottleneck__default["default"]({
1941
2001
  minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
@@ -1997,21 +2057,27 @@
1997
2057
  * Calls OpenAI compatible API to use a chat model.
1998
2058
  */
1999
2059
  async callChatModel(prompt) {
2060
+ return this.callChatModelWithRetry(prompt, prompt.modelRequirements);
2061
+ }
2062
+ /**
2063
+ * Internal method that handles parameter retry for chat model calls
2064
+ */
2065
+ async callChatModelWithRetry(prompt, currentModelRequirements) {
2000
2066
  var _a;
2001
2067
  if (this.options.isVerbose) {
2002
- console.info(`💎 ${this.title} callChatModel call`, { prompt });
2068
+ console.info(`💎 ${this.title} callChatModel call`, { prompt, currentModelRequirements });
2003
2069
  }
2004
- const { content, parameters, modelRequirements, format } = prompt;
2070
+ const { content, parameters, format } = prompt;
2005
2071
  const client = await this.getClient();
2006
2072
  // TODO: [☂] Use here more modelRequirements
2007
- if (modelRequirements.modelVariant !== 'CHAT') {
2073
+ if (currentModelRequirements.modelVariant !== 'CHAT') {
2008
2074
  throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
2009
2075
  }
2010
- const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
2076
+ const modelName = currentModelRequirements.modelName || this.getDefaultChatModel().modelName;
2011
2077
  const modelSettings = {
2012
2078
  model: modelName,
2013
- max_tokens: modelRequirements.maxTokens,
2014
- temperature: modelRequirements.temperature,
2079
+ max_tokens: currentModelRequirements.maxTokens,
2080
+ temperature: currentModelRequirements.temperature,
2015
2081
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
2016
2082
  // <- Note: [🧆]
2017
2083
  }; // <- TODO: [ðŸ’Đ] Guard here types better
@@ -2026,12 +2092,12 @@
2026
2092
  const rawRequest = {
2027
2093
  ...modelSettings,
2028
2094
  messages: [
2029
- ...(modelRequirements.systemMessage === undefined
2095
+ ...(currentModelRequirements.systemMessage === undefined
2030
2096
  ? []
2031
2097
  : [
2032
2098
  {
2033
2099
  role: 'system',
2034
- content: modelRequirements.systemMessage,
2100
+ content: currentModelRequirements.systemMessage,
2035
2101
  },
2036
2102
  ]),
2037
2103
  {
@@ -2045,69 +2111,110 @@
2045
2111
  if (this.options.isVerbose) {
2046
2112
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2047
2113
  }
2048
- const rawResponse = await this.limiter
2049
- .schedule(() => this.makeRequestWithRetry(() => client.chat.completions.create(rawRequest)))
2050
- .catch((error) => {
2051
- assertsError(error);
2114
+ try {
2115
+ const rawResponse = await this.limiter
2116
+ .schedule(() => this.makeRequestWithNetworkRetry(() => client.chat.completions.create(rawRequest)))
2117
+ .catch((error) => {
2118
+ assertsError(error);
2119
+ if (this.options.isVerbose) {
2120
+ console.info(colors__default["default"].bgRed('error'), error);
2121
+ }
2122
+ throw error;
2123
+ });
2052
2124
  if (this.options.isVerbose) {
2053
- console.info(colors__default["default"].bgRed('error'), error);
2125
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2054
2126
  }
2055
- throw error;
2056
- });
2057
- if (this.options.isVerbose) {
2058
- console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2059
- }
2060
- const complete = $getCurrentDate();
2061
- if (!rawResponse.choices[0]) {
2062
- throw new PipelineExecutionError(`No choises from ${this.title}`);
2063
- }
2064
- if (rawResponse.choices.length > 1) {
2065
- // TODO: This should be maybe only warning
2066
- throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2127
+ const complete = $getCurrentDate();
2128
+ if (!rawResponse.choices[0]) {
2129
+ throw new PipelineExecutionError(`No choises from ${this.title}`);
2130
+ }
2131
+ if (rawResponse.choices.length > 1) {
2132
+ // TODO: This should be maybe only warning
2133
+ throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2134
+ }
2135
+ const resultContent = rawResponse.choices[0].message.content;
2136
+ const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
2137
+ if (resultContent === null) {
2138
+ throw new PipelineExecutionError(`No response message from ${this.title}`);
2139
+ }
2140
+ return exportJson({
2141
+ name: 'promptResult',
2142
+ message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
2143
+ order: [],
2144
+ value: {
2145
+ content: resultContent,
2146
+ modelName: rawResponse.model || modelName,
2147
+ timing: {
2148
+ start,
2149
+ complete,
2150
+ },
2151
+ usage,
2152
+ rawPromptContent,
2153
+ rawRequest,
2154
+ rawResponse,
2155
+ // <- [ðŸ—Ŋ]
2156
+ },
2157
+ });
2067
2158
  }
2068
- const resultContent = rawResponse.choices[0].message.content;
2069
- const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
2070
- if (resultContent === null) {
2071
- throw new PipelineExecutionError(`No response message from ${this.title}`);
2159
+ catch (error) {
2160
+ assertsError(error);
2161
+ // Check if this is an unsupported parameter error
2162
+ if (!isUnsupportedParameterError(error)) {
2163
+ throw error;
2164
+ }
2165
+ // Parse which parameter is unsupported
2166
+ const unsupportedParameter = parseUnsupportedParameterError(error.message);
2167
+ if (!unsupportedParameter) {
2168
+ if (this.options.isVerbose) {
2169
+ console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
2170
+ }
2171
+ throw error;
2172
+ }
2173
+ // Create a unique key for this model + parameter combination to prevent infinite loops
2174
+ const retryKey = `${modelName}-${unsupportedParameter}`;
2175
+ if (this.retriedUnsupportedParameters.has(retryKey)) {
2176
+ // Already retried this parameter, throw the error
2177
+ if (this.options.isVerbose) {
2178
+ console.warn(colors__default["default"].bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2179
+ }
2180
+ throw error;
2181
+ }
2182
+ // Mark this parameter as retried
2183
+ this.retriedUnsupportedParameters.add(retryKey);
2184
+ // Log warning in verbose mode
2185
+ if (this.options.isVerbose) {
2186
+ console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2187
+ }
2188
+ // Remove the unsupported parameter and retry
2189
+ const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2190
+ return this.callChatModelWithRetry(prompt, modifiedModelRequirements);
2072
2191
  }
2073
- return exportJson({
2074
- name: 'promptResult',
2075
- message: `Result of \`OpenAiCompatibleExecutionTools.callChatModel\``,
2076
- order: [],
2077
- value: {
2078
- content: resultContent,
2079
- modelName: rawResponse.model || modelName,
2080
- timing: {
2081
- start,
2082
- complete,
2083
- },
2084
- usage,
2085
- rawPromptContent,
2086
- rawRequest,
2087
- rawResponse,
2088
- // <- [ðŸ—Ŋ]
2089
- },
2090
- });
2091
2192
  }
2092
2193
  /**
2093
2194
  * Calls OpenAI API to use a complete model.
2094
2195
  */
2095
2196
  async callCompletionModel(prompt) {
2197
+ return this.callCompletionModelWithRetry(prompt, prompt.modelRequirements);
2198
+ }
2199
+ /**
2200
+ * Internal method that handles parameter retry for completion model calls
2201
+ */
2202
+ async callCompletionModelWithRetry(prompt, currentModelRequirements) {
2096
2203
  var _a;
2097
2204
  if (this.options.isVerbose) {
2098
- console.info(`🖋 ${this.title} callCompletionModel call`, { prompt });
2205
+ console.info(`🖋 ${this.title} callCompletionModel call`, { prompt, currentModelRequirements });
2099
2206
  }
2100
- const { content, parameters, modelRequirements } = prompt;
2207
+ const { content, parameters } = prompt;
2101
2208
  const client = await this.getClient();
2102
2209
  // TODO: [☂] Use here more modelRequirements
2103
- if (modelRequirements.modelVariant !== 'COMPLETION') {
2210
+ if (currentModelRequirements.modelVariant !== 'COMPLETION') {
2104
2211
  throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
2105
2212
  }
2106
- const modelName = modelRequirements.modelName || this.getDefaultCompletionModel().modelName;
2213
+ const modelName = currentModelRequirements.modelName || this.getDefaultCompletionModel().modelName;
2107
2214
  const modelSettings = {
2108
2215
  model: modelName,
2109
- max_tokens: modelRequirements.maxTokens,
2110
- temperature: modelRequirements.temperature,
2216
+ max_tokens: currentModelRequirements.maxTokens,
2217
+ temperature: currentModelRequirements.temperature,
2111
2218
  // <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
2112
2219
  // <- Note: [🧆]
2113
2220
  };
@@ -2121,46 +2228,81 @@
2121
2228
  if (this.options.isVerbose) {
2122
2229
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2123
2230
  }
2124
- const rawResponse = await this.limiter
2125
- .schedule(() => this.makeRequestWithRetry(() => client.completions.create(rawRequest)))
2126
- .catch((error) => {
2127
- assertsError(error);
2231
+ try {
2232
+ const rawResponse = await this.limiter
2233
+ .schedule(() => this.makeRequestWithNetworkRetry(() => client.completions.create(rawRequest)))
2234
+ .catch((error) => {
2235
+ assertsError(error);
2236
+ if (this.options.isVerbose) {
2237
+ console.info(colors__default["default"].bgRed('error'), error);
2238
+ }
2239
+ throw error;
2240
+ });
2128
2241
  if (this.options.isVerbose) {
2129
- console.info(colors__default["default"].bgRed('error'), error);
2242
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2130
2243
  }
2131
- throw error;
2132
- });
2133
- if (this.options.isVerbose) {
2134
- console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
2135
- }
2136
- const complete = $getCurrentDate();
2137
- if (!rawResponse.choices[0]) {
2138
- throw new PipelineExecutionError(`No choises from ${this.title}`);
2244
+ const complete = $getCurrentDate();
2245
+ if (!rawResponse.choices[0]) {
2246
+ throw new PipelineExecutionError(`No choises from ${this.title}`);
2247
+ }
2248
+ if (rawResponse.choices.length > 1) {
2249
+ // TODO: This should be maybe only warning
2250
+ throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2251
+ }
2252
+ const resultContent = rawResponse.choices[0].text;
2253
+ const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
2254
+ return exportJson({
2255
+ name: 'promptResult',
2256
+ message: `Result of \`OpenAiCompatibleExecutionTools.callCompletionModel\``,
2257
+ order: [],
2258
+ value: {
2259
+ content: resultContent,
2260
+ modelName: rawResponse.model || modelName,
2261
+ timing: {
2262
+ start,
2263
+ complete,
2264
+ },
2265
+ usage,
2266
+ rawPromptContent,
2267
+ rawRequest,
2268
+ rawResponse,
2269
+ // <- [ðŸ—Ŋ]
2270
+ },
2271
+ });
2139
2272
  }
2140
- if (rawResponse.choices.length > 1) {
2141
- // TODO: This should be maybe only warning
2142
- throw new PipelineExecutionError(`More than one choise from ${this.title}`);
2273
+ catch (error) {
2274
+ assertsError(error);
2275
+ // Check if this is an unsupported parameter error
2276
+ if (!isUnsupportedParameterError(error)) {
2277
+ throw error;
2278
+ }
2279
+ // Parse which parameter is unsupported
2280
+ const unsupportedParameter = parseUnsupportedParameterError(error.message);
2281
+ if (!unsupportedParameter) {
2282
+ if (this.options.isVerbose) {
2283
+ console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
2284
+ }
2285
+ throw error;
2286
+ }
2287
+ // Create a unique key for this model + parameter combination to prevent infinite loops
2288
+ const retryKey = `${modelName}-${unsupportedParameter}`;
2289
+ if (this.retriedUnsupportedParameters.has(retryKey)) {
2290
+ // Already retried this parameter, throw the error
2291
+ if (this.options.isVerbose) {
2292
+ console.warn(colors__default["default"].bgRed('Error'), `Parameter '${unsupportedParameter}' for model '${modelName}' already retried once, throwing error:`, error.message);
2293
+ }
2294
+ throw error;
2295
+ }
2296
+ // Mark this parameter as retried
2297
+ this.retriedUnsupportedParameters.add(retryKey);
2298
+ // Log warning in verbose mode
2299
+ if (this.options.isVerbose) {
2300
+ console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
2301
+ }
2302
+ // Remove the unsupported parameter and retry
2303
+ const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
2304
+ return this.callCompletionModelWithRetry(prompt, modifiedModelRequirements);
2143
2305
  }
2144
- const resultContent = rawResponse.choices[0].text;
2145
- const usage = this.computeUsage(content || '', resultContent || '', rawResponse);
2146
- return exportJson({
2147
- name: 'promptResult',
2148
- message: `Result of \`OpenAiCompatibleExecutionTools.callCompletionModel\``,
2149
- order: [],
2150
- value: {
2151
- content: resultContent,
2152
- modelName: rawResponse.model || modelName,
2153
- timing: {
2154
- start,
2155
- complete,
2156
- },
2157
- usage,
2158
- rawPromptContent,
2159
- rawRequest,
2160
- rawResponse,
2161
- // <- [ðŸ—Ŋ]
2162
- },
2163
- });
2164
2306
  }
2165
2307
  /**
2166
2308
  * Calls OpenAI compatible API to use a embedding model
@@ -2186,7 +2328,7 @@
2186
2328
  console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
2187
2329
  }
2188
2330
  const rawResponse = await this.limiter
2189
- .schedule(() => this.makeRequestWithRetry(() => client.embeddings.create(rawRequest)))
2331
+ .schedule(() => this.makeRequestWithNetworkRetry(() => client.embeddings.create(rawRequest)))
2190
2332
  .catch((error) => {
2191
2333
  assertsError(error);
2192
2334
  if (this.options.isVerbose) {
@@ -2248,7 +2390,7 @@
2248
2390
  /**
2249
2391
  * Makes a request with retry logic for network errors like ECONNRESET
2250
2392
  */
2251
- async makeRequestWithRetry(requestFn) {
2393
+ async makeRequestWithNetworkRetry(requestFn) {
2252
2394
  let lastError;
2253
2395
  for (let attempt = 1; attempt <= CONNECTION_RETRIES_LIMIT; attempt++) {
2254
2396
  try {
@@ -2260,8 +2402,8 @@
2260
2402
  // Check if this is a retryable network error
2261
2403
  const isRetryableError = this.isRetryableNetworkError(error);
2262
2404
  if (!isRetryableError || attempt === CONNECTION_RETRIES_LIMIT) {
2263
- if (this.options.isVerbose) {
2264
- console.info(colors__default["default"].bgRed('Final error after retries'), `Attempt ${attempt}/${CONNECTION_RETRIES_LIMIT}:`, error);
2405
+ if (this.options.isVerbose && this.isRetryableNetworkError(error)) {
2406
+ console.info(colors__default["default"].bgRed('Final network error after retries'), `Attempt ${attempt}/${CONNECTION_RETRIES_LIMIT}:`, error);
2265
2407
  }
2266
2408
  throw error;
2267
2409
  }
@@ -2271,7 +2413,7 @@
2271
2413
  const jitterDelay = Math.random() * 500; // Add some randomness
2272
2414
  const totalDelay = backoffDelay + jitterDelay;
2273
2415
  if (this.options.isVerbose) {
2274
- console.info(colors__default["default"].bgYellow('Retrying request'), `Attempt ${attempt}/${CONNECTION_RETRIES_LIMIT}, waiting ${Math.round(totalDelay)}ms:`, error.message);
2416
+ console.info(colors__default["default"].bgYellow('Retrying network request'), `Attempt ${attempt}/${CONNECTION_RETRIES_LIMIT}, waiting ${Math.round(totalDelay)}ms:`, error.message);
2275
2417
  }
2276
2418
  // Wait before retrying
2277
2419
  await new Promise((resolve) => setTimeout(resolve, totalDelay));
@@ -2320,6 +2462,7 @@
2320
2462
  * TODO: [🛄] Maybe make custom `OpenAiCompatibleError`
2321
2463
  * TODO: [🧠][🈁] Maybe use `isDeterministic` from options
2322
2464
  * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
2465
+ * TODO: [🧠][ðŸĶĒ] Make reverse adapter from LlmExecutionTools to OpenAI-compatible:
2323
2466
  */
2324
2467
 
2325
2468
  /**
@@ -2582,6 +2725,14 @@
2582
2725
  */
2583
2726
  const DEFAULT_OLLAMA_BASE_URL = 'http://localhost:11434/v1';
2584
2727
 
2728
+ /**
2729
+ * Profile for Ollama provider
2730
+ */
2731
+ const OLLAMA_PROVIDER_PROFILE = {
2732
+ name: 'OLLAMA',
2733
+ fullname: 'Ollama',
2734
+ color: '#059669',
2735
+ };
2585
2736
  /**
2586
2737
  * Execution Tools for calling Ollama API
2587
2738
  *
@@ -2604,6 +2755,9 @@
2604
2755
  get description() {
2605
2756
  return 'Use all models provided by Ollama';
2606
2757
  }
2758
+ get profile() {
2759
+ return OLLAMA_PROVIDER_PROFILE;
2760
+ }
2607
2761
  /**
2608
2762
  * List all available models (non dynamically)
2609
2763
  *