@promptbook/remote-server 0.95.0 → 0.98.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 +12 -0
- package/esm/index.es.js +61 -1
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +61 -1
- package/umd/index.umd.js.map +1 -1
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.
|
|
18
|
+
* It follows semantic versioning (e.g., `0.98.0-1`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.0-2",
|
|
4
4
|
"description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"module": "./esm/index.es.js",
|
|
75
75
|
"typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@promptbook/core": "0.
|
|
77
|
+
"@promptbook/core": "0.98.0-2"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.98.0-2';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -7836,6 +7836,66 @@
|
|
|
7836
7836
|
response.setHeader('X-Powered-By', 'Promptbook engine');
|
|
7837
7837
|
next();
|
|
7838
7838
|
});
|
|
7839
|
+
// Note: OpenAI-compatible chat completions endpoint
|
|
7840
|
+
app.post('/v1/chat/completions', async (request, response) => {
|
|
7841
|
+
// TODO: !!!! Make more promptbook-native:
|
|
7842
|
+
try {
|
|
7843
|
+
const params = request.body;
|
|
7844
|
+
const { model, messages } = params;
|
|
7845
|
+
// Convert messages to a single prompt
|
|
7846
|
+
const prompt = messages
|
|
7847
|
+
.map((message) => `${message.role}: ${message.content}`)
|
|
7848
|
+
.join('\n');
|
|
7849
|
+
// Get pipeline for the book
|
|
7850
|
+
if (!collection) {
|
|
7851
|
+
throw new Error('No collection available');
|
|
7852
|
+
}
|
|
7853
|
+
const pipeline = await collection.getPipelineByUrl(model);
|
|
7854
|
+
const pipelineExecutor = createPipelineExecutor({
|
|
7855
|
+
pipeline,
|
|
7856
|
+
tools: await getExecutionToolsFromIdentification({
|
|
7857
|
+
isAnonymous: true,
|
|
7858
|
+
llmToolsConfiguration: [],
|
|
7859
|
+
}),
|
|
7860
|
+
});
|
|
7861
|
+
// Execute the pipeline with the prompt content as input
|
|
7862
|
+
const result = await pipelineExecutor({ prompt }).asPromise({ isCrashedOnError: true });
|
|
7863
|
+
if (!result.isSuccessful) {
|
|
7864
|
+
throw new Error(`Failed to execute book: ${result.errors.join(', ')}`);
|
|
7865
|
+
}
|
|
7866
|
+
// Return the result in OpenAI-compatible format
|
|
7867
|
+
response.json({
|
|
7868
|
+
id: 'chatcmpl-' + Math.random().toString(36).substring(2),
|
|
7869
|
+
object: 'chat.completion',
|
|
7870
|
+
created: Math.floor(Date.now() / 1000),
|
|
7871
|
+
model,
|
|
7872
|
+
choices: [
|
|
7873
|
+
{
|
|
7874
|
+
index: 0,
|
|
7875
|
+
message: {
|
|
7876
|
+
role: 'assistant',
|
|
7877
|
+
content: result.outputParameters.response,
|
|
7878
|
+
},
|
|
7879
|
+
finish_reason: 'stop',
|
|
7880
|
+
},
|
|
7881
|
+
],
|
|
7882
|
+
usage: {
|
|
7883
|
+
prompt_tokens: 0,
|
|
7884
|
+
completion_tokens: 0,
|
|
7885
|
+
total_tokens: 0,
|
|
7886
|
+
},
|
|
7887
|
+
});
|
|
7888
|
+
}
|
|
7889
|
+
catch (error) {
|
|
7890
|
+
response.status(500).json({
|
|
7891
|
+
error: {
|
|
7892
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
7893
|
+
type: 'server_error',
|
|
7894
|
+
code: 'internal_error',
|
|
7895
|
+
},
|
|
7896
|
+
});
|
|
7897
|
+
}
|
|
7898
|
+
});
|
|
7839
7899
|
// TODO: [🥺] Expose openapiJson to consumer and also allow to add new routes
|
|
7840
7900
|
app.use(OpenApiValidator__namespace.middleware({
|
|
7841
7901
|
apiSpec: openapiJson,
|