Skip to content

Commit fe2443b

Browse files
committed
SimpleChatTC:WebTools And Search - headers and search drops - js
Allow the web tools handshake helper to pass additional header entries provided by its caller. Make use of this to send a list of tag and id pairs wrt web search tool. Which will be used to drop div's matching the specified id.
1 parent 8e2c376 commit fe2443b

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

tools/server/public_simplechat/simplechat.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,19 @@ class MultiChatUI {
12901290
* The SEARCHWORDS keyword will get replaced by the actual user specified search words at runtime.
12911291
*/
12921292
const SearchURLS = {
1293-
duckduckgo: "https://duckduckgo.com/html/?q=SEARCHWORDS",
1294-
bing: "https://www.bing.com/search?q=SEARCHWORDS", // doesnt seem to like google chrome clients in particular
1295-
brave: "https://search.brave.com/search?q=SEARCHWORDS",
1296-
google: "https://www.google.com/search?q=SEARCHWORDS", // doesnt seem to like any client in general
1293+
duckduckgo: {
1294+
'template': "https://duckduckgo.com/html/?q=SEARCHWORDS",
1295+
'drop': [ { 'tag': 'div', 'id': "header" } ]
1296+
},
1297+
bing: {
1298+
'template': "https://www.bing.com/search?q=SEARCHWORDS", // doesnt seem to like google chrome clients in particular
1299+
},
1300+
brave: {
1301+
'template': "https://search.brave.com/search?q=SEARCHWORDS",
1302+
},
1303+
google: {
1304+
'template': "https://www.google.com/search?q=SEARCHWORDS", // doesnt seem to like any client in general
1305+
},
12971306
}
12981307

12991308

@@ -1307,7 +1316,8 @@ class Me {
13071316
enabled: true,
13081317
proxyUrl: "http://127.0.0.1:3128",
13091318
proxyAuthInsecure: "NeverSecure",
1310-
searchUrl: SearchURLS.duckduckgo,
1319+
searchUrl: SearchURLS.duckduckgo.template,
1320+
searchDrops: SearchURLS.duckduckgo.drop,
13111321
toolNames: /** @type {Array<string>} */([]),
13121322
/**
13131323
* Control the length of the tool call result data returned to ai after tool call.

tools/server/public_simplechat/toolweb.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ function bearer_transform() {
4949
* @param {string} chatid
5050
* @param {string} toolcallid
5151
* @param {string} toolname
52-
* @param {any} obj
52+
* @param {any} objSearchParams
5353
* @param {string} path
54+
* @param {any} objHeaders
5455
*/
55-
async function proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, path) {
56+
async function proxyserver_get_anyargs(chatid, toolcallid, toolname, objSearchParams, path, objHeaders={}) {
5657
if (gToolsWorker.onmessage != null) {
57-
let params = new URLSearchParams(obj)
58+
let params = new URLSearchParams(objSearchParams)
5859
let newUrl = `${get_gme().tools.proxyUrl}/${path}?${params}`
60+
let headers = new Headers(objHeaders)
5961
let btoken = await bearer_transform()
60-
fetch(newUrl, { headers: { 'Authorization': `Bearer ${btoken}` }}).then(resp => {
62+
headers.append('Authorization', `Bearer ${btoken}`)
63+
fetch(newUrl, { headers: headers}).then(resp => {
6164
if (!resp.ok) {
6265
throw new Error(`${resp.status}:${resp.statusText}`);
6366
}
@@ -256,7 +259,8 @@ function searchwebtext_run(chatid, toolcallid, toolname, obj) {
256259
searchUrl = searchUrl.replace("SEARCHWORDS", encodeURIComponent(obj.words));
257260
delete(obj.words)
258261
obj['url'] = searchUrl
259-
return proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, 'urltext');
262+
let headers = { 'Search-Drops': get_gme().tools.searchDrops }
263+
return proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, 'urltext', headers);
260264
}
261265
}
262266

0 commit comments

Comments
 (0)