@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.
- package/esm/index.es.js +259 -105
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +30 -0
- package/esm/typings/src/_packages/core.index.d.ts +12 -0
- package/esm/typings/src/_packages/types.index.d.ts +12 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +11 -4
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +3 -0
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +4 -22
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.d.ts +1 -26
- package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/DELETE/DELETE.d.ts +0 -24
- package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/GOAL/GOAL.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -6
- package/esm/typings/src/book-2.0/commitments/MEMORY/MEMORY.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/MESSAGE/MESSAGE.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/META/META.d.ts +0 -6
- package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +0 -6
- package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +0 -6
- package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +23 -14
- package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +2 -14
- package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/SCENARIO/SCENARIO.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +0 -12
- package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-2.0/commitments/index.d.ts +1 -1
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +3 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarChip/AvatarChip.d.ts +5 -2
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +3 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/MockedChat.d.ts +18 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +8 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +2 -15
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +5 -1
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +9 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/hooks/index.d.ts +2 -0
- package/esm/typings/src/book-components/Chat/hooks/useChatAutoScroll.d.ts +41 -0
- package/esm/typings/src/book-components/Chat/hooks/useSendMessageToLlmChat.d.ts +44 -0
- package/esm/typings/src/book-components/Chat/utils/parseMessageButtons.d.ts +22 -0
- package/esm/typings/src/book-components/Chat/utils/savePlugins.d.ts +55 -0
- package/esm/typings/src/book-components/icons/PauseIcon.d.ts +8 -0
- package/esm/typings/src/book-components/icons/PlayIcon.d.ts +8 -0
- package/esm/typings/src/execution/PromptResult.d.ts +2 -4
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -2
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +1 -3
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +8 -2
- package/esm/typings/src/llm-providers/_common/utils/removeUnsupportedModelRequirements.d.ts +25 -0
- package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +7 -18
- package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +11 -0
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +58 -0
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +29 -0
- package/esm/typings/src/llm-providers/agent/playground/playground.d.ts +8 -0
- package/esm/typings/src/llm-providers/agent/register-configuration.d.ts +11 -0
- package/esm/typings/src/llm-providers/agent/register-constructor.d.ts +13 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -8
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -5
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +4 -10
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +4 -6
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +16 -8
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -8
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +5 -14
- package/esm/typings/src/personas/preparePersona.d.ts +1 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +31 -31
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -2
- package/esm/typings/src/types/ModelRequirements.d.ts +2 -4
- package/esm/typings/src/utils/color/utils/colorSaturation.d.ts +1 -1
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +1 -1
- package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +0 -1
- package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +2 -2
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +259 -105
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-2.0/utils/extractAgentMetadata.d.ts +0 -17
- package/esm/typings/src/book-2.0/utils/extractProfileImageFromSystemMessage.d.ts +0 -12
- package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +0 -16
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +0 -10
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +0 -10
- package/esm/typings/src/llm-providers/_common/profiles/llmProviderProfiles.d.ts +0 -81
- /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.
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
2070
|
+
const { content, parameters, format } = prompt;
|
|
2005
2071
|
const client = await this.getClient();
|
|
2006
2072
|
// TODO: [â] Use here more modelRequirements
|
|
2007
|
-
if (
|
|
2073
|
+
if (currentModelRequirements.modelVariant !== 'CHAT') {
|
|
2008
2074
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
2009
2075
|
}
|
|
2010
|
-
const modelName =
|
|
2076
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultChatModel().modelName;
|
|
2011
2077
|
const modelSettings = {
|
|
2012
2078
|
model: modelName,
|
|
2013
|
-
max_tokens:
|
|
2014
|
-
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
|
-
...(
|
|
2095
|
+
...(currentModelRequirements.systemMessage === undefined
|
|
2030
2096
|
? []
|
|
2031
2097
|
: [
|
|
2032
2098
|
{
|
|
2033
2099
|
role: 'system',
|
|
2034
|
-
content:
|
|
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
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
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"].
|
|
2125
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
2054
2126
|
}
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
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
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
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
|
|
2207
|
+
const { content, parameters } = prompt;
|
|
2101
2208
|
const client = await this.getClient();
|
|
2102
2209
|
// TODO: [â] Use here more modelRequirements
|
|
2103
|
-
if (
|
|
2210
|
+
if (currentModelRequirements.modelVariant !== 'COMPLETION') {
|
|
2104
2211
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
2105
2212
|
}
|
|
2106
|
-
const modelName =
|
|
2213
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultCompletionModel().modelName;
|
|
2107
2214
|
const modelSettings = {
|
|
2108
2215
|
model: modelName,
|
|
2109
|
-
max_tokens:
|
|
2110
|
-
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
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
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"].
|
|
2242
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
2130
2243
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
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
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
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.
|
|
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
|
|
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
|
*
|