@aj-archipelago/cortex 1.3.42 → 1.3.43
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/config.js
CHANGED
|
@@ -478,6 +478,11 @@ var config = convict({
|
|
|
478
478
|
default: null,
|
|
479
479
|
env: 'NEURALSPACE_API_KEY'
|
|
480
480
|
},
|
|
481
|
+
browserServiceUrl: {
|
|
482
|
+
format: String,
|
|
483
|
+
default: null,
|
|
484
|
+
env: 'CORTEX_BROWSER_URL'
|
|
485
|
+
}
|
|
481
486
|
});
|
|
482
487
|
|
|
483
488
|
// Read in environment variables and set up service configuration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aj-archipelago/cortex",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.43",
|
|
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": {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// sys_tool_browser.js
|
|
2
|
+
// Tool pathway that handles web page content scraping functionality
|
|
3
|
+
import logger from '../../../../lib/logger.js';
|
|
4
|
+
import { config } from '../../../../config.js';
|
|
5
|
+
import { getSearchResultId } from '../../../../lib/util.js';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
prompt: [],
|
|
9
|
+
timeout: 300,
|
|
10
|
+
toolDefinition: {
|
|
11
|
+
type: "function",
|
|
12
|
+
icon: "🌍",
|
|
13
|
+
function: {
|
|
14
|
+
name: "WebPageContent",
|
|
15
|
+
description: "This tool allows you to fetch and extract the text content from any webpage. Use this when you need to analyze or understand the content of a specific webpage.",
|
|
16
|
+
parameters: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
url: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "The complete URL of the webpage to fetch and analyze"
|
|
22
|
+
},
|
|
23
|
+
userMessage: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "A user-friendly message that describes what you're doing with this tool"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ["url", "userMessage"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
executePathway: async ({args, runAllPrompts, resolver}) => {
|
|
34
|
+
// Check if browser service URL is available
|
|
35
|
+
const browserServiceUrl = config.get('browserServiceUrl');
|
|
36
|
+
if (!browserServiceUrl) {
|
|
37
|
+
throw new Error("Browser service is not available - missing CORTEX_BROWSER_URL configuration");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
// Construct the full URL for the browser service
|
|
42
|
+
const scrapeUrl = `${browserServiceUrl}/api/scrape?url=${encodeURIComponent(args.url)}`;
|
|
43
|
+
|
|
44
|
+
// Call the browser service
|
|
45
|
+
const response = await fetch(scrapeUrl);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(`Browser service returned error: ${response.status} ${response.statusText}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
|
|
52
|
+
// Create a result object with the scraped content
|
|
53
|
+
const result = {
|
|
54
|
+
searchResultId: getSearchResultId(),
|
|
55
|
+
title: "Webpage Content",
|
|
56
|
+
url: data.url,
|
|
57
|
+
content: data.text
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
resolver.tool = JSON.stringify({ toolUsed: "WebPageContent" });
|
|
61
|
+
return JSON.stringify({ _type: "SearchResponse", value: [result] });
|
|
62
|
+
} catch (e) {
|
|
63
|
+
logger.error(`Error in browser tool: ${e}`);
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|