@aj-archipelago/cortex 1.0.17 → 1.0.19

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.
@@ -1,4 +1,5 @@
1
1
  // pathwayTools.js
2
+ import { encode , decode } from 'gpt-3-encoder';
2
3
 
3
4
  // callPathway - call a pathway from another pathway
4
5
  const callPathway = async (config, pathwayName, args) => {
@@ -12,4 +13,12 @@ const callPathway = async (config, pathwayName, args) => {
12
13
  return data?.result;
13
14
  };
14
15
 
15
- export { callPathway };
16
+ const gpt3Encode = (text) => {
17
+ return encode(text);
18
+ }
19
+
20
+ const gpt3Decode = (text) => {
21
+ return decode(text);
22
+ }
23
+
24
+ export { callPathway, gpt3Encode, gpt3Decode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aj-archipelago/cortex",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  export default {
2
- prompt: `{{text}}`,
2
+ prompt: `{{{text}}}`,
3
3
  model: 'azure-cognitive',
4
4
  inputParameters: {
5
5
  inputVector: ``,
@@ -204,7 +204,7 @@ class PathwayResolver {
204
204
  async promptAndParse(args) {
205
205
  // Get saved context from contextId or change contextId if needed
206
206
  const { contextId } = args;
207
- this.savedContextId = contextId ? contextId : null;
207
+ this.savedContextId = contextId ? contextId : uuidv4();
208
208
  this.savedContext = contextId ? (getv && (await getv(contextId)) || {}) : {};
209
209
 
210
210
  // Save the context before processing the request
@@ -53,6 +53,8 @@ class AzureCognitivePlugin extends ModelPlugin {
53
53
  }
54
54
 
55
55
  if (mode == 'index') {
56
+
57
+ /*
56
58
  const calculateInputVector = async () => {
57
59
  try{
58
60
  if(!text || !text.trim()){
@@ -63,11 +65,12 @@ class AzureCognitivePlugin extends ModelPlugin {
63
65
  console.log(`Error in calculating input vector for text: ${text}, error: ${err}`);
64
66
  }
65
67
  }
68
+ */
66
69
 
67
70
  const doc = {
68
71
  id: uuidv4(),
69
72
  content: text,
70
- contentVector: inputVector || (await calculateInputVector()),
73
+ //contentVector: inputVector || (await calculateInputVector()),
71
74
  owner: savedContextId,
72
75
  docId: docId || uuidv4(),
73
76
  createdAt: new Date().toISOString()
@@ -197,6 +197,13 @@ class ModelPlugin {
197
197
  }
198
198
  });
199
199
 
200
+ // Clean up any null messages if they exist
201
+ expandedMessages.forEach((message) => {
202
+ if (typeof message === 'object' && message.content === null) {
203
+ message.content = '';
204
+ }
205
+ });
206
+
200
207
  return expandedMessages;
201
208
  }
202
209
 
@@ -57,7 +57,7 @@ class OpenAIChatPlugin extends ModelPlugin {
57
57
  if (isPalmFormat) {
58
58
  const context = modelPrompt.context || '';
59
59
  const examples = modelPrompt.examples || [];
60
- requestMessages = this.convertPalmToOpenAIMessages(context, examples, expandedMessages);
60
+ requestMessages = this.convertPalmToOpenAIMessages(context, examples, modelPromptMessages);
61
61
  }
62
62
 
63
63
  // Check if the token length exceeds the model's max token length