@promptbook/core 0.66.0-6 → 0.66.0-8
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 +365 -168
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/azure-openai.index.d.ts +4 -0
- package/esm/typings/src/_packages/cli.index.d.ts +4 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- 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/azure-openai/createAzureOpenAiExecutionTools.d.ts +15 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +9 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +11 -0
- 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 +365 -167
- 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-7';
|
|
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-7",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-7",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-7",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-7",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,31 @@ 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("[\uD83D\uDCE6] Registering ".concat(packageName, ".").concat(className, " again"));
|
|
6551
|
+
this.storage.push(registered);
|
|
6552
|
+
}
|
|
6553
|
+
else {
|
|
6554
|
+
console.warn("[\uD83D\uDCE6] Re-registering ".concat(packageName, ".").concat(className, " again"));
|
|
6555
|
+
this.storage[existingRegistrationIndex] = registered;
|
|
6556
|
+
}
|
|
6517
6557
|
};
|
|
6518
6558
|
return Register;
|
|
6519
6559
|
}());
|
|
6520
6560
|
|
|
6561
|
+
// TODO: !!!!!! Move this logic to Register and rename to $Register
|
|
6562
|
+
var globalScope = $getGlobalScope();
|
|
6563
|
+
if (globalScope.$llmToolsMetadataRegister === undefined) {
|
|
6564
|
+
globalScope.$llmToolsMetadataRegister = [];
|
|
6565
|
+
}
|
|
6566
|
+
else if (!Array.isArray(globalScope.$llmToolsMetadataRegister)) {
|
|
6567
|
+
throw new UnexpectedError("Expected $llmToolsMetadataRegister to be an array, but got ".concat(typeof globalScope.$llmToolsMetadataRegister));
|
|
6568
|
+
}
|
|
6569
|
+
var _ = globalScope.$llmToolsMetadataRegister;
|
|
6521
6570
|
/**
|
|
6522
6571
|
* @@@
|
|
6523
6572
|
*
|
|
@@ -6525,9 +6574,8 @@ var Register = /** @class */ (function () {
|
|
|
6525
6574
|
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
6526
6575
|
* @public exported from `@promptbook/core`
|
|
6527
6576
|
*/
|
|
6528
|
-
var $llmToolsMetadataRegister = new Register(
|
|
6529
|
-
|
|
6530
|
-
]);
|
|
6577
|
+
var $llmToolsMetadataRegister = new Register(_);
|
|
6578
|
+
$getGlobalScope().$llmToolsMetadataRegister;
|
|
6531
6579
|
|
|
6532
6580
|
/**
|
|
6533
6581
|
* @@@
|
|
@@ -6568,6 +6616,29 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6568
6616
|
enumerable: false,
|
|
6569
6617
|
configurable: true
|
|
6570
6618
|
});
|
|
6619
|
+
/**
|
|
6620
|
+
* Check the configuration of all execution tools
|
|
6621
|
+
*/
|
|
6622
|
+
RemoteLlmExecutionTools.prototype.checkConfiguration = function () {
|
|
6623
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6624
|
+
return __generator(this, function (_a) {
|
|
6625
|
+
return [2 /*return*/];
|
|
6626
|
+
});
|
|
6627
|
+
});
|
|
6628
|
+
};
|
|
6629
|
+
/**
|
|
6630
|
+
* List all available models that can be used
|
|
6631
|
+
*/
|
|
6632
|
+
RemoteLlmExecutionTools.prototype.listModels = function () {
|
|
6633
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6634
|
+
return __generator(this, function (_a) {
|
|
6635
|
+
return [2 /*return*/, (this.options.models ||
|
|
6636
|
+
[
|
|
6637
|
+
/* !!!!!! */
|
|
6638
|
+
])];
|
|
6639
|
+
});
|
|
6640
|
+
});
|
|
6641
|
+
};
|
|
6571
6642
|
/**
|
|
6572
6643
|
* Creates a connection to the remote proxy server.
|
|
6573
6644
|
*/
|
|
@@ -6662,19 +6733,6 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
6662
6733
|
});
|
|
6663
6734
|
});
|
|
6664
6735
|
};
|
|
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
6736
|
return RemoteLlmExecutionTools;
|
|
6679
6737
|
}());
|
|
6680
6738
|
/**
|
|
@@ -6871,12 +6929,10 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6871
6929
|
function AnthropicClaudeExecutionTools(options) {
|
|
6872
6930
|
if (options === void 0) { options = { isProxied: false }; }
|
|
6873
6931
|
this.options = options;
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
this.client = new Anthropic(anthropicOptions);
|
|
6879
|
-
// <- TODO: !!!!!! Lazy-load client
|
|
6932
|
+
/**
|
|
6933
|
+
* Anthropic Claude API client.
|
|
6934
|
+
*/
|
|
6935
|
+
this.client = null;
|
|
6880
6936
|
}
|
|
6881
6937
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
6882
6938
|
get: function () {
|
|
@@ -6892,12 +6948,47 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6892
6948
|
enumerable: false,
|
|
6893
6949
|
configurable: true
|
|
6894
6950
|
});
|
|
6951
|
+
AnthropicClaudeExecutionTools.prototype.getClient = function () {
|
|
6952
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6953
|
+
var anthropicOptions;
|
|
6954
|
+
return __generator(this, function (_a) {
|
|
6955
|
+
if (this.client === null) {
|
|
6956
|
+
anthropicOptions = __assign({}, this.options);
|
|
6957
|
+
delete anthropicOptions.isVerbose;
|
|
6958
|
+
delete anthropicOptions.isProxied;
|
|
6959
|
+
this.client = new Anthropic(anthropicOptions);
|
|
6960
|
+
}
|
|
6961
|
+
return [2 /*return*/, this.client];
|
|
6962
|
+
});
|
|
6963
|
+
});
|
|
6964
|
+
};
|
|
6965
|
+
/**
|
|
6966
|
+
* Check the `options` passed to `constructor`
|
|
6967
|
+
*/
|
|
6968
|
+
AnthropicClaudeExecutionTools.prototype.checkConfiguration = function () {
|
|
6969
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6970
|
+
return __generator(this, function (_a) {
|
|
6971
|
+
switch (_a.label) {
|
|
6972
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
6973
|
+
case 1:
|
|
6974
|
+
_a.sent();
|
|
6975
|
+
return [2 /*return*/];
|
|
6976
|
+
}
|
|
6977
|
+
});
|
|
6978
|
+
});
|
|
6979
|
+
};
|
|
6980
|
+
/**
|
|
6981
|
+
* List all available Anthropic Claude models that can be used
|
|
6982
|
+
*/
|
|
6983
|
+
AnthropicClaudeExecutionTools.prototype.listModels = function () {
|
|
6984
|
+
return ANTHROPIC_CLAUDE_MODELS;
|
|
6985
|
+
};
|
|
6895
6986
|
/**
|
|
6896
6987
|
* Calls Anthropic Claude API to use a chat model.
|
|
6897
6988
|
*/
|
|
6898
6989
|
AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
|
|
6899
6990
|
return __awaiter(this, void 0, void 0, function () {
|
|
6900
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6991
|
+
var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
|
|
6901
6992
|
return __generator(this, function (_a) {
|
|
6902
6993
|
switch (_a.label) {
|
|
6903
6994
|
case 0:
|
|
@@ -6905,6 +6996,9 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6905
6996
|
console.info('💬 Anthropic Claude callChatModel call');
|
|
6906
6997
|
}
|
|
6907
6998
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
6999
|
+
return [4 /*yield*/, this.getClient()];
|
|
7000
|
+
case 1:
|
|
7001
|
+
client = _a.sent();
|
|
6908
7002
|
// TODO: [☂] Use here more modelRequirements
|
|
6909
7003
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
6910
7004
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -6931,8 +7025,8 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6931
7025
|
if (this.options.isVerbose) {
|
|
6932
7026
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
6933
7027
|
}
|
|
6934
|
-
return [4 /*yield*/,
|
|
6935
|
-
case
|
|
7028
|
+
return [4 /*yield*/, client.messages.create(rawRequest)];
|
|
7029
|
+
case 2:
|
|
6936
7030
|
rawResponse = _a.sent();
|
|
6937
7031
|
if (this.options.isVerbose) {
|
|
6938
7032
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7063,13 +7157,6 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
7063
7157
|
AnthropicClaudeExecutionTools.prototype.getDefaultChatModel = function () {
|
|
7064
7158
|
return this.getDefaultModel('claude-3-opus');
|
|
7065
7159
|
};
|
|
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
7160
|
return AnthropicClaudeExecutionTools;
|
|
7074
7161
|
}());
|
|
7075
7162
|
/**
|
|
@@ -7476,10 +7563,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7476
7563
|
*/
|
|
7477
7564
|
function AzureOpenAiExecutionTools(options) {
|
|
7478
7565
|
this.options = options;
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7566
|
+
/**
|
|
7567
|
+
* OpenAI Azure API client.
|
|
7568
|
+
*/
|
|
7569
|
+
this.client = null;
|
|
7483
7570
|
}
|
|
7484
7571
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7485
7572
|
get: function () {
|
|
@@ -7495,28 +7582,74 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7495
7582
|
enumerable: false,
|
|
7496
7583
|
configurable: true
|
|
7497
7584
|
});
|
|
7585
|
+
AzureOpenAiExecutionTools.prototype.getClient = function () {
|
|
7586
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7587
|
+
return __generator(this, function (_a) {
|
|
7588
|
+
if (this.client === null) {
|
|
7589
|
+
this.client = new OpenAIClient("https://".concat(this.options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(this.options.apiKey));
|
|
7590
|
+
}
|
|
7591
|
+
return [2 /*return*/, this.client];
|
|
7592
|
+
});
|
|
7593
|
+
});
|
|
7594
|
+
};
|
|
7595
|
+
/**
|
|
7596
|
+
* Check the `options` passed to `constructor`
|
|
7597
|
+
*/
|
|
7598
|
+
AzureOpenAiExecutionTools.prototype.checkConfiguration = function () {
|
|
7599
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7600
|
+
return __generator(this, function (_a) {
|
|
7601
|
+
switch (_a.label) {
|
|
7602
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
7603
|
+
case 1:
|
|
7604
|
+
_a.sent();
|
|
7605
|
+
return [2 /*return*/];
|
|
7606
|
+
}
|
|
7607
|
+
});
|
|
7608
|
+
});
|
|
7609
|
+
};
|
|
7610
|
+
/**
|
|
7611
|
+
* List all available Azure OpenAI models that can be used
|
|
7612
|
+
*/
|
|
7613
|
+
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
7614
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7615
|
+
return __generator(this, function (_a) {
|
|
7616
|
+
// TODO: !!! Do here some filtering which models are really available as deployment
|
|
7617
|
+
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
7618
|
+
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
7619
|
+
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
7620
|
+
return ({
|
|
7621
|
+
modelTitle: "Azure ".concat(modelTitle),
|
|
7622
|
+
modelName: modelName,
|
|
7623
|
+
modelVariant: modelVariant,
|
|
7624
|
+
});
|
|
7625
|
+
})];
|
|
7626
|
+
});
|
|
7627
|
+
});
|
|
7628
|
+
};
|
|
7498
7629
|
/**
|
|
7499
7630
|
* Calls OpenAI API to use a chat model.
|
|
7500
7631
|
*/
|
|
7501
7632
|
AzureOpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
7502
7633
|
var _a, _b;
|
|
7503
7634
|
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) {
|
|
7635
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
|
|
7636
|
+
return __generator(this, function (_c) {
|
|
7637
|
+
switch (_c.label) {
|
|
7508
7638
|
case 0:
|
|
7509
7639
|
if (this.options.isVerbose) {
|
|
7510
7640
|
console.info('💬 OpenAI callChatModel call');
|
|
7511
7641
|
}
|
|
7512
7642
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7643
|
+
return [4 /*yield*/, this.getClient()];
|
|
7644
|
+
case 1:
|
|
7645
|
+
client = _c.sent();
|
|
7513
7646
|
// TODO: [☂] Use here more modelRequirements
|
|
7514
7647
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
7515
7648
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
7516
7649
|
}
|
|
7517
|
-
|
|
7518
|
-
case
|
|
7519
|
-
|
|
7650
|
+
_c.label = 2;
|
|
7651
|
+
case 2:
|
|
7652
|
+
_c.trys.push([2, 4, , 5]);
|
|
7520
7653
|
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7521
7654
|
modelSettings = {
|
|
7522
7655
|
maxTokens: modelRequirements.maxTokens,
|
|
@@ -7546,9 +7679,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7546
7679
|
console.info(colors.bgWhite('messages'), JSON.stringify(messages, null, 4));
|
|
7547
7680
|
}
|
|
7548
7681
|
rawRequest = [modelName, messages, modelSettings];
|
|
7549
|
-
return [4 /*yield*/,
|
|
7550
|
-
case
|
|
7551
|
-
rawResponse =
|
|
7682
|
+
return [4 /*yield*/, client.getChatCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
|
|
7683
|
+
case 3:
|
|
7684
|
+
rawResponse = _c.sent();
|
|
7552
7685
|
if (this.options.isVerbose) {
|
|
7553
7686
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7554
7687
|
}
|
|
@@ -7583,10 +7716,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7583
7716
|
rawResponse: rawResponse,
|
|
7584
7717
|
// <- [🗯]
|
|
7585
7718
|
}];
|
|
7586
|
-
case
|
|
7587
|
-
error_1 =
|
|
7719
|
+
case 4:
|
|
7720
|
+
error_1 = _c.sent();
|
|
7588
7721
|
throw this.transformAzureError(error_1);
|
|
7589
|
-
case
|
|
7722
|
+
case 5: return [2 /*return*/];
|
|
7590
7723
|
}
|
|
7591
7724
|
});
|
|
7592
7725
|
});
|
|
@@ -7597,22 +7730,24 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7597
7730
|
AzureOpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
7598
7731
|
var _a, _b;
|
|
7599
7732
|
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) {
|
|
7733
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
|
|
7734
|
+
return __generator(this, function (_c) {
|
|
7735
|
+
switch (_c.label) {
|
|
7604
7736
|
case 0:
|
|
7605
7737
|
if (this.options.isVerbose) {
|
|
7606
7738
|
console.info('🖋 OpenAI callCompletionModel call');
|
|
7607
7739
|
}
|
|
7608
7740
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7741
|
+
return [4 /*yield*/, this.getClient()];
|
|
7742
|
+
case 1:
|
|
7743
|
+
client = _c.sent();
|
|
7609
7744
|
// TODO: [☂] Use here more modelRequirements
|
|
7610
7745
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
7611
7746
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
7612
7747
|
}
|
|
7613
|
-
|
|
7614
|
-
case
|
|
7615
|
-
|
|
7748
|
+
_c.label = 2;
|
|
7749
|
+
case 2:
|
|
7750
|
+
_c.trys.push([2, 4, , 5]);
|
|
7616
7751
|
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7617
7752
|
modelSettings = {
|
|
7618
7753
|
maxTokens: modelRequirements.maxTokens || 2000,
|
|
@@ -7634,9 +7769,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7634
7769
|
[rawPromptContent],
|
|
7635
7770
|
modelSettings,
|
|
7636
7771
|
];
|
|
7637
|
-
return [4 /*yield*/,
|
|
7638
|
-
case
|
|
7639
|
-
rawResponse =
|
|
7772
|
+
return [4 /*yield*/, client.getCompletions.apply(client, __spreadArray([], __read(rawRequest), false))];
|
|
7773
|
+
case 3:
|
|
7774
|
+
rawResponse = _c.sent();
|
|
7640
7775
|
if (this.options.isVerbose) {
|
|
7641
7776
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7642
7777
|
}
|
|
@@ -7668,10 +7803,10 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7668
7803
|
rawResponse: rawResponse,
|
|
7669
7804
|
// <- [🗯]
|
|
7670
7805
|
}];
|
|
7671
|
-
case
|
|
7672
|
-
error_2 =
|
|
7806
|
+
case 4:
|
|
7807
|
+
error_2 = _c.sent();
|
|
7673
7808
|
throw this.transformAzureError(error_2);
|
|
7674
|
-
case
|
|
7809
|
+
case 5: return [2 /*return*/];
|
|
7675
7810
|
}
|
|
7676
7811
|
});
|
|
7677
7812
|
});
|
|
@@ -7687,25 +7822,6 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
|
7687
7822
|
var code = azureError.code, message = azureError.message;
|
|
7688
7823
|
return new PipelineExecutionError("".concat(code, ": ").concat(message));
|
|
7689
7824
|
};
|
|
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
7825
|
return AzureOpenAiExecutionTools;
|
|
7710
7826
|
}());
|
|
7711
7827
|
/**
|
|
@@ -7767,12 +7883,10 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7767
7883
|
function OpenAiExecutionTools(options) {
|
|
7768
7884
|
if (options === void 0) { options = {}; }
|
|
7769
7885
|
this.options = options;
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
this.client = new OpenAI(__assign({}, openAiOptions));
|
|
7775
|
-
// <- TODO: !!!!!! Lazy-load client
|
|
7886
|
+
/**
|
|
7887
|
+
* OpenAI API client.
|
|
7888
|
+
*/
|
|
7889
|
+
this.client = null;
|
|
7776
7890
|
}
|
|
7777
7891
|
Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
|
|
7778
7892
|
get: function () {
|
|
@@ -7788,12 +7902,54 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7788
7902
|
enumerable: false,
|
|
7789
7903
|
configurable: true
|
|
7790
7904
|
});
|
|
7905
|
+
OpenAiExecutionTools.prototype.getClient = function () {
|
|
7906
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7907
|
+
var openAiOptions;
|
|
7908
|
+
return __generator(this, function (_a) {
|
|
7909
|
+
if (this.client === null) {
|
|
7910
|
+
openAiOptions = __assign({}, this.options);
|
|
7911
|
+
delete openAiOptions.isVerbose;
|
|
7912
|
+
delete openAiOptions.user;
|
|
7913
|
+
this.client = new OpenAI(__assign({}, openAiOptions));
|
|
7914
|
+
}
|
|
7915
|
+
return [2 /*return*/, this.client];
|
|
7916
|
+
});
|
|
7917
|
+
});
|
|
7918
|
+
};
|
|
7919
|
+
/**
|
|
7920
|
+
* Check the `options` passed to `constructor`
|
|
7921
|
+
*/
|
|
7922
|
+
OpenAiExecutionTools.prototype.checkConfiguration = function () {
|
|
7923
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7924
|
+
return __generator(this, function (_a) {
|
|
7925
|
+
switch (_a.label) {
|
|
7926
|
+
case 0: return [4 /*yield*/, this.getClient()];
|
|
7927
|
+
case 1:
|
|
7928
|
+
_a.sent();
|
|
7929
|
+
return [2 /*return*/];
|
|
7930
|
+
}
|
|
7931
|
+
});
|
|
7932
|
+
});
|
|
7933
|
+
};
|
|
7934
|
+
/**
|
|
7935
|
+
* List all available OpenAI models that can be used
|
|
7936
|
+
*/
|
|
7937
|
+
OpenAiExecutionTools.prototype.listModels = function () {
|
|
7938
|
+
/*
|
|
7939
|
+
Note: Dynamic lising of the models
|
|
7940
|
+
const models = await this.openai.models.list({});
|
|
7941
|
+
|
|
7942
|
+
console.log({ models });
|
|
7943
|
+
console.log(models.data);
|
|
7944
|
+
*/
|
|
7945
|
+
return OPENAI_MODELS;
|
|
7946
|
+
};
|
|
7791
7947
|
/**
|
|
7792
7948
|
* Calls OpenAI API to use a chat model.
|
|
7793
7949
|
*/
|
|
7794
7950
|
OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
7795
7951
|
return __awaiter(this, void 0, void 0, function () {
|
|
7796
|
-
var content, parameters, modelRequirements, expectFormat, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7952
|
+
var content, parameters, modelRequirements, expectFormat, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7797
7953
|
return __generator(this, function (_a) {
|
|
7798
7954
|
switch (_a.label) {
|
|
7799
7955
|
case 0:
|
|
@@ -7801,6 +7957,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7801
7957
|
console.info('💬 OpenAI callChatModel call', { prompt: prompt });
|
|
7802
7958
|
}
|
|
7803
7959
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, expectFormat = prompt.expectFormat;
|
|
7960
|
+
return [4 /*yield*/, this.getClient()];
|
|
7961
|
+
case 1:
|
|
7962
|
+
client = _a.sent();
|
|
7804
7963
|
// TODO: [☂] Use here more modelRequirements
|
|
7805
7964
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
7806
7965
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -7837,8 +7996,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7837
7996
|
if (this.options.isVerbose) {
|
|
7838
7997
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7839
7998
|
}
|
|
7840
|
-
return [4 /*yield*/,
|
|
7841
|
-
case
|
|
7999
|
+
return [4 /*yield*/, client.chat.completions.create(rawRequest)];
|
|
8000
|
+
case 2:
|
|
7842
8001
|
rawResponse = _a.sent();
|
|
7843
8002
|
if (this.options.isVerbose) {
|
|
7844
8003
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7879,7 +8038,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7879
8038
|
*/
|
|
7880
8039
|
OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
7881
8040
|
return __awaiter(this, void 0, void 0, function () {
|
|
7882
|
-
var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
8041
|
+
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7883
8042
|
return __generator(this, function (_a) {
|
|
7884
8043
|
switch (_a.label) {
|
|
7885
8044
|
case 0:
|
|
@@ -7887,6 +8046,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7887
8046
|
console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
|
|
7888
8047
|
}
|
|
7889
8048
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
8049
|
+
return [4 /*yield*/, this.getClient()];
|
|
8050
|
+
case 1:
|
|
8051
|
+
client = _a.sent();
|
|
7890
8052
|
// TODO: [☂] Use here more modelRequirements
|
|
7891
8053
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
7892
8054
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
@@ -7906,8 +8068,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7906
8068
|
if (this.options.isVerbose) {
|
|
7907
8069
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7908
8070
|
}
|
|
7909
|
-
return [4 /*yield*/,
|
|
7910
|
-
case
|
|
8071
|
+
return [4 /*yield*/, client.completions.create(rawRequest)];
|
|
8072
|
+
case 2:
|
|
7911
8073
|
rawResponse = _a.sent();
|
|
7912
8074
|
if (this.options.isVerbose) {
|
|
7913
8075
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -7945,7 +8107,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7945
8107
|
*/
|
|
7946
8108
|
OpenAiExecutionTools.prototype.callEmbeddingModel = function (prompt) {
|
|
7947
8109
|
return __awaiter(this, void 0, void 0, function () {
|
|
7948
|
-
var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
8110
|
+
var content, parameters, modelRequirements, client, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
7949
8111
|
return __generator(this, function (_a) {
|
|
7950
8112
|
switch (_a.label) {
|
|
7951
8113
|
case 0:
|
|
@@ -7953,6 +8115,9 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7953
8115
|
console.info('🖋 OpenAI embedding call', { prompt: prompt });
|
|
7954
8116
|
}
|
|
7955
8117
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
8118
|
+
return [4 /*yield*/, this.getClient()];
|
|
8119
|
+
case 1:
|
|
8120
|
+
client = _a.sent();
|
|
7956
8121
|
// TODO: [☂] Use here more modelRequirements
|
|
7957
8122
|
if (modelRequirements.modelVariant !== 'EMBEDDING') {
|
|
7958
8123
|
throw new PipelineExecutionError('Use embed only for EMBEDDING variant');
|
|
@@ -7967,8 +8132,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7967
8132
|
if (this.options.isVerbose) {
|
|
7968
8133
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
7969
8134
|
}
|
|
7970
|
-
return [4 /*yield*/,
|
|
7971
|
-
case
|
|
8135
|
+
return [4 /*yield*/, client.embeddings.create(rawRequest)];
|
|
8136
|
+
case 2:
|
|
7972
8137
|
rawResponse = _a.sent();
|
|
7973
8138
|
if (this.options.isVerbose) {
|
|
7974
8139
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
@@ -8034,20 +8199,6 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
8034
8199
|
OpenAiExecutionTools.prototype.getDefaultEmbeddingModel = function () {
|
|
8035
8200
|
return this.getDefaultModel('text-embedding-3-large');
|
|
8036
8201
|
};
|
|
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
8202
|
return OpenAiExecutionTools;
|
|
8052
8203
|
}());
|
|
8053
8204
|
/**
|
|
@@ -8395,6 +8546,52 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
8395
8546
|
},
|
|
8396
8547
|
});
|
|
8397
8548
|
|
|
8549
|
+
/**
|
|
8550
|
+
* @@@ registration1 of default configuration for Azure Open AI
|
|
8551
|
+
*
|
|
8552
|
+
* Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
|
|
8553
|
+
*
|
|
8554
|
+
* @public exported from `@promptbook/core`
|
|
8555
|
+
* @public exported from `@promptbook/cli`
|
|
8556
|
+
*/
|
|
8557
|
+
var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
8558
|
+
title: 'Azure Open AI',
|
|
8559
|
+
packageName: '@promptbook/azure-openai',
|
|
8560
|
+
className: 'AzureOpenAiExecutionTools',
|
|
8561
|
+
getBoilerplateConfiguration: function () {
|
|
8562
|
+
return {
|
|
8563
|
+
title: 'Azure Open AI (boilerplate)',
|
|
8564
|
+
packageName: '@promptbook/azure-openai',
|
|
8565
|
+
className: 'AzureOpenAiExecutionTools',
|
|
8566
|
+
options: {
|
|
8567
|
+
apiKey: 'sk-',
|
|
8568
|
+
},
|
|
8569
|
+
};
|
|
8570
|
+
},
|
|
8571
|
+
createConfigurationFromEnv: function (env) {
|
|
8572
|
+
if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' &&
|
|
8573
|
+
typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' &&
|
|
8574
|
+
typeof env.AZUREOPENAI_API_KEY === 'string') {
|
|
8575
|
+
return {
|
|
8576
|
+
title: 'Azure Open AI (from env)',
|
|
8577
|
+
packageName: '@promptbook/azure-openai',
|
|
8578
|
+
className: 'AzureOpenAiExecutionTools',
|
|
8579
|
+
options: {
|
|
8580
|
+
resourceName: env.AZUREOPENAI_RESOURCE_NAME,
|
|
8581
|
+
deploymentName: env.AZUREOPENAI_DEPLOYMENT_NAME,
|
|
8582
|
+
apiKey: env.AZUREOPENAI_API_KEY,
|
|
8583
|
+
},
|
|
8584
|
+
};
|
|
8585
|
+
}
|
|
8586
|
+
else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
|
|
8587
|
+
typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
|
|
8588
|
+
typeof env.AZUREOPENAI_API_KEY === 'string') {
|
|
8589
|
+
throw new Error(spaceTrim("\n You must provide all of the following environment variables:\n \n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ") \n ")));
|
|
8590
|
+
}
|
|
8591
|
+
return null;
|
|
8592
|
+
},
|
|
8593
|
+
});
|
|
8594
|
+
|
|
8398
8595
|
/**
|
|
8399
8596
|
* @@@ registration1 of default configuration for Open AI
|
|
8400
8597
|
*
|
|
@@ -8404,9 +8601,9 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
|
8404
8601
|
* @public exported from `@promptbook/cli`
|
|
8405
8602
|
*/
|
|
8406
8603
|
var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
|
|
8407
|
-
title: '
|
|
8408
|
-
packageName: '@promptbook/
|
|
8409
|
-
className: '
|
|
8604
|
+
title: 'Open AI',
|
|
8605
|
+
packageName: '@promptbook/openai',
|
|
8606
|
+
className: 'OpenAiExecutionTools',
|
|
8410
8607
|
getBoilerplateConfiguration: function () {
|
|
8411
8608
|
return {
|
|
8412
8609
|
title: 'Open AI (boilerplate)',
|
|
@@ -8782,5 +8979,5 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
8782
8979
|
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
8783
8980
|
*/
|
|
8784
8981
|
|
|
8785
|
-
export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PrefixStorage, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, UnexpectedError, VersionMismatchError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _OpenAiMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
8982
|
+
export { $llmToolsMetadataRegister, $llmToolsRegister, BlockTypes, CLAIM, CallbackInterfaceTools, CollectionError, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, EXECUTIONS_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, LimitReachedError, MAX_EXECUTION_ATTEMPTS, MAX_FILENAME_LENGTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, MAX_PARALLEL_COUNT, MODEL_VARIANTS, MemoryStorage, NotFoundError, NotYetImplementedError, PIPELINE_COLLECTION_BASE_FILENAME, PROMPTBOOK_VERSION, ParsingError, PipelineExecutionError, PipelineLogicError, PrefixStorage, RESERVED_PARAMETER_NAMES, ReferenceError$1 as ReferenceError, UnexpectedError, VersionMismatchError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _OpenAiMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, isPassingExpectations, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgeFromMarkdown, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
|
|
8786
8983
|
//# sourceMappingURL=index.es.js.map
|