multi oai config support, timeout fix, execute_js_rich optimization
This commit is contained in:
@@ -223,8 +223,9 @@ class TMWebDriver:
|
||||
if hasjump and session.is_active():
|
||||
if not self.is_remote and auto_switch_newtab: self.last_cmd_time = time.time()
|
||||
return {"result": f"Session {session_id} reloaded.", "closed":1}
|
||||
if time.time() - start_time > timeout + 10:
|
||||
if time.time() - start_time > timeout:
|
||||
if tp == 'ws':
|
||||
if hasjump: return {"result": f"Session {session_id} reloaded and new page is loading...", "closed":1}
|
||||
return {"result": f"No response data in {timeout}s"}
|
||||
elif tp == 'http':
|
||||
return {"result": f"Session {session_id} no response."}
|
||||
|
||||
@@ -28,11 +28,12 @@ def get_system_prompt():
|
||||
class GeneraticAgent:
|
||||
def __init__(self):
|
||||
if not os.path.exists('temp'): os.makedirs('temp')
|
||||
from sidercall import sider_cookie, oai_apikey, oai_apibase
|
||||
from sidercall import sider_cookie, oai_configs
|
||||
llm_sessions = []
|
||||
if sider_cookie: llm_sessions += [SiderLLMSession(default_model=x) for x in \
|
||||
["gemini-3.0-flash", "claude-haiku-4.5", "kimi-k2"]]
|
||||
if oai_apikey: llm_sessions += [LLMSession(api_key=oai_apikey, api_base=oai_apibase)]
|
||||
for cfg in oai_configs.values():
|
||||
llm_sessions += [LLMSession(api_key=cfg['apikey'], api_base=cfg['apibase'], model=cfg['model'])]
|
||||
if len(llm_sessions) > 0:
|
||||
llmclient = ToolClient(llm_sessions, auto_save_tokens=True)
|
||||
self.llmclient = llmclient
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
|
||||
oai_apikey = 'sk-uklUR...'
|
||||
oai_apibase = "http://113.345.339.347:3001/v1"
|
||||
oai_model = "openai/gpt-5.1"
|
||||
oai_config = {
|
||||
'apikey':'sk-uklURcj',
|
||||
'apibase':"http://113.145.139.147:3001/v1",
|
||||
'model':"openai/gpt-5.1"
|
||||
}
|
||||
|
||||
# or
|
||||
|
||||
sider_cookie = 'token=Bearer%20eyJhbGciOiJIUz...'
|
||||
|
||||
# feel free to add more ~
|
||||
oai_config2 = {
|
||||
'apikey':'sk-uklURcj...',
|
||||
'apibase':"http://133.145.139.147:3001/v1",
|
||||
'model':"claude-opus-4-6-20260206"
|
||||
}
|
||||
|
||||
30
sidercall.py
30
sidercall.py
@@ -3,14 +3,14 @@ import os, json, re, time, requests, sys, threading
|
||||
try: import mykey
|
||||
except: raise Exception('[ERROR] mykey.py not found, please copy mykey_template.py to mykey.py and fill your LLM backend.')
|
||||
|
||||
def get_config(name, default=""): return getattr(mykey, name, default)
|
||||
mykeys = vars(mykey)
|
||||
sider_cookie = mykeys.get("sider_cookie")
|
||||
oai_configs = {
|
||||
k: v for k, v in vars(mykey).items() if k.startswith("oai_config") and v
|
||||
}
|
||||
google_api_key = mykeys.get("google_api_key")
|
||||
|
||||
sider_cookie = get_config("sider_cookie")
|
||||
oai_apikey = get_config("oai_apikey")
|
||||
oai_apibase = get_config("oai_apibase")
|
||||
oai_model = get_config("oai_model")
|
||||
google_api_key = get_config("google_api_key")
|
||||
proxy = get_config("proxy", 'http://127.0.0.1:2082')
|
||||
proxy = mykeys.get("proxy", 'http://127.0.0.1:2082')
|
||||
proxies = {"http": proxy, "https": proxy} if proxy else None
|
||||
|
||||
class SiderLLMSession:
|
||||
@@ -56,7 +56,7 @@ class GeminiSession:
|
||||
return iter([full_text]) if stream else full_text
|
||||
|
||||
class LLMSession:
|
||||
def __init__(self, api_key=oai_apikey, api_base=oai_apibase, model=oai_model, context_win=16000):
|
||||
def __init__(self, api_key, api_base, model, context_win=16000):
|
||||
self.api_key = api_key
|
||||
self.api_base = api_base
|
||||
self.raw_msgs = []
|
||||
@@ -297,14 +297,16 @@ if __name__ == "__main__":
|
||||
class MockMyKey: pass
|
||||
mykey = MockMyKey()
|
||||
|
||||
sider_cookie = get_config("sider_cookie")
|
||||
oai_apikey = get_config("oai_apikey")
|
||||
oai_apibase = get_config("oai_apibase")
|
||||
oai_model = get_config("oai_model")
|
||||
google_api_key = get_config("google_api_key")
|
||||
mykeys = vars(mykey)
|
||||
sider_cookie = mykeys.get("sider_cookie")
|
||||
oai_configs = {
|
||||
k: v for k, v in vars(mykey).items() if k.startswith("oai_config") and v
|
||||
}
|
||||
google_api_key = mykeys.get("google_api_key")
|
||||
cfg = oai_configs.get("oai_config")
|
||||
|
||||
llmclient = ToolClient(GeminiSession(api_key=google_api_key, proxy='127.0.0.1:2082').ask)
|
||||
#llmclient = ToolClient(LLMSession(api_key=oai_apikey, api_base=oai_apibase, model=oai_model).ask)
|
||||
#llmclient = ToolClient(LLMSession(api_key=cfg['apikey'], api_base=cfg['apibase'], model=cfg['model']).ask)
|
||||
#llmclient = ToolClient(SiderLLMSession().ask)
|
||||
def get_final(gen):
|
||||
try:
|
||||
|
||||
47
simphtml.py
47
simphtml.py
@@ -83,7 +83,9 @@ function analyzeNode(node, pPathType='main') {
|
||||
return;
|
||||
}
|
||||
const pathType = (node.dataset.mark && !node.dataset.mark.includes(':main')) ? 'second' : pPathType;
|
||||
const rectn = getNodeInfo(node).rect;
|
||||
const nodeInfoData = getNodeInfo(node);
|
||||
if (!nodeInfoData || !nodeInfoData.rect) return;
|
||||
const rectn = nodeInfoData.rect;
|
||||
if (rectn.width < window.innerWidth * 0.8 && rectn.height < window.innerHeight * 0.8) return node;
|
||||
if (node.tagName === 'TABLE') return;
|
||||
const children = Array.from(node.children);
|
||||
@@ -901,33 +903,34 @@ def execute_js_rich(script, driver):
|
||||
error_msg = str(error)
|
||||
print(f"❌ Error: {error_msg}")
|
||||
|
||||
transients = get_temp_texts(driver)
|
||||
|
||||
if driver.default_session_id != curr_session:
|
||||
curr_session = driver.latest_session_id
|
||||
print('Session changed')
|
||||
new_tab = True
|
||||
|
||||
current_html = get_html(driver)
|
||||
diff_summary = "无需对比 (报错)"
|
||||
is_significant_change = False
|
||||
if not error_msg:
|
||||
diff_data = find_changed_elements(last_html, current_html)
|
||||
change_count = diff_data.get('changed', 0)
|
||||
diff_summary = f"DOM变化量: {change_count}"
|
||||
if change_count < 5 and not transients and not new_tab:
|
||||
diff_summary += " (页面几乎无静默变化)"
|
||||
else:
|
||||
is_significant_change = True
|
||||
return {
|
||||
rr = {
|
||||
"status": "failed" if error_msg else "success",
|
||||
"js_return": result,
|
||||
"error": error_msg,
|
||||
"transients": transients,
|
||||
"environment": {
|
||||
"new_tab": new_tab,
|
||||
"reloaded": reloaded
|
||||
},
|
||||
"diff": diff_summary,
|
||||
"suggestion": "" if is_significant_change else "页面无明显变化"
|
||||
}
|
||||
}
|
||||
}
|
||||
if error_msg: rr['error'] = error_msg
|
||||
if not reloaded:
|
||||
transients = get_temp_texts(driver)
|
||||
rr['transients'] = transients
|
||||
if not reloaded and not new_tab:
|
||||
current_html = get_html(driver)
|
||||
diff_summary = "无需对比 (报错)"
|
||||
is_significant_change = False
|
||||
if not error_msg:
|
||||
diff_data = find_changed_elements(last_html, current_html)
|
||||
change_count = diff_data.get('changed', 0)
|
||||
diff_summary = f"DOM变化量: {change_count}"
|
||||
if change_count < 5 and not transients and not new_tab:
|
||||
diff_summary += " (页面几乎无静默变化)"
|
||||
else:
|
||||
is_significant_change = True
|
||||
rr['diff'] = diff_summary
|
||||
rr['suggestion'] = "" if is_significant_change else "页面无明显变化"
|
||||
return rr
|
||||
|
||||
Reference in New Issue
Block a user