@aj-archipelago/cortex 1.1.36 → 1.1.37

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.
@@ -3,6 +3,7 @@ import { S3 } from '@aws-sdk/client-s3';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import logger from './logger.js';
6
+ import { Prompt } from '../server/prompt.js';
6
7
 
7
8
  class StorageStrategy {
8
9
  async load() { throw new Error('Not implemented'); }
@@ -285,6 +286,33 @@ class PathwayManager {
285
286
  await this.storage.save(pathways);
286
287
  }
287
288
 
289
+ /**
290
+ * Transforms the prompts in a pathway to include the system prompt.
291
+ * @param {Object} pathway - The pathway object to transform.
292
+ * @param {string[]} pathway.prompt - Array of user prompts.
293
+ * @param {string} pathway.systemPrompt - The system prompt to prepend to each user prompt.
294
+ * @returns {Object} A new pathway object with transformed prompts.
295
+ */
296
+ async transformPrompts(pathway) {
297
+ const { prompt, systemPrompt } = pathway;
298
+
299
+ const newPathway = { ...pathway };
300
+
301
+ // Transform each prompt in the array
302
+ newPathway.prompt = prompt.map(p => {
303
+ return new Prompt({
304
+ messages: [
305
+ // Prepend the system prompt as a system message
306
+ { "role": "system", "content": systemPrompt },
307
+ // Add the original prompt as a user message
308
+ { "role": "user", "content": p },
309
+ ]
310
+ })
311
+ });
312
+
313
+ return newPathway;
314
+ }
315
+
288
316
  async putPathway(name, pathway, userId, secret, displayName) {
289
317
  if (!userId || !secret) {
290
318
  throw new Error('Both userId and secret are mandatory for adding or updating a pathway');
@@ -329,6 +357,7 @@ class PathwayManager {
329
357
 
330
358
  input PathwayInput {
331
359
  prompt: [String!]!
360
+ systemPrompt: String
332
361
  inputParameters: JSONObject
333
362
  model: String
334
363
  enableCache: Boolean
@@ -413,7 +442,7 @@ class PathwayManager {
413
442
  throw new Error(`Pathway '${pathwayName}' not found for user '${userId}'`);
414
443
  }
415
444
 
416
- return pathways[userId][pathwayName];
445
+ return this.transformPrompts(pathways[userId][pathwayName]);
417
446
  }
418
447
  }
419
448
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aj-archipelago/cortex",
3
- "version": "1.1.36",
3
+ "version": "1.1.37",
4
4
  "description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
5
5
  "private": false,
6
6
  "repository": {