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.
This commit is contained in:
parent
7fce3eeb2a
commit
f75bdb0e00
|
|
@ -1290,10 +1290,19 @@ class MultiChatUI {
|
||||||
* The SEARCHWORDS keyword will get replaced by the actual user specified search words at runtime.
|
* The SEARCHWORDS keyword will get replaced by the actual user specified search words at runtime.
|
||||||
*/
|
*/
|
||||||
const SearchURLS = {
|
const SearchURLS = {
|
||||||
duckduckgo: "https://duckduckgo.com/html/?q=SEARCHWORDS",
|
duckduckgo: {
|
||||||
bing: "https://www.bing.com/search?q=SEARCHWORDS", // doesnt seem to like google chrome clients in particular
|
'template': "https://duckduckgo.com/html/?q=SEARCHWORDS",
|
||||||
brave: "https://search.brave.com/search?q=SEARCHWORDS",
|
'drop': [ { 'tag': 'div', 'id': "header" } ]
|
||||||
google: "https://www.google.com/search?q=SEARCHWORDS", // doesnt seem to like any client in general
|
},
|
||||||
|
bing: {
|
||||||
|
'template': "https://www.bing.com/search?q=SEARCHWORDS", // doesnt seem to like google chrome clients in particular
|
||||||
|
},
|
||||||
|
brave: {
|
||||||
|
'template': "https://search.brave.com/search?q=SEARCHWORDS",
|
||||||
|
},
|
||||||
|
google: {
|
||||||
|
'template': "https://www.google.com/search?q=SEARCHWORDS", // doesnt seem to like any client in general
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1307,7 +1316,8 @@ class Me {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
proxyUrl: "http://127.0.0.1:3128",
|
proxyUrl: "http://127.0.0.1:3128",
|
||||||
proxyAuthInsecure: "NeverSecure",
|
proxyAuthInsecure: "NeverSecure",
|
||||||
searchUrl: SearchURLS.duckduckgo,
|
searchUrl: SearchURLS.duckduckgo.template,
|
||||||
|
searchDrops: SearchURLS.duckduckgo.drop,
|
||||||
toolNames: /** @type {Array<string>} */([]),
|
toolNames: /** @type {Array<string>} */([]),
|
||||||
/**
|
/**
|
||||||
* Control the length of the tool call result data returned to ai after tool call.
|
* Control the length of the tool call result data returned to ai after tool call.
|
||||||
|
|
|
||||||
|
|
@ -49,15 +49,18 @@ function bearer_transform() {
|
||||||
* @param {string} chatid
|
* @param {string} chatid
|
||||||
* @param {string} toolcallid
|
* @param {string} toolcallid
|
||||||
* @param {string} toolname
|
* @param {string} toolname
|
||||||
* @param {any} obj
|
* @param {any} objSearchParams
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
|
* @param {any} objHeaders
|
||||||
*/
|
*/
|
||||||
async function proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, path) {
|
async function proxyserver_get_anyargs(chatid, toolcallid, toolname, objSearchParams, path, objHeaders={}) {
|
||||||
if (gToolsWorker.onmessage != null) {
|
if (gToolsWorker.onmessage != null) {
|
||||||
let params = new URLSearchParams(obj)
|
let params = new URLSearchParams(objSearchParams)
|
||||||
let newUrl = `${get_gme().tools.proxyUrl}/${path}?${params}`
|
let newUrl = `${get_gme().tools.proxyUrl}/${path}?${params}`
|
||||||
|
let headers = new Headers(objHeaders)
|
||||||
let btoken = await bearer_transform()
|
let btoken = await bearer_transform()
|
||||||
fetch(newUrl, { headers: { 'Authorization': `Bearer ${btoken}` }}).then(resp => {
|
headers.append('Authorization', `Bearer ${btoken}`)
|
||||||
|
fetch(newUrl, { headers: headers}).then(resp => {
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
throw new Error(`${resp.status}:${resp.statusText}`);
|
throw new Error(`${resp.status}:${resp.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +259,8 @@ function searchwebtext_run(chatid, toolcallid, toolname, obj) {
|
||||||
searchUrl = searchUrl.replace("SEARCHWORDS", encodeURIComponent(obj.words));
|
searchUrl = searchUrl.replace("SEARCHWORDS", encodeURIComponent(obj.words));
|
||||||
delete(obj.words)
|
delete(obj.words)
|
||||||
obj['url'] = searchUrl
|
obj['url'] = searchUrl
|
||||||
return proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, 'urltext');
|
let headers = { 'Search-Drops': get_gme().tools.searchDrops }
|
||||||
|
return proxyserver_get_anyargs(chatid, toolcallid, toolname, obj, 'urltext', headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue