@promptbook/cli 0.94.0-1 → 0.94.0-2

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/README.md CHANGED
@@ -114,6 +114,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
114
114
 
115
115
  During the computer revolution, we have seen [multiple generations of computer languages](https://github.com/webgptorg/promptbook/discussions/180), from the physical rewiring of the vacuum tubes through low-level machine code to the high-level languages like Python or JavaScript. And now, we're on the edge of the **next revolution**!
116
116
 
117
+
118
+
117
119
  It's a revolution of writing software in **plain human language** that is understandable and executable by both humans and machines – and it's going to change everything!
118
120
 
119
121
  The incredible growth in power of microprocessors and the Moore's Law have been the driving force behind the ever-more powerful languages, and it's been an amazing journey! Similarly, the large language models (like GPT or Claude) are the next big thing in language technology, and they're set to transform the way we interact with computers.
@@ -239,16 +241,8 @@ Join our growing community of developers and users:
239
241
 
240
242
  _A concise, Markdown-based DSL for crafting AI workflows and automations._
241
243
 
242
- ---
243
244
 
244
- ### 📑 Table of Contents
245
245
 
246
- - [Introduction](#introduction)
247
- - [Example](#example)
248
- - [1. What: Workflows, Tasks & Parameters](#1-what-workflows-tasks--parameters)
249
- - [2. Who: Personas](#2-who-personas)
250
- - [3. How: Knowledge, Instruments & Actions](#3-how-knowledge-instruments-and-actions)
251
- - [General Principles](#general-principles)
252
246
 
253
247
  ### Introduction
254
248
 
@@ -299,6 +293,8 @@ Personas can have access to different knowledge, tools and actions. They can als
299
293
 
300
294
  - [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
301
295
 
296
+
297
+
302
298
  ### **3. How:** Knowledge, Instruments and Actions
303
299
 
304
300
  The resources used by the personas are used to do the work.
@@ -398,6 +394,8 @@ The following glossary is used to clarify certain concepts:
398
394
 
399
395
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
400
396
 
397
+
398
+
401
399
  ### 💯 Core concepts
402
400
 
403
401
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
package/esm/index.es.js CHANGED
@@ -28,7 +28,6 @@ import swaggerUi from 'swagger-ui-express';
28
28
  import Anthropic from '@anthropic-ai/sdk';
29
29
  import Bottleneck from 'bottleneck';
30
30
  import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
31
- import fetch$1 from 'node-fetch';
32
31
  import OpenAI from 'openai';
33
32
  import { Readability } from '@mozilla/readability';
34
33
  import { JSDOM } from 'jsdom';
@@ -48,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
48
47
  * @generated
49
48
  * @see https://github.com/webgptorg/promptbook
50
49
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.94.0-1';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.94.0-2';
52
51
  /**
53
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -17014,7 +17013,7 @@ const _OllamaMetadataRegistration = $llmToolsMetadataRegister.register({
17014
17013
  packageName: '@promptbook/ollama',
17015
17014
  className: 'OllamaExecutionTools',
17016
17015
  options: {
17017
- baseUrl: 'http://localhost:11434',
17016
+ baseURL: 'http://localhost:11434',
17018
17017
  model: 'llama2',
17019
17018
  maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17020
17019
  },
@@ -17027,7 +17026,7 @@ const _OllamaMetadataRegistration = $llmToolsMetadataRegister.register({
17027
17026
  packageName: '@promptbook/ollama',
17028
17027
  className: 'OllamaExecutionTools',
17029
17028
  options: {
17030
- baseUrl: env.OLLAMA_BASE_URL,
17029
+ baseURL: env.OLLAMA_BASE_URL,
17031
17030
  model: env.OLLAMA_MODEL || 'llama2',
17032
17031
  maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17033
17032
  },
@@ -17040,203 +17039,6 @@ const _OllamaMetadataRegistration = $llmToolsMetadataRegister.register({
17040
17039
  * Note: [💞] Ignore a discrepancy between file name and entity name
17041
17040
  */
17042
17041
 
17043
- /**
17044
- * Execution Tools for calling a local Ollama model via HTTP API
17045
- *
17046
- * @public exported from `@promptbook/ollama`
17047
- */
17048
- class OllamaExecutionTools {
17049
- constructor(options) {
17050
- this.options = options;
17051
- this.limiter = new Bottleneck({
17052
- minTime: 60000 / (options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
17053
- });
17054
- }
17055
- get title() {
17056
- return 'Ollama';
17057
- }
17058
- get description() {
17059
- return 'Local Ollama LLM via HTTP';
17060
- }
17061
- async checkConfiguration() {
17062
- const res = await fetch$1(`${this.options.baseUrl}/models`);
17063
- if (!res.ok)
17064
- throw new UnexpectedError(`Failed to reach Ollama API at ${this.options.baseUrl}`);
17065
- }
17066
- async listModels() {
17067
- const res = await fetch$1(`${this.options.baseUrl}/models`);
17068
- if (!res.ok)
17069
- throw new UnexpectedError(`Error listing Ollama models: ${res.statusText}`);
17070
- const data = (await res.json());
17071
- return data.map((m) => ({ modelName: m.name, modelVariant: 'CHAT' }));
17072
- }
17073
- async callChatModel(prompt) {
17074
- const { content, parameters, modelRequirements } = prompt;
17075
- if (modelRequirements.modelVariant !== 'CHAT') {
17076
- throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
17077
- }
17078
- const modelName = modelRequirements.modelName || this.options.model;
17079
- const body = {
17080
- model: modelName,
17081
- messages: [
17082
- ...(modelRequirements.systemMessage
17083
- ? [{ role: 'system', content: modelRequirements.systemMessage }]
17084
- : []),
17085
- { role: 'user', content: content },
17086
- ],
17087
- parameters: parameters,
17088
- };
17089
- const start = $getCurrentDate();
17090
- const res = await this.limiter.schedule(() => fetch$1(`${this.options.baseUrl}/chat/completions`, {
17091
- method: 'POST',
17092
- headers: { 'Content-Type': 'application/json' },
17093
- body: JSON.stringify(body),
17094
- }));
17095
- if (!res.ok)
17096
- throw new PipelineExecutionError(`Ollama API error: ${res.statusText}`);
17097
- const json = await res.json();
17098
- const complete = $getCurrentDate();
17099
- if (!json.choices || !json.choices[0]) {
17100
- throw new PipelineExecutionError('No choices from Ollama');
17101
- }
17102
- const resultContent = json.choices[0].message.content;
17103
- const usage = { price: { value: 0, isUncertain: true }, input: {}, output: {} }; /* <- !!! */
17104
- return exportJson({
17105
- name: 'promptResult',
17106
- message: 'Result of Ollama',
17107
- order: [],
17108
- value: {
17109
- content: resultContent,
17110
- modelName,
17111
- timing: { start, complete },
17112
- usage,
17113
- rawPromptContent: content,
17114
- rawRequest: body,
17115
- rawResponse: json,
17116
- },
17117
- });
17118
- }
17119
- }
17120
-
17121
- /**
17122
- * Execution Tools for calling Ollama API
17123
- *
17124
- * @public exported from `@promptbook/ollama`
17125
- */
17126
- const createOllamaExecutionTools = Object.assign((options) => new OllamaExecutionTools(options), {
17127
- packageName: '@promptbook/ollama',
17128
- className: 'OllamaExecutionTools',
17129
- });
17130
-
17131
- /**
17132
- * Registration of LLM provider
17133
- *
17134
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
17135
- *
17136
- * @public exported from `@promptbook/ollama`
17137
- * @public exported from `@promptbook/wizzard`
17138
- * @public exported from `@promptbook/cli`
17139
- */
17140
- const _OllamaRegistration = $llmToolsRegister.register(createOllamaExecutionTools);
17141
- /**
17142
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
17143
- * Note: [💞] Ignore a discrepancy between file name and entity name
17144
- */
17145
-
17146
- /**
17147
- * Registration of LLM provider metadata
17148
- *
17149
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
17150
- *
17151
- * @public exported from `@promptbook/core`
17152
- * @public exported from `@promptbook/wizzard`
17153
- * @public exported from `@promptbook/cli`
17154
- */
17155
- const _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
17156
- title: 'Open AI',
17157
- packageName: '@promptbook/openai',
17158
- className: 'OpenAiExecutionTools',
17159
- envVariables: ['OPENAI_API_KEY'],
17160
- trustLevel: 'CLOSED',
17161
- order: MODEL_ORDERS.TOP_TIER,
17162
- getBoilerplateConfiguration() {
17163
- return {
17164
- title: 'Open AI',
17165
- packageName: '@promptbook/openai',
17166
- className: 'OpenAiExecutionTools',
17167
- options: {
17168
- apiKey: 'sk-',
17169
- maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17170
- },
17171
- };
17172
- },
17173
- createConfigurationFromEnv(env) {
17174
- // Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
17175
- if (typeof env.OPENAI_API_KEY === 'string') {
17176
- return {
17177
- title: 'Open AI (from env)',
17178
- packageName: '@promptbook/openai',
17179
- className: 'OpenAiExecutionTools',
17180
- options: {
17181
- apiKey: env.OPENAI_API_KEY,
17182
- },
17183
- };
17184
- }
17185
- return null;
17186
- },
17187
- });
17188
- /**
17189
- * Registration of the OpenAI Assistant metadata
17190
- *
17191
- * Note: [🏐] Configurations registrations are done in the metadata registration section, but the constructor registration is handled separately.
17192
- *
17193
- * @public exported from `@promptbook/core`
17194
- * @public exported from `@promptbook/wizzard`
17195
- * @public exported from `@promptbook/cli`
17196
- */
17197
- const _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
17198
- title: 'Open AI Assistant',
17199
- packageName: '@promptbook/openai',
17200
- className: 'OpenAiAssistantExecutionTools',
17201
- envVariables: null,
17202
- // <- TODO: ['OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID']
17203
- trustLevel: 'CLOSED',
17204
- order: MODEL_ORDERS.NORMAL,
17205
- getBoilerplateConfiguration() {
17206
- return {
17207
- title: 'Open AI Assistant',
17208
- packageName: '@promptbook/openai',
17209
- className: 'OpenAiAssistantExecutionTools',
17210
- options: {
17211
- apiKey: 'sk-',
17212
- assistantId: 'asst_',
17213
- maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17214
- },
17215
- };
17216
- },
17217
- createConfigurationFromEnv(env) {
17218
- return null;
17219
- /*
17220
- if (typeof env.OPENAI_API_KEY === 'string' || typeof env.OPENAI_XXX === 'string') {
17221
- return {
17222
- title: 'Open AI Assistant (from env)',
17223
- packageName: '@promptbook/openai',
17224
- className: 'OpenAiAssistantExecutionTools',
17225
- options: {
17226
- apiKey: env.OPENAI_API_KEY!,
17227
- assistantId: env.OPENAI_XXX!
17228
- },
17229
- };
17230
- }
17231
-
17232
- return null;
17233
- */
17234
- },
17235
- });
17236
- /**
17237
- * Note: [💞] Ignore a discrepancy between file name and entity name
17238
- */
17239
-
17240
17042
  /**
17241
17043
  * Computes the usage of the OpenAI API based on the response from OpenAI
17242
17044
  *
@@ -17349,7 +17151,7 @@ class OpenAiExecutionTools {
17349
17151
  /**
17350
17152
  * List all available OpenAI models that can be used
17351
17153
  */
17352
- listModels() {
17154
+ async listModels() {
17353
17155
  /*
17354
17156
  Note: Dynamic lising of the models
17355
17157
  const models = await this.openai.models.list({});
@@ -17357,7 +17159,26 @@ class OpenAiExecutionTools {
17357
17159
  console.log({ models });
17358
17160
  console.log(models.data);
17359
17161
  */
17360
- return OPENAI_MODELS;
17162
+ const client = await this.getClient();
17163
+ const rawModelsList = await client.models.list();
17164
+ const availableModels = rawModelsList.data
17165
+ .sort((a, b) => (a.created > b.created ? 1 : -1))
17166
+ .map((modelFromApi) => {
17167
+ // TODO: !!!! What about other model compatibilities?
17168
+ const modelFromList = OPENAI_MODELS.find(({ modelName }) => modelName === modelFromApi.id ||
17169
+ modelName.startsWith(modelFromApi.id) ||
17170
+ modelFromApi.id.startsWith(modelName));
17171
+ if (modelFromList !== undefined) {
17172
+ return modelFromList;
17173
+ }
17174
+ return {
17175
+ modelVariant: 'CHAT',
17176
+ modelTitle: modelFromApi.id,
17177
+ modelName: modelFromApi.id,
17178
+ modelDescription: '',
17179
+ };
17180
+ });
17181
+ return availableModels;
17361
17182
  }
17362
17183
  /**
17363
17184
  * Calls OpenAI API to use a chat model.
@@ -17637,6 +17458,163 @@ class OpenAiExecutionTools {
17637
17458
  * TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
17638
17459
  */
17639
17460
 
17461
+ /**
17462
+ * Execution Tools for calling OpenAI API
17463
+ *
17464
+ * Note: This can be also used for other OpenAI compatible APIs, like Ollama
17465
+ *
17466
+ * @public exported from `@promptbook/openai`
17467
+ */
17468
+ const createOpenAiExecutionTools = Object.assign((options) => {
17469
+ // TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
17470
+ if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
17471
+ options = { ...options, dangerouslyAllowBrowser: true };
17472
+ }
17473
+ return new OpenAiExecutionTools(options);
17474
+ }, {
17475
+ packageName: '@promptbook/openai',
17476
+ className: 'OpenAiExecutionTools',
17477
+ });
17478
+ /**
17479
+ * TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
17480
+ * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
17481
+ */
17482
+
17483
+ /**
17484
+ * Default base URL for Ollama API
17485
+ *
17486
+ * @public exported from `@promptbook/ollama`
17487
+ */
17488
+ const DEFAULT_OLLAMA_BASE_URL = 'http://localhost:11434'; // <- TODO: !!!! What is the correct base URL? /v1?
17489
+
17490
+ /**
17491
+ * Execution Tools for calling Ollama API
17492
+ *
17493
+ * @public exported from `@promptbook/ollama`
17494
+ */
17495
+ const createOllamaExecutionTools = Object.assign((ollamaOptions) => {
17496
+ const openAiCompatibleOptions = {
17497
+ baseURL: DEFAULT_OLLAMA_BASE_URL,
17498
+ ...ollamaOptions,
17499
+ userId: 'ollama',
17500
+ };
17501
+ // TODO: !!!! Listing the models - do it dynamically in OpenAiExecutionTools
17502
+ // TODO: !!!! Do not allow to create Assistant from OpenAi compatible tools
17503
+ return createOpenAiExecutionTools(openAiCompatibleOptions);
17504
+ }, {
17505
+ packageName: '@promptbook/ollama',
17506
+ className: 'OllamaExecutionTools',
17507
+ });
17508
+
17509
+ /**
17510
+ * Registration of LLM provider
17511
+ *
17512
+ * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
17513
+ *
17514
+ * @public exported from `@promptbook/ollama`
17515
+ * @public exported from `@promptbook/wizzard`
17516
+ * @public exported from `@promptbook/cli`
17517
+ */
17518
+ const _OllamaRegistration = $llmToolsRegister.register(createOllamaExecutionTools);
17519
+ /**
17520
+ * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
17521
+ * Note: [💞] Ignore a discrepancy between file name and entity name
17522
+ */
17523
+
17524
+ /**
17525
+ * Registration of LLM provider metadata
17526
+ *
17527
+ * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
17528
+ *
17529
+ * @public exported from `@promptbook/core`
17530
+ * @public exported from `@promptbook/wizzard`
17531
+ * @public exported from `@promptbook/cli`
17532
+ */
17533
+ const _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
17534
+ title: 'Open AI',
17535
+ packageName: '@promptbook/openai',
17536
+ className: 'OpenAiExecutionTools',
17537
+ envVariables: ['OPENAI_API_KEY'],
17538
+ trustLevel: 'CLOSED',
17539
+ order: MODEL_ORDERS.TOP_TIER,
17540
+ getBoilerplateConfiguration() {
17541
+ return {
17542
+ title: 'Open AI',
17543
+ packageName: '@promptbook/openai',
17544
+ className: 'OpenAiExecutionTools',
17545
+ options: {
17546
+ apiKey: 'sk-',
17547
+ maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17548
+ },
17549
+ };
17550
+ },
17551
+ createConfigurationFromEnv(env) {
17552
+ // Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
17553
+ if (typeof env.OPENAI_API_KEY === 'string') {
17554
+ return {
17555
+ title: 'Open AI (from env)',
17556
+ packageName: '@promptbook/openai',
17557
+ className: 'OpenAiExecutionTools',
17558
+ options: {
17559
+ apiKey: env.OPENAI_API_KEY,
17560
+ },
17561
+ };
17562
+ }
17563
+ return null;
17564
+ },
17565
+ });
17566
+ /**
17567
+ * Registration of the OpenAI Assistant metadata
17568
+ *
17569
+ * Note: [🏐] Configurations registrations are done in the metadata registration section, but the constructor registration is handled separately.
17570
+ *
17571
+ * @public exported from `@promptbook/core`
17572
+ * @public exported from `@promptbook/wizzard`
17573
+ * @public exported from `@promptbook/cli`
17574
+ */
17575
+ const _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
17576
+ title: 'Open AI Assistant',
17577
+ packageName: '@promptbook/openai',
17578
+ className: 'OpenAiAssistantExecutionTools',
17579
+ envVariables: null,
17580
+ // <- TODO: ['OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID']
17581
+ trustLevel: 'CLOSED',
17582
+ order: MODEL_ORDERS.NORMAL,
17583
+ getBoilerplateConfiguration() {
17584
+ return {
17585
+ title: 'Open AI Assistant',
17586
+ packageName: '@promptbook/openai',
17587
+ className: 'OpenAiAssistantExecutionTools',
17588
+ options: {
17589
+ apiKey: 'sk-',
17590
+ assistantId: 'asst_',
17591
+ maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
17592
+ },
17593
+ };
17594
+ },
17595
+ createConfigurationFromEnv(env) {
17596
+ return null;
17597
+ /*
17598
+ if (typeof env.OPENAI_API_KEY === 'string' || typeof env.OPENAI_XXX === 'string') {
17599
+ return {
17600
+ title: 'Open AI Assistant (from env)',
17601
+ packageName: '@promptbook/openai',
17602
+ className: 'OpenAiAssistantExecutionTools',
17603
+ options: {
17604
+ apiKey: env.OPENAI_API_KEY!,
17605
+ assistantId: env.OPENAI_XXX!
17606
+ },
17607
+ };
17608
+ }
17609
+
17610
+ return null;
17611
+ */
17612
+ },
17613
+ });
17614
+ /**
17615
+ * Note: [💞] Ignore a discrepancy between file name and entity name
17616
+ */
17617
+
17640
17618
  /**
17641
17619
  * Execution Tools for calling OpenAI API Assistants
17642
17620
  *
@@ -17824,26 +17802,6 @@ const createOpenAiAssistantExecutionTools = Object.assign((options) => {
17824
17802
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
17825
17803
  */
17826
17804
 
17827
- /**
17828
- * Execution Tools for calling OpenAI API
17829
- *
17830
- * @public exported from `@promptbook/openai`
17831
- */
17832
- const createOpenAiExecutionTools = Object.assign((options) => {
17833
- // TODO: [🧠][main] !!4 If browser, auto add `dangerouslyAllowBrowser`
17834
- if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
17835
- options = { ...options, dangerouslyAllowBrowser: true };
17836
- }
17837
- return new OpenAiExecutionTools(options);
17838
- }, {
17839
- packageName: '@promptbook/openai',
17840
- className: 'OpenAiExecutionTools',
17841
- });
17842
- /**
17843
- * TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
17844
- * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
17845
- */
17846
-
17847
17805
  /**
17848
17806
  * Registration of LLM provider
17849
17807
  *