@promptbook/remote-server 0.95.0 → 0.98.0-3

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
@@ -25,6 +25,10 @@ Write AI applications using plain human language across multiple models and plat
25
25
 
26
26
 
27
27
 
28
+ <blockquote style="color: #ff8811">
29
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
30
+ </blockquote>
31
+
28
32
  ## 📦 Package `@promptbook/remote-server`
29
33
 
30
34
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -56,6 +60,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
56
60
 
57
61
  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**!
58
62
 
63
+
64
+
59
65
  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!
60
66
 
61
67
  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.
@@ -181,6 +187,8 @@ Join our growing community of developers and users:
181
187
 
182
188
  _A concise, Markdown-based DSL for crafting AI workflows and automations._
183
189
 
190
+
191
+
184
192
  ### Introduction
185
193
 
186
194
  Book is a Markdown-based language that simplifies the creation of AI applications, workflows, and automations. With human-readable commands, you can define inputs, outputs, personas, knowledge sources, and actions—without needing model-specific details.
@@ -230,6 +238,8 @@ Personas can have access to different knowledge, tools and actions. They can als
230
238
 
231
239
  - [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
232
240
 
241
+
242
+
233
243
  ### **3. How:** Knowledge, Instruments and Actions
234
244
 
235
245
  The resources used by the personas are used to do the work.
@@ -329,6 +339,8 @@ The following glossary is used to clarify certain concepts:
329
339
 
330
340
  _Note: This section is not a complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
331
341
 
342
+
343
+
332
344
  ### 💯 Core concepts
333
345
 
334
346
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
package/esm/index.es.js CHANGED
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.95.0';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.98.0-3';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7821,6 +7821,66 @@ function startRemoteServer(options) {
7821
7821
  response.setHeader('X-Powered-By', 'Promptbook engine');
7822
7822
  next();
7823
7823
  });
7824
+ // Note: OpenAI-compatible chat completions endpoint
7825
+ app.post('/v1/chat/completions', async (request, response) => {
7826
+ // TODO: !!!! Make more promptbook-native:
7827
+ try {
7828
+ const params = request.body;
7829
+ const { model, messages } = params;
7830
+ // Convert messages to a single prompt
7831
+ const prompt = messages
7832
+ .map((message) => `${message.role}: ${message.content}`)
7833
+ .join('\n');
7834
+ // Get pipeline for the book
7835
+ if (!collection) {
7836
+ throw new Error('No collection available');
7837
+ }
7838
+ const pipeline = await collection.getPipelineByUrl(model);
7839
+ const pipelineExecutor = createPipelineExecutor({
7840
+ pipeline,
7841
+ tools: await getExecutionToolsFromIdentification({
7842
+ isAnonymous: true,
7843
+ llmToolsConfiguration: [],
7844
+ }),
7845
+ });
7846
+ // Execute the pipeline with the prompt content as input
7847
+ const result = await pipelineExecutor({ prompt }).asPromise({ isCrashedOnError: true });
7848
+ if (!result.isSuccessful) {
7849
+ throw new Error(`Failed to execute book: ${result.errors.join(', ')}`);
7850
+ }
7851
+ // Return the result in OpenAI-compatible format
7852
+ response.json({
7853
+ id: 'chatcmpl-' + Math.random().toString(36).substring(2),
7854
+ object: 'chat.completion',
7855
+ created: Math.floor(Date.now() / 1000),
7856
+ model,
7857
+ choices: [
7858
+ {
7859
+ index: 0,
7860
+ message: {
7861
+ role: 'assistant',
7862
+ content: result.outputParameters.response,
7863
+ },
7864
+ finish_reason: 'stop',
7865
+ },
7866
+ ],
7867
+ usage: {
7868
+ prompt_tokens: 0,
7869
+ completion_tokens: 0,
7870
+ total_tokens: 0,
7871
+ },
7872
+ });
7873
+ }
7874
+ catch (error) {
7875
+ response.status(500).json({
7876
+ error: {
7877
+ message: error instanceof Error ? error.message : 'Unknown error',
7878
+ type: 'server_error',
7879
+ code: 'internal_error',
7880
+ },
7881
+ });
7882
+ }
7883
+ });
7824
7884
  // TODO: [🥺] Expose openapiJson to consumer and also allow to add new routes
7825
7885
  app.use(OpenApiValidator.middleware({
7826
7886
  apiSpec: openapiJson,