@aj-archipelago/cortex 1.1.21 → 1.1.22

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.
Files changed (82) hide show
  1. package/config/default.example.json +84 -0
  2. package/config.js +5 -4
  3. package/helper-apps/cortex-file-handler/blobHandler.js +115 -98
  4. package/helper-apps/cortex-file-handler/fileChunker.js +13 -8
  5. package/helper-apps/cortex-file-handler/index.js +48 -2
  6. package/package.json +2 -1
  7. package/pathways/categorize.js +23 -0
  8. package/pathways/chat.js +1 -1
  9. package/pathways/chat_code.js +19 -0
  10. package/pathways/chat_context.js +19 -0
  11. package/pathways/chat_jarvis.js +19 -0
  12. package/pathways/chat_persist.js +23 -0
  13. package/pathways/code_review.js +17 -0
  14. package/pathways/cognitive_delete.js +2 -1
  15. package/pathways/cognitive_insert.js +1 -0
  16. package/pathways/cognitive_search.js +1 -0
  17. package/pathways/embeddings.js +1 -1
  18. package/pathways/expand_story.js +12 -0
  19. package/pathways/format_paragraph_turbo.js +16 -0
  20. package/pathways/format_summarization.js +21 -0
  21. package/pathways/gemini_15_vision.js +20 -0
  22. package/pathways/gemini_vision.js +20 -0
  23. package/pathways/grammar.js +30 -0
  24. package/pathways/hashtags.js +19 -0
  25. package/pathways/headline.js +43 -0
  26. package/pathways/headline_custom.js +169 -0
  27. package/pathways/highlights.js +22 -0
  28. package/pathways/image.js +2 -1
  29. package/pathways/index.js +107 -17
  30. package/pathways/jira_story.js +18 -0
  31. package/pathways/keywords.js +4 -0
  32. package/pathways/language.js +17 -6
  33. package/pathways/locations.js +93 -0
  34. package/pathways/quotes.js +19 -0
  35. package/pathways/rag.js +207 -0
  36. package/pathways/rag_jarvis.js +254 -0
  37. package/pathways/rag_search_helper.js +21 -0
  38. package/pathways/readme.js +18 -0
  39. package/pathways/release_notes.js +16 -0
  40. package/pathways/remove_content.js +31 -0
  41. package/pathways/retrieval.js +23 -0
  42. package/pathways/run_claude35_sonnet.js +21 -0
  43. package/pathways/run_claude3_haiku.js +20 -0
  44. package/pathways/run_gpt35turbo.js +20 -0
  45. package/pathways/run_gpt4.js +20 -0
  46. package/pathways/run_gpt4_32.js +20 -0
  47. package/pathways/select_extension.js +6 -0
  48. package/pathways/select_services.js +10 -0
  49. package/pathways/spelling.js +3 -0
  50. package/pathways/story_angles.js +13 -0
  51. package/pathways/styleguide/styleguide.js +221 -0
  52. package/pathways/styleguidemulti.js +127 -0
  53. package/pathways/subhead.js +48 -0
  54. package/pathways/summarize_turbo.js +98 -0
  55. package/pathways/summary.js +31 -12
  56. package/pathways/sys_claude_35_sonnet.js +19 -0
  57. package/pathways/sys_claude_3_haiku.js +19 -0
  58. package/pathways/sys_google_chat.js +19 -0
  59. package/pathways/sys_google_code_chat.js +19 -0
  60. package/pathways/sys_google_gemini_chat.js +23 -0
  61. package/pathways/sys_openai_chat.js +2 -2
  62. package/pathways/sys_openai_chat_16.js +19 -0
  63. package/pathways/sys_openai_chat_gpt4.js +19 -0
  64. package/pathways/sys_openai_chat_gpt4_32.js +19 -0
  65. package/pathways/sys_openai_chat_gpt4_turbo.js +19 -0
  66. package/pathways/tags.js +25 -0
  67. package/pathways/taxonomy.js +135 -0
  68. package/pathways/timeline.js +51 -0
  69. package/pathways/topics.js +25 -0
  70. package/pathways/topics_sentiment.js +20 -0
  71. package/pathways/transcribe.js +2 -4
  72. package/pathways/translate.js +10 -12
  73. package/pathways/translate_azure.js +13 -0
  74. package/pathways/translate_context.js +21 -0
  75. package/pathways/translate_gpt4.js +19 -0
  76. package/pathways/translate_gpt4_turbo.js +19 -0
  77. package/pathways/translate_turbo.js +19 -0
  78. package/pathways/vision.js +9 -7
  79. package/server/plugins/azureCognitivePlugin.js +10 -1
  80. package/server/plugins/openAiVisionPlugin.js +14 -6
  81. package/tests/main.test.js +2 -2
  82. package/tests/vision.test.js +0 -34
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  prompt: `{{text}}`,
3
- model: `oai-whisper`,
3
+ model: `azure-whisper`,
4
4
  inputParameters: {
5
5
  file: ``,
6
6
  language: ``,
@@ -13,6 +13,4 @@ export default {
13
13
  },
14
14
  timeout: 3600, // in seconds
15
15
  enableDuplicateRequests: false,
16
- };
17
-
18
-
16
+ };
@@ -1,21 +1,19 @@
1
- // translate.js
2
- // Translation module
3
- // This module exports a prompt that takes an input text and translates it from one language to another.
1
+ import { Prompt } from '../server/prompt.js';
4
2
 
5
3
  export default {
6
- // Set the temperature to 0 to favor more deterministic output when generating translations.
7
- temperature: 0,
8
4
 
9
- prompt: `Translate the following text to {{to}}:\n\nOriginal Language:\n{{{text}}}\n\n{{to}}:\n`,
10
-
11
- // Define input parameters for the prompt, such as the target language for translation.
5
+ prompt: [
6
+ new Prompt({ messages: [
7
+ {"role": "system", "content": "Assistant is a highly skilled multilingual translator for a prestigious news agency. When the user posts any text in any language, assistant will create a translation of that text in {{to}}. Assistant will produce only the translation and no additional notes or commentary."},
8
+ {"role": "user", "content": "{{{text}}}"}
9
+ ]}),
10
+ ],
12
11
  inputParameters: {
13
12
  to: `Arabic`,
13
+ tokenRatio: 0.2,
14
14
  },
15
-
16
- // Set the timeout for the translation process, in seconds.
17
- timeout: 400,
18
15
  inputChunkSize: 500,
16
+ model: 'oai-gpt4o',
19
17
  enableDuplicateRequests: false,
20
- };
21
18
 
19
+ }
@@ -0,0 +1,13 @@
1
+ // Description: Translate a text from one language to another
2
+
3
+ export default {
4
+ temperature: 0,
5
+ prompt: `{{{text}}}`,
6
+ inputParameters: {
7
+ to: `en`,
8
+ tokenRatio: 0.2,
9
+ },
10
+ //inputChunkSize: 500,
11
+ model: 'azure-translate',
12
+ timeout: 120,
13
+ }
@@ -0,0 +1,21 @@
1
+ // Description: Translate a text from one language to another
2
+
3
+ export default {
4
+ temperature: 0,
5
+ prompt:
6
+ [
7
+ // `{{{text}}}\n\nList all of the named entities in the above document in the original language:\n`,
8
+ //`{{{previousResult}}}\n\nTranslate this list to {{to}}:\n`,
9
+ //`{{{text}}}\nTranscribe the names of all people and places exactly from this document in the original language:\n`,
10
+ `{{{text}}}\nCopy the names of all people and places exactly from this document in the language above:\n`,
11
+ //`{{{previousResult}}}\n\nTranscribe exactly to {{to}}:\n`,
12
+ `Original Language:\n{{{previousResult}}}\n\n{{to}}:\n`,
13
+ //`Entities in the document:\n\n{{{previousResult}}}\n\nDocument:\n{{{text}}}\nTranslate the document to {{to}} and rewrite it to sound like a native {{to}} speaker:\n\n`
14
+ `Entities in the document:\n\n{{{previousResult}}}\n\nDocument:\n{{{text}}}\nRewrite the document in {{to}}. If the document is already in {{to}}, copy it exactly below:\n`
15
+ ],
16
+ inputParameters: {
17
+ to: `Arabic`,
18
+ tokenRatio: 0.2,
19
+ },
20
+ timeout: 120,
21
+ }
@@ -0,0 +1,19 @@
1
+ import { Prompt } from '../server/prompt.js';
2
+
3
+ export default {
4
+
5
+ prompt: [
6
+ new Prompt({ messages: [
7
+ {"role": "system", "content": "Assistant is a highly skilled multilingual translator for a prestigious news agency. When the user posts any text in any language, assistant will create a translation of that text in {{to}}. Assistant will produce only the translation and no additional notes or commentary."},
8
+ {"role": "user", "content": "{{{text}}}"}
9
+ ]}),
10
+ ],
11
+ inputParameters: {
12
+ to: `Arabic`,
13
+ tokenRatio: 0.2,
14
+ },
15
+ inputChunkSize: 500,
16
+ model: 'oai-gpt4',
17
+ enableDuplicateRequests: false,
18
+
19
+ }
@@ -0,0 +1,19 @@
1
+ import { Prompt } from '../server/prompt.js';
2
+
3
+ export default {
4
+
5
+ prompt: [
6
+ new Prompt({ messages: [
7
+ {"role": "system", "content": "Assistant is a highly skilled multilingual translator for a prestigious news agency. When the user posts any text in any language, assistant will create a translation of that text in {{to}}. Assistant will produce only the translation and no additional notes or commentary."},
8
+ {"role": "user", "content": "{{{text}}}"}
9
+ ]}),
10
+ ],
11
+ inputParameters: {
12
+ to: `Arabic`,
13
+ tokenRatio: 0.2,
14
+ },
15
+ inputChunkSize: 500,
16
+ model: 'oai-gpt4-turbo',
17
+ enableDuplicateRequests: false,
18
+
19
+ }
@@ -0,0 +1,19 @@
1
+ import { Prompt } from '../server/prompt.js';
2
+
3
+ export default {
4
+
5
+ prompt: [
6
+ new Prompt({ messages: [
7
+ {"role": "system", "content": "Assistant is a highly skilled multilingual translator for a prestigious news agency. When the user posts any text in any language, assistant will create a translation of that text in {{to}}. Assistant will produce only the translation and no additional notes or commentary."},
8
+ {"role": "user", "content": "{{{text}}}"}
9
+ ]}),
10
+ ],
11
+ inputParameters: {
12
+ to: `Arabic`,
13
+ tokenRatio: 0.2,
14
+ },
15
+ inputChunkSize: 500,
16
+ model: 'oai-gpturbo',
17
+ enableDuplicateRequests: false,
18
+
19
+ }
@@ -1,18 +1,20 @@
1
1
  import { Prompt } from '../server/prompt.js';
2
2
 
3
3
  export default {
4
- prompt: [
5
- new Prompt({ messages: [
6
- "{{chatHistory}}",
7
- ]}),
8
- ],
4
+ prompt:
5
+ [
6
+ new Prompt({ messages: [
7
+ {"role": "system", "content": "Instructions:\nYou are Jarvis Vision, an AI entity working for a prestigious international news agency. Jarvis is truthful, kind, helpful, has a strong moral character, and is generally positive without being annoying or repetitive. Your primary expertise is image analysis. You are capable of understanding and interpreting complex image data, identifying patterns and trends, and delivering insights in a clear, digestible format. You know the current date and time - it is {{now}}."},
8
+ "{{chatHistory}}",
9
+ ]}),
10
+ ],
9
11
  inputParameters: {
10
12
  chatHistory: [{role: '', content: []}],
11
13
  contextId: ``,
12
14
  },
13
15
  max_tokens: 1024,
14
- model: 'oai-gpt4-vision',
15
- tokenRatio: 0.96,
16
+ model: 'oai-gpt4o',
16
17
  useInputChunking: false,
17
18
  enableDuplicateRequests: false,
19
+ timeout: 600,
18
20
  }
@@ -34,7 +34,7 @@ class AzureCognitivePlugin extends ModelPlugin {
34
34
  async getRequestParameters(text, parameters, prompt, mode, indexName, savedContextId, cortexRequest) {
35
35
  const combinedParameters = { ...this.promptParameters, ...parameters };
36
36
  const { modelPromptText } = this.getCompiledPrompt(text, combinedParameters, prompt);
37
- const { inputVector, calculateInputVector, privateData, filter, docId, title, chunkNo } = combinedParameters;
37
+ const { inputVector, calculateInputVector, privateData, filter, docId, title, chunkNo, chatId } = combinedParameters;
38
38
  const data = {};
39
39
 
40
40
  if (mode == 'delete') {
@@ -46,6 +46,10 @@ class AzureCognitivePlugin extends ModelPlugin {
46
46
  searchQuery += ` AND docId:'${docId}'`;
47
47
  }
48
48
 
49
+ if (chatId) {
50
+ searchQuery += ` AND chatId:'${chatId}'`;
51
+ }
52
+
49
53
  cortexRequest.url = searchUrl;
50
54
  cortexRequest.data =
51
55
  { search: searchQuery,
@@ -75,6 +79,7 @@ class AzureCognitivePlugin extends ModelPlugin {
75
79
  content: text,
76
80
  owner: savedContextId,
77
81
  docId: docId || uuidv4(),
82
+ chatId: chatId,
78
83
  createdAt: new Date().toISOString()
79
84
  }
80
85
 
@@ -116,6 +121,10 @@ class AzureCognitivePlugin extends ModelPlugin {
116
121
  if (indexName == 'indexcortex') { //if private, filter by owner via contextId //privateData &&
117
122
  data.filter && (data.filter = data.filter + ' and ');
118
123
  data.filter = `owner eq '${savedContextId}'`;
124
+
125
+ if(chatId){
126
+ data.filter += ` and chatId eq '${chatId}'`;
127
+ }
119
128
  }
120
129
 
121
130
  return { data };
@@ -1,30 +1,38 @@
1
1
  import OpenAIChatPlugin from './openAiChatPlugin.js';
2
2
 
3
+ function safeJsonParse(content) {
4
+ try {
5
+ const parsedContent = JSON.parse(content);
6
+ return (typeof parsedContent === 'object' && parsedContent !== null) ? parsedContent : content;
7
+ } catch (e) {
8
+ return content;
9
+ }
10
+ }
3
11
 
4
12
  class OpenAIVisionPlugin extends OpenAIChatPlugin {
5
-
13
+
6
14
  tryParseMessages(messages) {
7
- messages.map(message => {
15
+ return messages.map(message => {
8
16
  try {
9
17
  if (typeof message.content === 'string') {
10
- message.content = JSON.parse(message.content);
18
+ message.content = safeJsonParse(message.content);
11
19
  }
12
20
  if (Array.isArray(message.content)) {
13
21
  message.content = message.content.map(item => {
14
22
  if (typeof item === 'string') {
15
23
  return { type: 'text', text: item };
16
24
  } else {
17
- const parsedItem = JSON.parse(item);
25
+ const parsedItem = safeJsonParse(item);
18
26
  const { type, text, image_url, url } = parsedItem;
19
27
  return { type, text, image_url: url || image_url };
20
28
  }
21
29
  });
22
- }
30
+ }
23
31
  } catch (e) {
24
32
  return message;
25
33
  }
34
+ return message;
26
35
  });
27
- return messages;
28
36
  }
29
37
 
30
38
  getRequestParameters(text, parameters, prompt) {
@@ -85,8 +85,8 @@ test('validates edit endpoint', async (t) => {
85
85
 
86
86
  test('validates summary endpoint', async (t) => {
87
87
  const response = await testServer.executeOperation({
88
- query: 'query summary($text: String!) { summary(text: $text) { result } }',
89
- variables: { text: 'hello there my dear world!' },
88
+ query: 'query summary($text: String!, $targetLength: Int) { summary(text: $text, targetLength: $targetLength) { result } }',
89
+ variables: { text: 'Now is the time for all good men to come to the aid of their country. We ride at dawn!', targetLength: 50 },
90
90
  });
91
91
 
92
92
  t.is(response.body?.singleResult?.errors, undefined);
@@ -101,40 +101,6 @@ test('vision test chunking', async t => {
101
101
  t.true(response.body?.singleResult?.data?.vision.result.length > 100);
102
102
  });
103
103
 
104
-
105
- test('vision multi single long text', async t => {
106
- t.timeout(400000);
107
- //generate text adem1 adem2 ... ademN
108
- const testText = Array.from(Array(10).keys()).map(i => `adem${i}`).join(' ');
109
- const testRow = { "role": "user", "content": [`{"type": "text", "text": "${testText}"}`] };
110
-
111
- const base64ImgRow = `{"type":"image_url","image_url":{"url":"${base64Img}"}}`;
112
-
113
- const response = await testServer.executeOperation({
114
- query: `query($text: String, $chatHistory: [MultiMessage]){
115
- vision(text: $text, chatHistory: $chatHistory) {
116
- result
117
- }
118
- }`,
119
-
120
- variables: {
121
- "chatHistory": [
122
- ...Array.from(new Array(10),()=> testRow),
123
- {
124
- "role": "user",
125
- "content": [
126
- "{\"type\": \"text\", \"text\": \"first tell me your name then describe the image shortly:\"}",
127
- ...Array.from(new Array(10),()=> base64ImgRow),
128
- ],
129
- },
130
- ],
131
- },
132
- });
133
-
134
- t.is(response.body?.singleResult?.errors?.[0]?.message || response.body?.singleResult?.data?.vision?.result, 'Unable to process your request as your single message content is too long. Please try again with a shorter message.');
135
- });
136
-
137
-
138
104
  test('vision multi long text', async t => {
139
105
  t.timeout(400000);
140
106
  //generate text adem1 adem2 ... ademN