@promptbook/openai 0.95.0 → 0.98.0-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/README.md +63 -2
  2. package/esm/index.es.js +602 -4
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/openai.index.d.ts +10 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +12 -2
  9. package/esm/typings/src/_packages/wizard.index.d.ts +4 -0
  10. package/esm/typings/src/config.d.ts +1 -1
  11. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +8 -0
  12. package/esm/typings/src/execution/utils/validatePromptResult.d.ts +53 -0
  13. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
  14. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  15. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +2 -2
  16. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +4 -4
  17. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionToolsOptions.d.ts +52 -0
  18. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +3 -5
  19. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +74 -0
  20. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +11 -0
  21. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +14 -0
  22. package/esm/typings/src/version.d.ts +1 -1
  23. package/package.json +3 -2
  24. package/umd/index.umd.js +606 -7
  25. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI));
5
- })(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai'), require('socket.io-client')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai', 'socket.io-client'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI, global.socket_ioClient));
5
+ })(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI, socket_ioClient) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.95.0';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.98.0-10';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -283,6 +283,19 @@
283
283
  * @public exported from `@promptbook/utils`
284
284
  */
285
285
  const SMALL_NUMBER = 0.001;
286
+ /**
287
+ * Timeout for the connections in milliseconds
288
+ *
289
+ * @private within the repository - too low-level in comparison with other `MAX_...`
290
+ */
291
+ const CONNECTION_TIMEOUT_MS = 7 * 1000;
292
+ // <- TODO: [⏳] Standardize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
293
+ /**
294
+ * How many times to retry the connections
295
+ *
296
+ * @private within the repository - too low-level in comparison with other `MAX_...`
297
+ */
298
+ const CONNECTION_RETRIES_LIMIT = 5;
286
299
  // <- TODO: [🧜‍♂️]
287
300
  /**
288
301
  * Default settings for parsing and generating CSV files in Promptbook.
@@ -1787,7 +1800,7 @@
1787
1800
  */
1788
1801
 
1789
1802
  /**
1790
- * Execution Tools for calling OpenAI API or other OpeenAI compatible provider
1803
+ * Execution Tools for calling OpenAI API or other OpenAI compatible provider
1791
1804
  *
1792
1805
  * @public exported from `@promptbook/openai`
1793
1806
  */
@@ -2155,7 +2168,7 @@
2155
2168
  * Default model for chat variant.
2156
2169
  */
2157
2170
  getDefaultChatModel() {
2158
- return this.getDefaultModel('gpt-4o');
2171
+ return this.getDefaultModel('gpt-4-turbo');
2159
2172
  }
2160
2173
  /**
2161
2174
  * Default model for completion variant.
@@ -2185,6 +2198,9 @@
2185
2198
  * @param options which are relevant are directly passed to the OpenAI client
2186
2199
  */
2187
2200
  constructor(options) {
2201
+ if (options.isProxied) {
2202
+ throw new NotYetImplementedError(`Proxy mode is not yet implemented for OpenAI assistants`);
2203
+ }
2188
2204
  super(options);
2189
2205
  this.assistantId = options.assistantId;
2190
2206
  // TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
@@ -2358,6 +2374,569 @@
2358
2374
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
2359
2375
  */
2360
2376
 
2377
+ /**
2378
+ * This error indicates problems parsing the format value
2379
+ *
2380
+ * For example, when the format value is not a valid JSON or CSV
2381
+ * This is not thrown directly but in extended classes
2382
+ *
2383
+ * @public exported from `@promptbook/core`
2384
+ */
2385
+ class AbstractFormatError extends Error {
2386
+ // Note: To allow instanceof do not put here error `name`
2387
+ // public readonly name = 'AbstractFormatError';
2388
+ constructor(message) {
2389
+ super(message);
2390
+ Object.setPrototypeOf(this, AbstractFormatError.prototype);
2391
+ }
2392
+ }
2393
+
2394
+ /**
2395
+ * This error indicates problem with parsing of CSV
2396
+ *
2397
+ * @public exported from `@promptbook/core`
2398
+ */
2399
+ class CsvFormatError extends AbstractFormatError {
2400
+ constructor(message) {
2401
+ super(message);
2402
+ this.name = 'CsvFormatError';
2403
+ Object.setPrototypeOf(this, CsvFormatError.prototype);
2404
+ }
2405
+ }
2406
+
2407
+ /**
2408
+ * AuthenticationError is thrown from login function which is dependency of remote server
2409
+ *
2410
+ * @public exported from `@promptbook/core`
2411
+ */
2412
+ class AuthenticationError extends Error {
2413
+ constructor(message) {
2414
+ super(message);
2415
+ this.name = 'AuthenticationError';
2416
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2417
+ }
2418
+ }
2419
+
2420
+ /**
2421
+ * This error indicates that the pipeline collection cannot be properly loaded
2422
+ *
2423
+ * @public exported from `@promptbook/core`
2424
+ */
2425
+ class CollectionError extends Error {
2426
+ constructor(message) {
2427
+ super(message);
2428
+ this.name = 'CollectionError';
2429
+ Object.setPrototypeOf(this, CollectionError.prototype);
2430
+ }
2431
+ }
2432
+
2433
+ /**
2434
+ * This error type indicates that you try to use a feature that is not available in the current environment
2435
+ *
2436
+ * @public exported from `@promptbook/core`
2437
+ */
2438
+ class EnvironmentMismatchError extends Error {
2439
+ constructor(message) {
2440
+ super(message);
2441
+ this.name = 'EnvironmentMismatchError';
2442
+ Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
2443
+ }
2444
+ }
2445
+
2446
+ /**
2447
+ * This error occurs when some expectation is not met in the execution of the pipeline
2448
+ *
2449
+ * @public exported from `@promptbook/core`
2450
+ * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
2451
+ * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
2452
+ * Note: This is a kindof subtype of PipelineExecutionError
2453
+ */
2454
+ class ExpectError extends Error {
2455
+ constructor(message) {
2456
+ super(message);
2457
+ this.name = 'ExpectError';
2458
+ Object.setPrototypeOf(this, ExpectError.prototype);
2459
+ }
2460
+ }
2461
+
2462
+ /**
2463
+ * This error indicates that the promptbook can not retrieve knowledge from external sources
2464
+ *
2465
+ * @public exported from `@promptbook/core`
2466
+ */
2467
+ class KnowledgeScrapeError extends Error {
2468
+ constructor(message) {
2469
+ super(message);
2470
+ this.name = 'KnowledgeScrapeError';
2471
+ Object.setPrototypeOf(this, KnowledgeScrapeError.prototype);
2472
+ }
2473
+ }
2474
+
2475
+ /**
2476
+ * This error type indicates that some tools are missing for pipeline execution or preparation
2477
+ *
2478
+ * @public exported from `@promptbook/core`
2479
+ */
2480
+ class MissingToolsError extends Error {
2481
+ constructor(message) {
2482
+ super(spaceTrim.spaceTrim((block) => `
2483
+ ${block(message)}
2484
+
2485
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
2486
+
2487
+ `));
2488
+ this.name = 'MissingToolsError';
2489
+ Object.setPrototypeOf(this, MissingToolsError.prototype);
2490
+ }
2491
+ }
2492
+
2493
+ /**
2494
+ * This error indicates that promptbook not found in the collection
2495
+ *
2496
+ * @public exported from `@promptbook/core`
2497
+ */
2498
+ class NotFoundError extends Error {
2499
+ constructor(message) {
2500
+ super(message);
2501
+ this.name = 'NotFoundError';
2502
+ Object.setPrototypeOf(this, NotFoundError.prototype);
2503
+ }
2504
+ }
2505
+
2506
+ /**
2507
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
2508
+ *
2509
+ * @public exported from `@promptbook/core`
2510
+ */
2511
+ class ParseError extends Error {
2512
+ constructor(message) {
2513
+ super(message);
2514
+ this.name = 'ParseError';
2515
+ Object.setPrototypeOf(this, ParseError.prototype);
2516
+ }
2517
+ }
2518
+ /**
2519
+ * TODO: Maybe split `ParseError` and `ApplyError`
2520
+ */
2521
+
2522
+ /**
2523
+ * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
2524
+ *
2525
+ * @public exported from `@promptbook/core`
2526
+ */
2527
+ class PipelineLogicError extends Error {
2528
+ constructor(message) {
2529
+ super(message);
2530
+ this.name = 'PipelineLogicError';
2531
+ Object.setPrototypeOf(this, PipelineLogicError.prototype);
2532
+ }
2533
+ }
2534
+
2535
+ /**
2536
+ * This error indicates errors in referencing promptbooks between each other
2537
+ *
2538
+ * @public exported from `@promptbook/core`
2539
+ */
2540
+ class PipelineUrlError extends Error {
2541
+ constructor(message) {
2542
+ super(message);
2543
+ this.name = 'PipelineUrlError';
2544
+ Object.setPrototypeOf(this, PipelineUrlError.prototype);
2545
+ }
2546
+ }
2547
+
2548
+ /**
2549
+ * Error thrown when a fetch request fails
2550
+ *
2551
+ * @public exported from `@promptbook/core`
2552
+ */
2553
+ class PromptbookFetchError extends Error {
2554
+ constructor(message) {
2555
+ super(message);
2556
+ this.name = 'PromptbookFetchError';
2557
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2558
+ }
2559
+ }
2560
+
2561
+ /**
2562
+ * Index of all custom errors
2563
+ *
2564
+ * @public exported from `@promptbook/core`
2565
+ */
2566
+ const PROMPTBOOK_ERRORS = {
2567
+ AbstractFormatError,
2568
+ CsvFormatError,
2569
+ CollectionError,
2570
+ EnvironmentMismatchError,
2571
+ ExpectError,
2572
+ KnowledgeScrapeError,
2573
+ LimitReachedError,
2574
+ MissingToolsError,
2575
+ NotFoundError,
2576
+ NotYetImplementedError,
2577
+ ParseError,
2578
+ PipelineExecutionError,
2579
+ PipelineLogicError,
2580
+ PipelineUrlError,
2581
+ AuthenticationError,
2582
+ PromptbookFetchError,
2583
+ UnexpectedError,
2584
+ WrappedError,
2585
+ // TODO: [🪑]> VersionMismatchError,
2586
+ };
2587
+ /**
2588
+ * Index of all javascript errors
2589
+ *
2590
+ * @private for internal usage
2591
+ */
2592
+ const COMMON_JAVASCRIPT_ERRORS = {
2593
+ Error,
2594
+ EvalError,
2595
+ RangeError,
2596
+ ReferenceError,
2597
+ SyntaxError,
2598
+ TypeError,
2599
+ URIError,
2600
+ AggregateError,
2601
+ /*
2602
+ Note: Not widely supported
2603
+ > InternalError,
2604
+ > ModuleError,
2605
+ > HeapError,
2606
+ > WebAssemblyCompileError,
2607
+ > WebAssemblyRuntimeError,
2608
+ */
2609
+ };
2610
+ /**
2611
+ * Index of all errors
2612
+ *
2613
+ * @private for internal usage
2614
+ */
2615
+ const ALL_ERRORS = {
2616
+ ...PROMPTBOOK_ERRORS,
2617
+ ...COMMON_JAVASCRIPT_ERRORS,
2618
+ };
2619
+ /**
2620
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2621
+ */
2622
+
2623
+ /**
2624
+ * Deserializes the error object
2625
+ *
2626
+ * @public exported from `@promptbook/utils`
2627
+ */
2628
+ function deserializeError(error) {
2629
+ const { name, stack, id } = error; // Added id
2630
+ let { message } = error;
2631
+ let ErrorClass = ALL_ERRORS[error.name];
2632
+ if (ErrorClass === undefined) {
2633
+ ErrorClass = Error;
2634
+ message = `${name}: ${message}`;
2635
+ }
2636
+ if (stack !== undefined && stack !== '') {
2637
+ message = spaceTrim__default["default"]((block) => `
2638
+ ${block(message)}
2639
+
2640
+ Original stack trace:
2641
+ ${block(stack || '')}
2642
+ `);
2643
+ }
2644
+ const deserializedError = new ErrorClass(message);
2645
+ deserializedError.id = id; // Assign id to the error object
2646
+ return deserializedError;
2647
+ }
2648
+
2649
+ /**
2650
+ * Tests if given string is valid URL.
2651
+ *
2652
+ * Note: Dataurl are considered perfectly valid.
2653
+ * Note: There are two similar functions:
2654
+ * - `isValidUrl` which tests any URL
2655
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
2656
+ *
2657
+ * @public exported from `@promptbook/utils`
2658
+ */
2659
+ function isValidUrl(url) {
2660
+ if (typeof url !== 'string') {
2661
+ return false;
2662
+ }
2663
+ try {
2664
+ if (url.startsWith('blob:')) {
2665
+ url = url.replace(/^blob:/, '');
2666
+ }
2667
+ const urlObject = new URL(url /* because fail is handled */);
2668
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
2669
+ return false;
2670
+ }
2671
+ return true;
2672
+ }
2673
+ catch (error) {
2674
+ return false;
2675
+ }
2676
+ }
2677
+
2678
+ /**
2679
+ * Creates a connection to the remote proxy server.
2680
+ *
2681
+ * Note: This function creates a connection to the remote server and returns a socket but responsibility of closing the connection is on the caller
2682
+ *
2683
+ * @private internal utility function
2684
+ */
2685
+ async function createRemoteClient(options) {
2686
+ const { remoteServerUrl } = options;
2687
+ if (!isValidUrl(remoteServerUrl)) {
2688
+ throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
2689
+ }
2690
+ const remoteServerUrlParsed = new URL(remoteServerUrl);
2691
+ if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
2692
+ remoteServerUrlParsed.pathname = '/';
2693
+ throw new Error(spaceTrim__default["default"]((block) => `
2694
+ Remote server requires root url \`/\`
2695
+
2696
+ You have provided \`remoteServerUrl\`:
2697
+ ${block(remoteServerUrl)}
2698
+
2699
+ But something like this is expected:
2700
+ ${block(remoteServerUrlParsed.href)}
2701
+
2702
+ Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
2703
+
2704
+ `));
2705
+ }
2706
+ return new Promise((resolve, reject) => {
2707
+ const socket = socket_ioClient.io(remoteServerUrl, {
2708
+ retries: CONNECTION_RETRIES_LIMIT,
2709
+ timeout: CONNECTION_TIMEOUT_MS,
2710
+ path: '/socket.io',
2711
+ transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
2712
+ });
2713
+ // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
2714
+ socket.on('connect', () => {
2715
+ resolve(socket);
2716
+ });
2717
+ // TODO: [💩] Better timeout handling
2718
+ setTimeout(() => {
2719
+ reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
2720
+ }, CONNECTION_TIMEOUT_MS);
2721
+ });
2722
+ }
2723
+
2724
+ /**
2725
+ * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
2726
+ *
2727
+ * You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
2728
+ * This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
2729
+ *
2730
+ * @see https://github.com/webgptorg/promptbook#remote-server
2731
+ * @public exported from `@promptbook/remote-client`
2732
+ */
2733
+ class RemoteLlmExecutionTools {
2734
+ /* <- TODO: [🍚] `, Destroyable` */
2735
+ constructor(options) {
2736
+ this.options = options;
2737
+ }
2738
+ get title() {
2739
+ // TODO: [🧠] Maybe fetch title+description from the remote server (as well as if model methods are defined)
2740
+ return 'Promptbook remote server';
2741
+ }
2742
+ get description() {
2743
+ return `Models from Promptbook remote server ${this.options.remoteServerUrl}`;
2744
+ }
2745
+ /**
2746
+ * Check the configuration of all execution tools
2747
+ */
2748
+ async checkConfiguration() {
2749
+ const socket = await createRemoteClient(this.options);
2750
+ socket.disconnect();
2751
+ // TODO: [main] !!3 Check version of the remote server and compatibility
2752
+ // TODO: [🎍] Send checkConfiguration
2753
+ }
2754
+ /**
2755
+ * List all available models that can be used
2756
+ */
2757
+ async listModels() {
2758
+ // TODO: [👒] Listing models (and checking configuration) probably should go through REST API not Socket.io
2759
+ const socket = await createRemoteClient(this.options);
2760
+ socket.emit('listModels-request', {
2761
+ identification: this.options.identification,
2762
+ } /* <- Note: [🤛] */);
2763
+ const promptResult = await new Promise((resolve, reject) => {
2764
+ socket.on('listModels-response', (response) => {
2765
+ resolve(response.models);
2766
+ socket.disconnect();
2767
+ });
2768
+ socket.on('error', (error) => {
2769
+ reject(deserializeError(error));
2770
+ socket.disconnect();
2771
+ });
2772
+ });
2773
+ socket.disconnect();
2774
+ return promptResult;
2775
+ }
2776
+ /**
2777
+ * Calls remote proxy server to use a chat model
2778
+ */
2779
+ callChatModel(prompt) {
2780
+ if (this.options.isVerbose) {
2781
+ console.info(`🖋 Remote callChatModel call`);
2782
+ }
2783
+ return /* not await */ this.callCommonModel(prompt);
2784
+ }
2785
+ /**
2786
+ * Calls remote proxy server to use a completion model
2787
+ */
2788
+ callCompletionModel(prompt) {
2789
+ if (this.options.isVerbose) {
2790
+ console.info(`💬 Remote callCompletionModel call`);
2791
+ }
2792
+ return /* not await */ this.callCommonModel(prompt);
2793
+ }
2794
+ /**
2795
+ * Calls remote proxy server to use a embedding model
2796
+ */
2797
+ callEmbeddingModel(prompt) {
2798
+ if (this.options.isVerbose) {
2799
+ console.info(`💬 Remote callEmbeddingModel call`);
2800
+ }
2801
+ return /* not await */ this.callCommonModel(prompt);
2802
+ }
2803
+ // <- Note: [🤖] callXxxModel
2804
+ /**
2805
+ * Calls remote proxy server to use both completion or chat model
2806
+ */
2807
+ async callCommonModel(prompt) {
2808
+ const socket = await createRemoteClient(this.options);
2809
+ socket.emit('prompt-request', {
2810
+ identification: this.options.identification,
2811
+ prompt,
2812
+ } /* <- Note: [🤛] */);
2813
+ const promptResult = await new Promise((resolve, reject) => {
2814
+ socket.on('prompt-response', (response) => {
2815
+ resolve(response.promptResult);
2816
+ socket.disconnect();
2817
+ });
2818
+ socket.on('error', (error) => {
2819
+ reject(deserializeError(error));
2820
+ socket.disconnect();
2821
+ });
2822
+ });
2823
+ socket.disconnect();
2824
+ return promptResult;
2825
+ }
2826
+ }
2827
+ /**
2828
+ * TODO: Maybe use `$exportJson`
2829
+ * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
2830
+ * TODO: [🍓] Allow to list compatible models with each variant
2831
+ * TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
2832
+ * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
2833
+ * TODO: [🧠] Maybe remove `@promptbook/remote-client` and just use `@promptbook/core`
2834
+ */
2835
+
2836
+ /**
2837
+ * Execution Tools for calling OpenAI compatible API
2838
+ *
2839
+ * Note: This can be used for any OpenAI compatible APIs
2840
+ *
2841
+ * @public exported from `@promptbook/openai`
2842
+ */
2843
+ const createOpenAiCompatibleExecutionTools = Object.assign((options) => {
2844
+ if (options.isProxied) {
2845
+ return new RemoteLlmExecutionTools({
2846
+ ...options,
2847
+ identification: {
2848
+ isAnonymous: true,
2849
+ llmToolsConfiguration: [
2850
+ {
2851
+ title: 'OpenAI Compatible (proxied)',
2852
+ packageName: '@promptbook/openai',
2853
+ className: 'OpenAiCompatibleExecutionTools',
2854
+ options: {
2855
+ ...options,
2856
+ isProxied: false,
2857
+ },
2858
+ },
2859
+ ],
2860
+ },
2861
+ });
2862
+ }
2863
+ if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
2864
+ options = { ...options, dangerouslyAllowBrowser: true };
2865
+ }
2866
+ return new HardcodedOpenAiCompatibleExecutionTools(options.defaultModelName, options);
2867
+ }, {
2868
+ packageName: '@promptbook/openai',
2869
+ className: 'OpenAiCompatibleExecutionTools',
2870
+ });
2871
+ /**
2872
+ * Execution Tools for calling ONE SPECIFIC PRECONFIGURED OpenAI compatible provider
2873
+ *
2874
+ * @private for `createOpenAiCompatibleExecutionTools`
2875
+ */
2876
+ class HardcodedOpenAiCompatibleExecutionTools extends OpenAiCompatibleExecutionTools {
2877
+ /**
2878
+ * Creates OpenAI compatible Execution Tools.
2879
+ *
2880
+ * @param options which are relevant are directly passed to the OpenAI compatible client
2881
+ */
2882
+ constructor(defaultModelName, options) {
2883
+ super(options);
2884
+ this.defaultModelName = defaultModelName;
2885
+ this.options = options;
2886
+ }
2887
+ get title() {
2888
+ return `${this.defaultModelName} on ${this.options.baseURL}`;
2889
+ }
2890
+ get description() {
2891
+ return `OpenAI compatible connected to "${this.options.baseURL}" model "${this.defaultModelName}"`;
2892
+ }
2893
+ /**
2894
+ * List all available models (non dynamically)
2895
+ *
2896
+ * Note: Purpose of this is to provide more information about models than standard listing from API
2897
+ */
2898
+ get HARDCODED_MODELS() {
2899
+ return [
2900
+ {
2901
+ modelName: this.defaultModelName,
2902
+ modelVariant: 'CHAT',
2903
+ modelDescription: '', // <- TODO: What is the best value here, maybe `this.description`?
2904
+ },
2905
+ ];
2906
+ }
2907
+ /**
2908
+ * Computes the usage
2909
+ */
2910
+ computeUsage(...args) {
2911
+ return {
2912
+ ...computeOpenAiUsage(...args),
2913
+ price: UNCERTAIN_ZERO_VALUE, // <- TODO: Maybe in future pass this counting mechanism, but for now, we dont know
2914
+ };
2915
+ }
2916
+ /**
2917
+ * Default model for chat variant.
2918
+ */
2919
+ getDefaultChatModel() {
2920
+ return this.getDefaultModel(this.defaultModelName);
2921
+ }
2922
+ /**
2923
+ * Default model for completion variant.
2924
+ */
2925
+ getDefaultCompletionModel() {
2926
+ throw new PipelineExecutionError(`${this.title} does not support COMPLETION model variant`);
2927
+ }
2928
+ /**
2929
+ * Default model for completion variant.
2930
+ */
2931
+ getDefaultEmbeddingModel() {
2932
+ throw new PipelineExecutionError(`${this.title} does not support EMBEDDING model variant`);
2933
+ }
2934
+ }
2935
+ /**
2936
+ * TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
2937
+ * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
2938
+ */
2939
+
2361
2940
  /**
2362
2941
  * Execution Tools for calling OpenAI API
2363
2942
  *
@@ -2369,6 +2948,9 @@
2369
2948
  if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
2370
2949
  options = { ...options, dangerouslyAllowBrowser: true };
2371
2950
  }
2951
+ if (options.isProxied) {
2952
+ throw new NotYetImplementedError(`Proxy mode is not yet implemented in createOpenAiExecutionTools`);
2953
+ }
2372
2954
  return new OpenAiExecutionTools(options);
2373
2955
  }, {
2374
2956
  packageName: '@promptbook/openai',
@@ -2519,6 +3101,7 @@
2519
3101
  * TODO: [®] DRY Register logic
2520
3102
  */
2521
3103
 
3104
+ // Note: OpenAiCompatibleExecutionTools is an abstract class and cannot be instantiated directly
2522
3105
  /**
2523
3106
  * Registration of LLM provider
2524
3107
  *
@@ -2539,6 +3122,20 @@
2539
3122
  * @public exported from `@promptbook/cli`
2540
3123
  */
2541
3124
  const _OpenAiAssistantRegistration = $llmToolsRegister.register(createOpenAiAssistantExecutionTools);
3125
+ /**
3126
+ * Registration of the OpenAI Compatible provider
3127
+ *
3128
+ * Note: [🏐] Configurations registrations are done in register-constructor.ts BUT constructor register-constructor.ts
3129
+ *
3130
+ * @public exported from `@promptbook/openai`
3131
+ * @public exported from `@promptbook/wizard`
3132
+ * @public exported from `@promptbook/cli`
3133
+ */
3134
+ const _OpenAiCompatibleRegistration = $llmToolsRegister.register(createOpenAiCompatibleExecutionTools);
3135
+ /**
3136
+ * Note: OpenAiCompatibleExecutionTools is an abstract class and cannot be registered directly.
3137
+ * It serves as a base class for OpenAiExecutionTools and other compatible implementations.
3138
+ */
2542
3139
  /**
2543
3140
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
2544
3141
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2551,8 +3148,10 @@
2551
3148
  exports.OpenAiExecutionTools = OpenAiExecutionTools;
2552
3149
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
2553
3150
  exports._OpenAiAssistantRegistration = _OpenAiAssistantRegistration;
3151
+ exports._OpenAiCompatibleRegistration = _OpenAiCompatibleRegistration;
2554
3152
  exports._OpenAiRegistration = _OpenAiRegistration;
2555
3153
  exports.createOpenAiAssistantExecutionTools = createOpenAiAssistantExecutionTools;
3154
+ exports.createOpenAiCompatibleExecutionTools = createOpenAiCompatibleExecutionTools;
2556
3155
  exports.createOpenAiExecutionTools = createOpenAiExecutionTools;
2557
3156
 
2558
3157
  Object.defineProperty(exports, '__esModule', { value: true });