SimpleChatTC:WebFetch: Try confirm simpleproxy before enabling
This commit is contained in:
parent
a6aa563a18
commit
98d43fac7f
|
|
@ -47,6 +47,8 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||||
handle_urlraw(self, pr)
|
handle_urlraw(self, pr)
|
||||||
case '/urltext':
|
case '/urltext':
|
||||||
handle_urltext(self, pr)
|
handle_urltext(self, pr)
|
||||||
|
case '/aum':
|
||||||
|
handle_aum(self, pr)
|
||||||
case _:
|
case _:
|
||||||
print(f"WARN:ProxyHandler:GET:UnknownPath{pr.path}")
|
print(f"WARN:ProxyHandler:GET:UnknownPath{pr.path}")
|
||||||
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
|
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
|
||||||
|
|
@ -58,6 +60,12 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||||
self.send_headers_common()
|
self.send_headers_common()
|
||||||
|
|
||||||
|
|
||||||
|
def handle_aum(ph: ProxyHandler, pr: urllib.parse.ParseResult):
|
||||||
|
ph.send_response_only(200, "bharatavarshe")
|
||||||
|
ph.send_header('Access-Control-Allow-Origin', '*')
|
||||||
|
ph.end_headers()
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class UrlReqResp:
|
class UrlReqResp:
|
||||||
callOk: bool
|
callOk: bool
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@ browser js runtime environment. Depending on the path specified wrt the proxy se
|
||||||
(and not urlraw), it additionally tries to convert html content into equivalent text to some extent
|
(and not urlraw), it additionally tries to convert html content into equivalent text to some extent
|
||||||
in a simple minded manner by dropping head block as well as all scripts/styles/footers/headers/nav.
|
in a simple minded manner by dropping head block as well as all scripts/styles/footers/headers/nav.
|
||||||
May add support for white list of allowed sites to access or so.
|
May add support for white list of allowed sites to access or so.
|
||||||
* the logic does a simple dumb check to see if there is something running at specified proxyUrl
|
* the logic does a simple check to see if the bundled simpleproxy is running at specified proxyUrl
|
||||||
before enabling fetch web related tool calls.
|
before enabling fetch web related tool calls.
|
||||||
* The bundled simple proxy can be found at
|
* The bundled simple proxy can be found at
|
||||||
* tools/server/public_simplechat/local.tools/simpleproxy.py
|
* tools/server/public_simplechat/local.tools/simpleproxy.py
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,18 @@ function fetchweburlraw_run(toolcallid, toolname, obj) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup fetch_web_url_raw for tool calling
|
* Setup fetch_web_url_raw for tool calling
|
||||||
* NOTE: Currently it just checks there is something at given proxyUrl
|
* NOTE: Currently the logic is setup for the bundled simpleproxy.py
|
||||||
* @param {Object<string, Object<string, any>>} tcs
|
* @param {Object<string, Object<string, any>>} tcs
|
||||||
*/
|
*/
|
||||||
async function fetchweburlraw_setup(tcs) {
|
async function fetchweburlraw_setup(tcs) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let got = await fetch(`${document["gMe"].proxyUrl}/urlraw?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{
|
let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.multiverse.987654321123456789`).then(resp=>{
|
||||||
|
if (resp.statusText != 'bharatavarshe') {
|
||||||
|
console.log("WARN:ToolJS:FetchWebUrlRaw:Dont forget to run the bundled local.tools/simpleproxy.py to enable me")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
console.log("INFO:ToolJS:FetchWebUrlRaw:Enabling...")
|
||||||
|
}
|
||||||
tcs["fetch_web_url_raw"] = {
|
tcs["fetch_web_url_raw"] = {
|
||||||
"handler": fetchweburlraw_run,
|
"handler": fetchweburlraw_run,
|
||||||
"meta": fetchweburlraw_meta,
|
"meta": fetchweburlraw_meta,
|
||||||
|
|
@ -201,12 +207,18 @@ function fetchweburltext_run(toolcallid, toolname, obj) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup fetch_web_url_text for tool calling
|
* Setup fetch_web_url_text for tool calling
|
||||||
* NOTE: Currently it just checks there is something at given proxyUrl
|
* NOTE: Currently the logic is setup for the bundled simpleproxy.py
|
||||||
* @param {Object<string, Object<string, any>>} tcs
|
* @param {Object<string, Object<string, any>>} tcs
|
||||||
*/
|
*/
|
||||||
async function fetchweburltext_setup(tcs) {
|
async function fetchweburltext_setup(tcs) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let got = await fetch(`${document["gMe"].proxyUrl}/urltext?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{
|
let got = await fetch(`${document["gMe"].proxyUrl}/aum?url=jambudweepe.akashaganga.multiverse.987654321123456789`).then(resp=>{
|
||||||
|
if (resp.statusText != 'bharatavarshe') {
|
||||||
|
console.log("WARN:ToolJS:FetchWebUrlText:Dont forget to run the bundled local.tools/simpleproxy.py to enable me")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
console.log("INFO:ToolJS:FetchWebUrlText:Enabling...")
|
||||||
|
}
|
||||||
tcs["fetch_web_url_text"] = {
|
tcs["fetch_web_url_text"] = {
|
||||||
"handler": fetchweburltext_run,
|
"handler": fetchweburltext_run,
|
||||||
"meta": fetchweburltext_meta,
|
"meta": fetchweburltext_meta,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue