@aj-archipelago/cortex 0.0.5 → 0.0.7

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/pathways/edit.js CHANGED
@@ -1,4 +1,10 @@
1
+ // edit.js
2
+ // Grammar and spelling correction module
3
+ // This module exports a prompt that takes an input text and corrects all spelling and grammar errors found within the text.
4
+
1
5
  module.exports = {
6
+ // Set the temperature to 0 to favor more deterministic output when generating corrections.
2
7
  temperature: 0,
8
+
3
9
  prompt: `Correct all spelling and grammar errors in the input text.\n\nInput:\n{{text}}\n\nOutput:\n`
4
10
  }
@@ -1,9 +1,21 @@
1
+ // entities.js
2
+ // Entity extraction module
3
+ // This module exports a prompt that takes an input text and extracts the top entities and their definitions as specified by the count parameter.
4
+
1
5
  module.exports = {
6
+ // Set the temperature to 0 to favor more deterministic output when generating entity extraction.
2
7
  temperature: 0,
8
+
3
9
  prompt: `{{text}}\n\nList the top {{count}} entities and their definitions for the above in the format {{format}}:`,
10
+
11
+ // Define the format for displaying the extracted entities and their definitions.
4
12
  format: `(name: definition)`,
13
+
14
+ // Define input parameters for the prompt, such as the number of entities to extract.
5
15
  inputParameters: {
6
16
  count: 5,
7
17
  },
18
+
19
+ // Set the list option to true as the prompt is expected to return a list of entities.
8
20
  list: true,
9
21
  }
package/pathways/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = {
7
7
  "paraphrase": require('./paraphrase'),
8
8
  "sentiment": require('./sentiment'),
9
9
  "summary": require('./summary'),
10
- "topics": require('./topics'),
10
+ "transcribe": require('./transcribe'),
11
11
  "translate": require('./translate'),
12
12
  }
@@ -1,3 +1,7 @@
1
+ // paraphrase.js
2
+ // Paraphrasing module
3
+ // This module exports a prompt that takes an input text and rewrites it in a different way while maintaining the original meaning.
4
+
1
5
  module.exports = {
2
6
  prompt: `Rewrite the following:\n\n{{{text}}}`
3
7
  }
@@ -1,3 +1,7 @@
1
+ // sentiment.js
2
+ // Sentiment detection module
3
+ // This module exports a prompt that takes an input text and asks how it makes the AI feel.
4
+
1
5
  module.exports = {
2
- prompt: `How does this article make you feel?\n\n{{text}}`,
6
+ prompt: `How does the text below make you feel?\n\n{{text}}`,
3
7
  }
@@ -1,43 +1,60 @@
1
+ // summary.js
2
+ // Text summarization module with custom resolver
3
+ // This module exports a prompt that takes an input text and generates a summary using a custom resolver.
4
+
5
+ // Import required modules
1
6
  const { semanticTruncate } = require('../graphql/chunker');
2
7
  const { PathwayResolver } = require('../graphql/pathwayResolver');
3
8
 
4
9
  module.exports = {
10
+ // The main prompt function that takes the input text and asks to generate a summary.
5
11
  prompt: `{{{text}}}\n\nWrite a summary of the above text:\n\n`,
6
12
 
13
+ // Define input parameters for the prompt, such as the target length of the summary.
7
14
  inputParameters: {
8
- targetLength: 500,
15
+ targetLength: 0,
9
16
  },
17
+
18
+ // Custom resolver to generate summaries by reprompting if they are too long or too short.
10
19
  resolver: async (parent, args, contextValue, info) => {
11
20
  const { config, pathway, requestState } = contextValue;
12
21
  const originalTargetLength = args.targetLength;
22
+
23
+ // If targetLength is not provided, execute the prompt once and return the result.
24
+ if (originalTargetLength === 0) {
25
+ let pathwayResolver = new PathwayResolver({ config, pathway, args, requestState });
26
+ return await pathwayResolver.resolve(args);
27
+ }
28
+
13
29
  const errorMargin = 0.2;
14
30
  const lowTargetLength = originalTargetLength * (1 - errorMargin);
15
31
  const targetWords = Math.round(originalTargetLength / 6.6);
16
32
 
17
- // if the text is shorter than the summary length, just return the text
33
+ // If the text is shorter than the summary length, just return the text.
18
34
  if (args.text.length <= originalTargetLength) {
19
35
  return args.text;
20
36
  }
21
37
 
22
38
  const MAX_ITERATIONS = 5;
23
39
  let summary = '';
24
- let bestSummary = '';
25
- let pathwayResolver = new PathwayResolver({ config, pathway, requestState });
26
- // modify the prompt to be words-based instead of characters-based
40
+ let pathwayResolver = new PathwayResolver({ config, pathway, args, requestState });
41
+
42
+
43
+ // Modify the prompt to be words-based instead of characters-based.
27
44
  pathwayResolver.pathwayPrompt = `{{{text}}}\n\nWrite a summary of the above text in exactly ${targetWords} words:\n\n`
28
45
 
29
46
  let i = 0;
30
- // reprompt if summary is too long or too short
47
+ // Reprompt if summary is too long or too short.
31
48
  while (((summary.length > originalTargetLength) || (summary.length < lowTargetLength)) && i < MAX_ITERATIONS) {
32
49
  summary = await pathwayResolver.resolve(args);
33
50
  i++;
34
51
  }
35
52
 
36
- // if the summary is still too long, truncate it
53
+ // If the summary is still too long, truncate it.
37
54
  if (summary.length > originalTargetLength) {
38
55
  return semanticTruncate(summary, originalTargetLength);
39
56
  } else {
40
57
  return summary;
41
58
  }
42
59
  }
43
- }
60
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ prompt: `{{text}}`,
3
+ model: `oai-whisper`,
4
+ inputParameters: {
5
+ file: ``,
6
+ },
7
+ timeout: 600, // in seconds
8
+ }
@@ -1,9 +1,18 @@
1
- // Description: Translate a text from one language to another
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.
2
4
 
3
5
  module.exports = {
6
+ // Set the temperature to 0 to favor more deterministic output when generating translations.
4
7
  temperature: 0,
8
+
5
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.
6
12
  inputParameters: {
7
13
  to: `Arabic`,
8
14
  },
15
+
16
+ // Set the timeout for the translation process, in seconds.
17
+ timeout: 300,
9
18
  }
@@ -4,6 +4,11 @@ jest.setTimeout(1800000);
4
4
 
5
5
  const testServer = getTestServer();
6
6
 
7
+ //stop server after all tests
8
+ afterAll(async () => {
9
+ await testServer.stop();
10
+ });
11
+
7
12
  it('chunking test of translate endpoint with huge text', async () => {
8
13
  const response = await testServer.executeOperation({
9
14
  query: 'query translate($text: String!) { translate(text: $text) { result } }',
@@ -14,6 +14,11 @@ const getTestServer = () => {
14
14
 
15
15
  const testServer = getTestServer();
16
16
 
17
+ //stop server after all tests
18
+ afterAll(async () => {
19
+ await testServer.stop();
20
+ });
21
+
17
22
  it('validates bias endpoint', async () => {
18
23
  const response = await testServer.executeOperation({
19
24
  query: 'query bias($text: String!) { bias(text: $text) { result } }',
@@ -88,19 +93,6 @@ it('validates summary endpoint', async () => {
88
93
  expect(response.data?.summary.result).toBeDefined();
89
94
  });
90
95
 
91
- it('validates topics endpoint with given num of count return', async () => {
92
- const response = await testServer.executeOperation({
93
- query: 'query topics($text: String!, $count: Int) { topics(text: $text, count: $count) { result } }',
94
- variables: { text: 'hello there my dear world!', count: 3 },
95
- });
96
-
97
- expect(response.errors).toBeUndefined();
98
- expect(response.data?.topics.result.length).toBe(3);
99
- response.data?.topics.result.forEach((topic) => {
100
- expect(topic).toBeDefined();
101
- });
102
- });
103
-
104
96
  module.exports = {
105
97
  getTestServer,
106
98
  };
@@ -4,6 +4,11 @@ jest.setTimeout(1800000);
4
4
 
5
5
  const testServer = getTestServer();
6
6
 
7
+ //stop server after all tests
8
+ afterAll(async () => {
9
+ await testServer.stop();
10
+ });
11
+
7
12
  it('test translate endpoint with huge arabic text english translation and check return non-arabic/english', async () => {
8
13
  const response = await testServer.executeOperation({
9
14
  query: 'query translate($text: String!, $to:String) { translate(text: $text, to:$to) { result } }',
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- prompt: [`{{text}}\n\nList the top {{count}} news categories for the above article (e.g. 1. Finance):`,
3
- `{{previousResult}}\n\nPick the {{count}} most important news categories from the above:`
4
- ],
5
- inputParameters: {
6
- count: 5,
7
- },
8
- list: true,
9
- }