@promptbook/core 0.66.0-6 → 0.66.0-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +314 -164
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +2 -2
- package/esm/typings/src/cli/main.d.ts +2 -2
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +10 -5
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +10 -5
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +8 -4
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +8 -4
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +9 -5
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +10 -5
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +8 -4
- package/esm/typings/src/personas/preparePersona.test.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +314 -164
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -14,7 +14,7 @@ import moment from 'moment';
|
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook library
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_VERSION = '0.66.0-
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.66.0-6';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -1645,7 +1645,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1645
1645
|
});
|
|
1646
1646
|
}
|
|
1647
1647
|
|
|
1648
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0-
|
|
1648
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0-6",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0-6",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1649
1649
|
|
|
1650
1650
|
var defaultDiacriticsRemovalMap = [
|
|
1651
1651
|
{
|
|
@@ -2238,6 +2238,60 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2238
2238
|
enumerable: false,
|
|
2239
2239
|
configurable: true
|
|
2240
2240
|
});
|
|
2241
|
+
/**
|
|
2242
|
+
* Check the configuration of all execution tools
|
|
2243
|
+
*/
|
|
2244
|
+
MultipleLlmExecutionTools.prototype.checkConfiguration = function () {
|
|
2245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2246
|
+
return __generator(this, function (_a) {
|
|
2247
|
+
return [2 /*return*/];
|
|
2248
|
+
});
|
|
2249
|
+
});
|
|
2250
|
+
};
|
|
2251
|
+
/**
|
|
2252
|
+
* List all available models that can be used
|
|
2253
|
+
* This lists is a combination of all available models from all execution tools
|
|
2254
|
+
*/
|
|
2255
|
+
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
2256
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2257
|
+
var availableModels, _a, _b, llmExecutionTools, models, e_1_1;
|
|
2258
|
+
var e_1, _c;
|
|
2259
|
+
return __generator(this, function (_d) {
|
|
2260
|
+
switch (_d.label) {
|
|
2261
|
+
case 0:
|
|
2262
|
+
availableModels = [];
|
|
2263
|
+
_d.label = 1;
|
|
2264
|
+
case 1:
|
|
2265
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
2266
|
+
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
2267
|
+
_d.label = 2;
|
|
2268
|
+
case 2:
|
|
2269
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
2270
|
+
llmExecutionTools = _b.value;
|
|
2271
|
+
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
2272
|
+
case 3:
|
|
2273
|
+
models = _d.sent();
|
|
2274
|
+
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
2275
|
+
_d.label = 4;
|
|
2276
|
+
case 4:
|
|
2277
|
+
_b = _a.next();
|
|
2278
|
+
return [3 /*break*/, 2];
|
|
2279
|
+
case 5: return [3 /*break*/, 8];
|
|
2280
|
+
case 6:
|
|
2281
|
+
e_1_1 = _d.sent();
|
|
2282
|
+
e_1 = { error: e_1_1 };
|
|
2283
|
+
return [3 /*break*/, 8];
|
|
2284
|
+
case 7:
|
|
2285
|
+
try {
|
|
2286
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2287
|
+
}
|
|
2288
|
+
finally { if (e_1) throw e_1.error; }
|
|
2289
|
+
return [7 /*endfinally*/];
|
|
2290
|
+
case 8: return [2 /*return*/, availableModels];
|
|
2291
|
+
}
|
|
2292
|
+
});
|
|
2293
|
+
});
|
|
2294
|
+
};
|
|
2241
2295
|
/**
|
|
2242
2296
|
* Calls the best available chat model
|
|
2243
2297
|
*/
|
|
@@ -2264,8 +2318,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2264
2318
|
*/
|
|
2265
2319
|
MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
|
|
2266
2320
|
return __awaiter(this, void 0, void 0, function () {
|
|
2267
|
-
var errors, _a, _b, llmExecutionTools, _c, error_1,
|
|
2268
|
-
var
|
|
2321
|
+
var errors, _a, _b, llmExecutionTools, _c, error_1, e_2_1;
|
|
2322
|
+
var e_2, _d;
|
|
2269
2323
|
var _this = this;
|
|
2270
2324
|
return __generator(this, function (_e) {
|
|
2271
2325
|
switch (_e.label) {
|
|
@@ -2321,14 +2375,14 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2321
2375
|
return [3 /*break*/, 2];
|
|
2322
2376
|
case 14: return [3 /*break*/, 17];
|
|
2323
2377
|
case 15:
|
|
2324
|
-
|
|
2325
|
-
|
|
2378
|
+
e_2_1 = _e.sent();
|
|
2379
|
+
e_2 = { error: e_2_1 };
|
|
2326
2380
|
return [3 /*break*/, 17];
|
|
2327
2381
|
case 16:
|
|
2328
2382
|
try {
|
|
2329
2383
|
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
2330
2384
|
}
|
|
2331
|
-
finally { if (
|
|
2385
|
+
finally { if (e_2) throw e_2.error; }
|
|
2332
2386
|
return [7 /*endfinally*/];
|
|
2333
2387
|
case 17:
|
|
2334
2388
|
if (errors.length === 1) {
|
|
@@ -2356,50 +2410,6 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2356
2410
|
});
|
|
2357
2411
|
});
|
|
2358
2412
|
};
|
|
2359
|
-
/**
|
|
2360
|
-
* List all available models that can be used
|
|
2361
|
-
* This lists is a combination of all available models from all execution tools
|
|
2362
|
-
*/
|
|
2363
|
-
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
2364
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2365
|
-
var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
|
|
2366
|
-
var e_2, _c;
|
|
2367
|
-
return __generator(this, function (_d) {
|
|
2368
|
-
switch (_d.label) {
|
|
2369
|
-
case 0:
|
|
2370
|
-
availableModels = [];
|
|
2371
|
-
_d.label = 1;
|
|
2372
|
-
case 1:
|
|
2373
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
2374
|
-
_a = __values(this.llmExecutionTools), _b = _a.next();
|
|
2375
|
-
_d.label = 2;
|
|
2376
|
-
case 2:
|
|
2377
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
2378
|
-
llmExecutionTools = _b.value;
|
|
2379
|
-
return [4 /*yield*/, llmExecutionTools.listModels()];
|
|
2380
|
-
case 3:
|
|
2381
|
-
models = _d.sent();
|
|
2382
|
-
availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
|
|
2383
|
-
_d.label = 4;
|
|
2384
|
-
case 4:
|
|
2385
|
-
_b = _a.next();
|
|
2386
|
-
return [3 /*break*/, 2];
|
|
2387
|
-
case 5: return [3 /*break*/, 8];
|
|
2388
|
-
case 6:
|
|
2389
|
-
e_2_1 = _d.sent();
|
|
2390
|
-
e_2 = { error: e_2_1 };
|
|
2391
|
-
return [3 /*break*/, 8];
|
|
2392
|
-
case 7:
|
|
2393
|
-
try {
|
|
2394
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
2395
|
-
}
|
|
2396
|
-
finally { if (e_2) throw e_2.error; }
|
|
2397
|
-
return [7 /*endfinally*/];
|
|
2398
|
-
case 8: return [2 /*return*/, availableModels];
|
|
2399
|
-
}
|
|
2400
|
-
});
|
|
2401
|
-
});
|
|
2402
|
-
};
|
|
2403
2413
|
return MultipleLlmExecutionTools;
|
|
2404
2414
|
}());
|
|
2405
2415
|
/**
|
|
@@ -3856,6 +3866,13 @@ function countTotalUsage(llmTools) {
|
|
|
3856
3866
|
// TODO: [🧠] Maybe put here some suffix
|
|
3857
3867
|
return llmTools.description;
|
|
3858
3868
|
},
|
|
3869
|
+
checkConfiguration: function () {
|
|
3870
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3871
|
+
return __generator(this, function (_a) {
|
|
3872
|
+
return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
|
|
3873
|
+
});
|
|
3874
|
+
});
|
|
3875
|
+
},
|
|
3859
3876
|
listModels: function () {
|
|
3860
3877
|
return /* not await */ llmTools.listModels();
|
|
3861
3878
|
},
|
|
@@ -6497,6 +6514,20 @@ var CallbackInterfaceTools = /** @class */ (function () {
|
|
|
6497
6514
|
return CallbackInterfaceTools;
|
|
6498
6515
|
}());
|
|
6499
6516
|
|
|
6517
|
+
/**
|
|
6518
|
+
* @@@
|
|
6519
|
+
*
|
|
6520
|
+
* Note: `$` is used to indicate that this function is not a pure function - it access global
|
|
6521
|
+
*
|
|
6522
|
+
* @public exported from `@promptbook/utils`
|
|
6523
|
+
*/
|
|
6524
|
+
function $getGlobalScope() {
|
|
6525
|
+
return Function('return this')();
|
|
6526
|
+
}
|
|
6527
|
+
/***
|
|
6528
|
+
* TODO: !!!!! Make private and promptbook registry from this
|
|
6529
|
+
*/
|
|
6530
|
+
|
|
6500
6531
|
/**
|
|
6501
6532
|
* Register is @@@
|
|
6502
6533
|
*
|
|
@@ -6511,13 +6542,30 @@ var Register = /** @class */ (function () {
|
|
|
6511
6542
|
return this.storage;
|
|
6512
6543
|
};
|
|
6513
6544
|
Register.prototype.register = function (registered) {
|
|
6514
|
-
//
|
|
6515
|
-
|
|
6516
|
-
this.storage.
|
|
6545
|
+
// <- TODO: What to return here
|
|
6546
|
+
var packageName = registered.packageName, className = registered.className;
|
|
6547
|
+
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
6548
|
+
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
6549
|
+
if (existingRegistration) {
|
|
6550
|
+
console.warn("!!!!!! Re-registering ".concat(packageName, ".").concat(className, " again"));
|
|
6551
|
+
this.storage[existingRegistrationIndex] = registered;
|
|
6552
|
+
}
|
|
6553
|
+
else {
|
|
6554
|
+
this.storage.push(registered);
|
|
6555
|
+
}
|
|
6517
6556
|
};
|
|
6518
6557
|
return Register;
|
|
6519
6558
|
}());
|
|
6520
6559
|
|
|
6560
|
+
// TODO: !!!!!! Move this logic to Register and rename to $Register
|
|
6561
|
+
var globalScope = $getGlobalScope();
|
|
6562
|
+
if (globalScope.$llmToolsMetadataRegister === undefined) {
|
|
6563
|
+
globalScope.$llmToolsMetadataRegister = [];
|
|
6564
|
+
}
|
|
6565
|
+
else if (!Array.isArray(globalScope.$llmToolsMetadataRegister)) {
|
|
6566
|
+
throw new UnexpectedError("Expected $llmToolsMetadataRegister to be an array, but got ".concat(typeof globalScope.$llmToolsMetadataRegister));
|
|
6567
|
+
}
|
|
6568
|
+
var _ = globalScope.$llmToolsMetadataRegister;
|
|
6521
6569
|
/**
|
|
6522
6570
|
* @@@
|
|
6523
6571
|
*
|
|
@@ -6525,9 +6573,8 @@ var Register = /** @class */ (function () {
|
|
|
6525
6573
|
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
6526
6574
|
* @public exported from `@promptbook/core`
|
|
6527
6575
|
*/
|
|
6528
|
-
var $llmToolsMetadataRegister = new Register(
|
|
6529
|
-
|
|
6530
|
-
]);
|
|
6576
|
+
var $llmToolsMetadataRegister = new Register(_);
|
|
6577
|
+
$getGlobalScope().$llmToolsMetadataRegister;
|
|
6531
6578
|
|
|
6532
6579
|
/**
|
|
6533
6580
|
* @@@
|
|
@@ -6568,6 +6615,29 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6568
6615
|
enumerable: false,
|
|
6569
6616
|
configurable: true
|
|
6570
6617
|
});
|
|
6618
|
+
/**
|
|
6619
|
+
* Check the configuration of all execution tools
|
|
6620
|
+
*/
|
|
6621
|
+
RemoteLlmExecutionTools.prototype.checkConfiguration = function () {
|
|
6622
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6623
|
+
return __generator(this, function (_a) {
|
|
6624
|
+
return [2 /*return*/];
|
|
6625
|
+
});
|
|
6626
|
+
});
|
|
6627
|
+
};
|
|
6628
|
+
/**
|
|
6629
|
+
* List all available models that can be used
|
|
6630
|
+
*/
|
|
6631
|
+
RemoteLlmExecutionTools.prototype.listModels = function () {
|
|
6632
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6633
|
+
return __generator(this, function (_a) {
|
|
6634
|
+
return [2 /*return*/, (this.options.models ||
|
|
6635
|
+
[
|
|
6636
|
+
/* !!!!!! */
|
|
6637
|
+
])];
|
|
6638
|
+
});
|
|
6639
|
+
});
|
|
6640
|
+
};
|
|
6571
6641
|
/**
|
|
6572
6642
|
* Creates a connection to the remote proxy server.
|
|
6573
6643
|
*/
|
|
@@ -6662,19 +6732,6 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6662
6732
|
});
|
|
6663
6733
|
});
|
|
6664
6734
|
};
|
|
6665
|
-
/**
|
|
6666
|
-
* List all available models that can be used
|
|
6667
|
-
*/
|
|
6668
|
-
RemoteLlmExecutionTools.prototype.listModels = function () {
|
|
6669
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
6670
|
-
return __generator(this, function (_a) {
|
|
6671
|
-
return [2 /*return*/, (this.options.models ||
|
|
6672
|
-
[
|
|
6673
|
-
/* !!! */
|
|
6674
|
-
])];
|
|
6675
|
-
});
|
|
6676
|
-
});
|
|
6677
|
-
};
|
|
6678
6735
|
return RemoteLlmExecutionTools;
|
|
6679
6736
|
}());
|
|
6680
6737
|
/**
|
|
@@ -6871,12 +6928,10 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6871
6928
|
function AnthropicClaudeExecutionTools(options) {
|
|
6872
6929
|
if (options === void 0) { options = { isProxied: false }; }
|
|
6873
6930
|
this.options = options;
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
this.client = new Anthropic(anthropicOptions);
|
|
6879
|
-
// <- TODO: !!!!!! Lazy-load client
|
|
6931
|
+
/**
|
|
6932
|
+
* Anthropic Claude API client.
|
|
6933
|
+
*/
|
|
6934
|
+
this.client = null;
|
|
6880
6935
|
}
|
|
6881
6936
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
6882
6937
|
get: function () {
|
|
@@ -6892,12 +6947,47 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6892
6947
|
enumerable: false,
|
|
6893
6948
|
configurable: true
|
|
6894
6949
|
});
|
|
6950
|
+
AnthropicClaudeExecutionTools.prototype.getClient = function () {
|
|
6951
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6952
|
+
var anthropicOptions;
|
|
6953
|
+
return __generator(this, function (_a) {
|
|
6954
|
+
if (this.client === null) {
|
|
6955
|
+
anthropicOptions = __assign({}, this.options);
|
|
6956
|
+
delete anthropicOptions.isVerbose;
|
|
6957
|
+
delete anthropicOptions.isProxied;
|
|
6958
|
+
this.client = new Anthropic(anthropicOptions);
|
|
6959
|
+
}
|
|
6960
|
+
return [2 /*return*/, this.client];
|
|
6961
|
+
});
|
|
6962
|
+
});
|
|
6963
|
+
};
|
|
6964
|
+
/**
|
|
6965
|
+
* Check the `options` passed to `constructor`
|
|
6966
|
+
*/
|
|
6967
|
+
AnthropicClaudeExecutionTools.prototype.checkConfiguration = function () {
|
|
6968
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6969
|
+
return __generator(this, function (_a) {
|
|
6970
|
+
switch (_a.label) {
|
|
6971
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
6972
|
+
case 1:
|
|
6973
|
+
_a.sent();
|
|
6974
|
+
return [2 /*return*/];
|
|
6975
|
+
}
|
|
6976
|
+
});
|
|
6977
|
+
});
|
|
6978
|
+
};
|
|
6979
|
+
/**
|
|
6980
|
+
* List all available Anthropic Claude models that can be used
|
|
6981
|
+
*/
|
|
6982
|
+
AnthropicClaudeExecutionTools.prototype.listModels = function () {
|
|
6983
|
+
return ANTHROPIC_CLAUDE_MODELS;
|
|
6984
|
+
};
|
|
6895
6985
|
/**
|
|
6896
6986
|
* Calls Anthropic Claude API to use a chat model.
|
|
6897
6987
|
*/
|
|
6898
6988
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6899
6989
|
return __awaiter(this, void 0, void 0, function () {
|
|
6900
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6990
|
+
var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6901
6991
|
return __generator(this, function (_a) {
|
|
6902
6992
|
switch (_a.label) {
|
|
6903
6993
|
case 0:
|
|
@@ -6905,6 +6995,9 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6905
6995
|
console.info('💬 Anthropic Claude callChatModel call');
|
|
6906
6996
|
}
|
|
6907
6997
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6998
|
+
return [4 /*yield*/, this.getClient()];
|
|
6999
|
+
case 1:
|
|
7000
|
+
client = _a.sent();
|
|
6908
7001
|
// TODO: [☂] Use here more modelRequirements
|
|
6909
7002
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
6910
7003
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -6931,8 +7024,8 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6931
7024
|
if (this.options.isVerbose) {
|
|
6932
7025
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
6933
7026
|
}
|
|
6934
|
-
return [4 /*yield*/,
|
|
6935
|
-
case
|
|
7027
|
+
return [4 /*yield*/, client.messages.create(rawRequest)];
|
|
7028
|
+
case 2:
|
|
6936
7029
|
rawResponse = _a.sent();
|
|
6937
7030
|
if (this.options.isVerbose) {
|
|
6938
7031
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7063,13 +7156,6 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
7063
7156
|
AnthropicClaudeExecutionTools.prototype.getDefaultChatModel = function () {
|
|
7064
7157
|
return this.getDefaultModel('claude-3-opus');
|
|
7065
7158
|
};
|
|
7066
|
-
// <- Note: [🤖] getDefaultXxxModel
|
|
7067
|
-
/**
|
|
7068
|
-
* List all available Anthropic Claude models that can be used
|
|
7069
|
-
*/
|
|
7070
|
-
AnthropicClaudeExecutionTools.prototype.listModels = function () {
|
|
7071
|
-
return ANTHROPIC_CLAUDE_MODELS;
|
|
7072
|
-
};
|
|
7073
7159
|
return AnthropicClaudeExecutionTools;
|
|
7074
7160
|
}());
|
|
7075
7161
|
/**
|
|
@@ -7476,10 +7562,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7476
7562
|
*/
|
|
7477
7563
|
function AzureOpenAiExecutionTools(options) {
|
|
7478
7564
|
this.options = options;
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7565
|
+
/**
|
|
7566
|
+
* OpenAI Azure API client.
|
|
7567
|
+
*/
|
|
7568
|
+
this.client = null;
|
|
7483
7569
|
}
|
|
7484
7570
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7485
7571
|
get: function () {
|
|
@@ -7495,28 +7581,74 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7495
7581
|
enumerable: false,
|
|
7496
7582
|
configurable: true
|
|
7497
7583
|
});
|
|
7584
|
+
AzureOpenAiExecutionTools.prototype.getClient = function () {
|
|
7585
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7586
|
+
return __generator(this, function (_a) {
|
|
7587
|
+
if (this.client === null) {
|
|
7588
|
+
this.client = new OpenAIClient("https://".concat(this.options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(this.options.apiKey));
|
|
7589
|
+
}
|
|
7590
|
+
return [2 /*return*/, this.client];
|
|
7591
|
+
});
|
|
7592
|
+
});
|
|
7593
|
+
};
|
|
7594
|
+
/**
|
|
7595
|
+
* Check the `options` passed to `constructor`
|
|
7596
|
+
*/
|
|
7597
|
+
AzureOpenAiExecutionTools.prototype.checkConfiguration = function () {
|
|
7598
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7599
|
+
return __generator(this, function (_a) {
|
|
7600
|
+
switch (_a.label) {
|
|
7601
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
7602
|
+
case 1:
|
|
7603
|
+
_a.sent();
|
|
7604
|
+
return [2 /*return*/];
|
|
7605
|
+
}
|
|
7606
|
+
});
|
|
7607
|
+
});
|
|
7608
|
+
};
|
|
7609
|
+
/**
|
|
7610
|
+
* List all available Azure OpenAI models that can be used
|
|
7611
|
+
*/
|
|
7612
|
+
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
7613
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7614
|
+
return __generator(this, function (_a) {
|
|
7615
|
+
// TODO: !!! Do here some filtering which models are really available as deployment
|
|
7616
|
+
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
7617
|
+
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
7618
|
+
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
7619
|
+
return ({
|
|
7620
|
+
modelTitle: "Azure ".concat(modelTitle),
|
|
7621
|
+
modelName: modelName,
|
|
7622
|
+
modelVariant: modelVariant,
|
|
7623
|
+
});
|
|
7624
|
+
})];
|
|
7625
|
+
});
|
|
7626
|
+
});
|
|
7627
|
+
};
|
|
7498
7628
|
/**
|
|
7499
7629
|
* Calls OpenAI API to use a chat model.
|
|
7500
7630
|
*/
|
|
7501
7631
|
AzureOpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
7502
7632
|
var _a, _b;
|
|
7503
7633
|
return __awaiter(this, void 0, void 0, function () {
|
|
7504
|
-
var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
switch (_d.label) {
|
|
7634
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
|
|
7635
|
+
return __generator(this, function (_c) {
|
|
7636
|
+
switch (_c.label) {
|
|
7508
7637
|
case 0:
|
|
7509
7638
|
if (this.options.isVerbose) {
|
|
7510
7639
|
console.info('💬 OpenAI callChatModel call');
|
|
7511
7640
|
}
|
|
7512
7641
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7642
|
+
return [4 /*yield*/, this.getClient()];
|
|
7643
|
+
case 1:
|
|
7644
|
+
client = _c.sent();
|
|
7513
7645
|
// TODO: [☂] Use here more modelRequirements
|
|
7514
7646
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
7515
7647
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
7516
7648
|
}
|
|
7517
|
-
|
|
7518
|
-
case
|
|
7519
|
-
|
|
7649
|
+
_c.label = 2;
|
|
7650
|
+
case 2:
|
|
7651
|
+
_c.trys.push([2, 4, , 5]);
|
|
7520
7652
|
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7521
7653
|
modelSettings = {
|
|
7522
7654
|
maxTokens: modelRequirements.maxTokens,
|
|
@@ -7546,9 +7678,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7546
7678
|
console.info(colors.bgWhite('messages'), JSON.stringify(messages, null, 4));
|
|
7547
7679
|
}
|
|
7548
7680
|
rawRequest = [modelName, messages, modelSettings];
|
|
7549
|
-
return [4 /*yield*/,
|
|
7550
|
-
case
|
|
7551
|
-
rawResponse =
|
|
7681
|
+
return [4 /*yield*/, client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
|
|
7682
|
+
case 3:
|
|
7683
|
+
rawResponse = _c.sent();
|
|
7552
7684
|
if (this.options.isVerbose) {
|
|
7553
7685
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7554
7686
|
}
|
|
@@ -7583,10 +7715,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7583
7715
|
rawResponse: rawResponse,
|
|
7584
7716
|
// <- [🗯]
|
|
7585
7717
|
}];
|
|
7586
|
-
case
|
|
7587
|
-
error_1 =
|
|
7718
|
+
case 4:
|
|
7719
|
+
error_1 = _c.sent();
|
|
7588
7720
|
throw this.transformAzureError(error_1);
|
|
7589
|
-
case
|
|
7721
|
+
case 5: return [2 /*return*/];
|
|
7590
7722
|
}
|
|
7591
7723
|
});
|
|
7592
7724
|
});
|
|
@@ -7597,22 +7729,24 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7597
7729
|
AzureOpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
7598
7730
|
var _a, _b;
|
|
7599
7731
|
return __awaiter(this, void 0, void 0, function () {
|
|
7600
|
-
var content, parameters, modelRequirements, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
switch (_d.label) {
|
|
7732
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
|
|
7733
|
+
return __generator(this, function (_c) {
|
|
7734
|
+
switch (_c.label) {
|
|
7604
7735
|
case 0:
|
|
7605
7736
|
if (this.options.isVerbose) {
|
|
7606
7737
|
console.info('🖋 OpenAI callCompletionModel call');
|
|
7607
7738
|
}
|
|
7608
7739
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7740
|
+
return [4 /*yield*/, this.getClient()];
|
|
7741
|
+
case 1:
|
|
7742
|
+
client = _c.sent();
|
|
7609
7743
|
// TODO: [☂] Use here more modelRequirements
|
|
7610
7744
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
7611
7745
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
7612
7746
|
}
|
|
7613
|
-
|
|
7614
|
-
case
|
|
7615
|
-
|
|
7747
|
+
_c.label = 2;
|
|
7748
|
+
case 2:
|
|
7749
|
+
_c.trys.push([2, 4, , 5]);
|
|
7616
7750
|
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7617
7751
|
modelSettings = {
|
|
7618
7752
|
maxTokens: modelRequirements.maxTokens || 2000,
|
|
@@ -7634,9 +7768,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7634
7768
|
[rawPromptContent],
|
|
7635
7769
|
modelSettings,
|
|
7636
7770
|
];
|
|
7637
|
-
return [4 /*yield*/,
|
|
7638
|
-
case
|
|
7639
|
-
rawResponse =
|
|
7771
|
+
return [4 /*yield*/, client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
|
|
7772
|
+
case 3:
|
|
7773
|
+
rawResponse = _c.sent();
|
|
7640
7774
|
if (this.options.isVerbose) {
|
|
7641
7775
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7642
7776
|
}
|
|
@@ -7668,10 +7802,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7668
7802
|
rawResponse: rawResponse,
|
|
7669
7803
|
// <- [🗯]
|
|
7670
7804
|
}];
|
|
7671
|
-
case
|
|
7672
|
-
error_2 =
|
|
7805
|
+
case 4:
|
|
7806
|
+
error_2 = _c.sent();
|
|
7673
7807
|
throw this.transformAzureError(error_2);
|
|
7674
|
-
case
|
|
7808
|
+
case 5: return [2 /*return*/];
|
|
7675
7809
|
}
|
|
7676
7810
|
});
|
|
7677
7811
|
});
|
|
@@ -7687,25 +7821,6 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7687
7821
|
var code = azureError.code, message = azureError.message;
|
|
7688
7822
|
return new PipelineExecutionError("".concat(code, ": ").concat(message));
|
|
7689
7823
|
};
|
|
7690
|
-
/**
|
|
7691
|
-
* List all available Azure OpenAI models that can be used
|
|
7692
|
-
*/
|
|
7693
|
-
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
7694
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7695
|
-
return __generator(this, function (_a) {
|
|
7696
|
-
// TODO: !!! Do here some filtering which models are really available as deployment
|
|
7697
|
-
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
7698
|
-
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
7699
|
-
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
7700
|
-
return ({
|
|
7701
|
-
modelTitle: "Azure ".concat(modelTitle),
|
|
7702
|
-
modelName: modelName,
|
|
7703
|
-
modelVariant: modelVariant,
|
|
7704
|
-
});
|
|
7705
|
-
})];
|
|
7706
|
-
});
|
|
7707
|
-
});
|
|
7708
|
-
};
|
|
7709
7824
|
return AzureOpenAiExecutionTools;
|
|
7710
7825
|
}());
|
|
7711
7826
|
/**
|
|
@@ -7767,12 +7882,10 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7767
7882
|
function OpenAiExecutionTools(options) {
|
|
7768
7883
|
if (options === void 0) { options = {}; }
|
|
7769
7884
|
this.options = options;
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
this.client = new OpenAI(__assign({}, openAiOptions));
|
|
7775
|
-
// <- TODO: !!!!!! Lazy-load client
|
|
7885
|
+
/**
|
|
7886
|
+
* OpenAI API client.
|
|
7887
|
+
*/
|
|
7888
|
+
this.client = null;
|
|
7776
7889
|
}
|
|
7777
7890
|
Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
|
|
7778
7891
|
get: function () {
|
|
@@ -7788,12 +7901,54 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7788
7901
|
enumerable: false,
|
|
7789
7902
|
configurable: true
|
|
7790
7903
|
});
|
|
7904
|
+
OpenAiExecutionTools.prototype.getClient = function () {
|
|
7905
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7906
|
+
var openAiOptions;
|
|
7907
|
+
return __generator(this, function (_a) {
|
|
7908
|
+
if (this.client === null) {
|
|
7909
|
+
openAiOptions = __assign({}, this.options);
|
|
7910
|
+
delete openAiOptions.isVerbose;
|
|
7911
|
+
delete openAiOptions.user;
|
|
7912
|
+
this.client = new OpenAI(__assign({}, openAiOptions));
|
|
7913
|
+
}
|
|
7914
|
+
return [2 /*return*/, this.client];
|
|
7915
|
+
});
|
|
7916
|
+
});
|
|
7917
|
+
};
|
|
7918
|
+
/**
|
|
7919
|
+
* Check the `options` passed to `constructor`
|
|
7920
|
+
*/
|
|
7921
|
+
OpenAiExecutionTools.prototype.checkConfiguration = function () {
|
|
7922
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7923
|
+
return __generator(this, function (_a) {
|
|
7924
|
+
switch (_a.label) {
|
|
7925
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
7926
|
+
case 1:
|
|
7927
|
+
_a.sent();
|
|
7928
|
+
return [2 /*return*/];
|
|
7929
|
+
}
|
|
7930
|
+
});
|
|
7931
|
+
});
|
|
7932
|
+
};
|
|
7933
|
+
/**
|
|
7934
|
+
* List all available OpenAI models that can be used
|
|
7935
|
+
*/
|
|
7936
|
+
OpenAiExecutionTools.prototype.listModels = function () {
|
|
7937
|
+
/*
|
|
7938
|
+
Note: Dynamic lising of the models
|
|
7939
|
+
const models = await this.openai.models.list({});
|
|
7940
|
+
|
|
7941
|
+
console.log({ models });
|
|
7942
|
+
console.log(models.data);
|
|
7943
|
+
*/
|
|
7944
|
+
return OPENAI_MODELS;
|
|
7945
|
+
};
|
|
7791
7946
|
/**
|
|
7792
7947
|
* Calls OpenAI API to use a chat model.
|
|
7793
7948
|
*/
|
|
7794
7949
|
OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
7795
7950
|
return __awaiter(this, void 0, void 0, function () {
|
|
7796
|
-
var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7951
|
+
var content, parameters, modelRequirements, expectFormat, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7797
7952
|
return __generator(this, function (_a) {
|
|
7798
7953
|
switch (_a.label) {
|
|
7799
7954
|
case 0:
|
|
@@ -7801,6 +7956,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7801
7956
|
console.info('💬 OpenAI callChatModel call', { prompt: prompt });
|
|
7802
7957
|
}
|
|
7803
7958
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
7959
|
+
return [4 /*yield*/, this.getClient()];
|
|
7960
|
+
case 1:
|
|
7961
|
+
client = _a.sent();
|
|
7804
7962
|
// TODO: [☂] Use here more modelRequirements
|
|
7805
7963
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
7806
7964
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -7837,8 +7995,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7837
7995
|
if (this.options.isVerbose) {
|
|
7838
7996
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7839
7997
|
}
|
|
7840
|
-
return [4 /*yield*/,
|
|
7841
|
-
case
|
|
7998
|
+
return [4 /*yield*/, client.chat.completions.create(rawRequest)];
|
|
7999
|
+
case 2:
|
|
7842
8000
|
rawResponse = _a.sent();
|
|
7843
8001
|
if (this.options.isVerbose) {
|
|
7844
8002
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7879,7 +8037,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7879
8037
|
*/
|
|
7880
8038
|
OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
7881
8039
|
return __awaiter(this, void 0, void 0, function () {
|
|
7882
|
-
var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
8040
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7883
8041
|
return __generator(this, function (_a) {
|
|
7884
8042
|
switch (_a.label) {
|
|
7885
8043
|
case 0:
|
|
@@ -7887,6 +8045,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7887
8045
|
console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
|
|
7888
8046
|
}
|
|
7889
8047
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
8048
|
+
return [4 /*yield*/, this.getClient()];
|
|
8049
|
+
case 1:
|
|
8050
|
+
client = _a.sent();
|
|
7890
8051
|
// TODO: [☂] Use here more modelRequirements
|
|
7891
8052
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
7892
8053
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
@@ -7906,8 +8067,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7906
8067
|
if (this.options.isVerbose) {
|
|
7907
8068
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7908
8069
|
}
|
|
7909
|
-
return [4 /*yield*/,
|
|
7910
|
-
case
|
|
8070
|
+
return [4 /*yield*/, client.completions.create(rawRequest)];
|
|
8071
|
+
case 2:
|
|
7911
8072
|
rawResponse = _a.sent();
|
|
7912
8073
|
if (this.options.isVerbose) {
|
|
7913
8074
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7945,7 +8106,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7945
8106
|
*/
|
|
7946
8107
|
OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
7947
8108
|
return __awaiter(this, void 0, void 0, function () {
|
|
7948
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
8109
|
+
var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7949
8110
|
return __generator(this, function (_a) {
|
|
7950
8111
|
switch (_a.label) {
|
|
7951
8112
|
case 0:
|
|
@@ -7953,6 +8114,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7953
8114
|
console.info('🖋 OpenAI embedding call', { prompt: prompt });
|
|
7954
8115
|
}
|
|
7955
8116
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
8117
|
+
return [4 /*yield*/, this.getClient()];
|
|
8118
|
+
case 1:
|
|
8119
|
+
client = _a.sent();
|
|
7956
8120
|
// TODO: [☂] Use here more modelRequirements
|
|
7957
8121
|
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
7958
8122
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
@@ -7967,8 +8131,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7967
8131
|
if (this.options.isVerbose) {
|
|
7968
8132
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7969
8133
|
}
|
|
7970
|
-
return [4 /*yield*/,
|
|
7971
|
-
case
|
|
8134
|
+
return [4 /*yield*/, client.embeddings.create(rawRequest)];
|
|
8135
|
+
case 2:
|
|
7972
8136
|
rawResponse = _a.sent();
|
|
7973
8137
|
if (this.options.isVerbose) {
|
|
7974
8138
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -8034,20 +8198,6 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
8034
8198
|
OpenAiExecutionTools.prototype.getDefaultEmbeddingModel = function () {
|
|
8035
8199
|
return this.getDefaultModel('text-embedding-3-large');
|
|
8036
8200
|
};
|
|
8037
|
-
// <- Note: [🤖] getDefaultXxxModel
|
|
8038
|
-
/**
|
|
8039
|
-
* List all available OpenAI models that can be used
|
|
8040
|
-
*/
|
|
8041
|
-
OpenAiExecutionTools.prototype.listModels = function () {
|
|
8042
|
-
/*
|
|
8043
|
-
Note: Dynamic lising of the models
|
|
8044
|
-
const models = await this.openai.models.list({});
|
|
8045
|
-
|
|
8046
|
-
console.log({ models });
|
|
8047
|
-
console.log(models.data);
|
|
8048
|
-
*/
|
|
8049
|
-
return OPENAI_MODELS;
|
|
8050
|
-
};
|
|
8051
8201
|
return OpenAiExecutionTools;
|
|
8052
8202
|
}());
|
|
8053
8203
|
/**
|