multi oai config support, timeout fix, execute_js_rich optimization

This commit is contained in:
Liang Jiaqing
2026-02-12 16:56:11 +08:00
parent 1276021422
commit 69153f7a42
5 changed files with 58 additions and 42 deletions

View File

@@ -223,8 +223,9 @@ class TMWebDriver:
if hasjump and session.is_active(): if hasjump and session.is_active():
if not self.is_remote and auto_switch_newtab: self.last_cmd_time = time.time() if not self.is_remote and auto_switch_newtab: self.last_cmd_time = time.time()
return {"result": f"Session {session_id} reloaded.", "closed":1} 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 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"} return {"result": f"No response data in {timeout}s"}
elif tp == 'http': elif tp == 'http':
return {"result": f"Session {session_id} no response."} return {"result": f"Session {session_id} no response."}

View File

@@ -28,11 +28,12 @@ def get_system_prompt():
class GeneraticAgent: class GeneraticAgent:
def __init__(self): def __init__(self):
if not os.path.exists('temp'): os.makedirs('temp') 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 = [] llm_sessions = []
if sider_cookie: llm_sessions += [SiderLLMSession(default_model=x) for x in \ if sider_cookie: llm_sessions += [SiderLLMSession(default_model=x) for x in \
["gemini-3.0-flash", "claude-haiku-4.5", "kimi-k2"]] ["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: if len(llm_sessions) > 0:
llmclient = ToolClient(llm_sessions, auto_save_tokens=True) llmclient = ToolClient(llm_sessions, auto_save_tokens=True)
self.llmclient = llmclient self.llmclient = llmclient

View File

@@ -1,8 +1,17 @@
oai_apikey = 'sk-uklUR...' oai_config = {
oai_apibase = "http://113.345.339.347:3001/v1" 'apikey':'sk-uklURcj',
oai_model = "openai/gpt-5.1" 'apibase':"http://113.145.139.147:3001/v1",
'model':"openai/gpt-5.1"
}
# or # or
sider_cookie = 'token=Bearer%20eyJhbGciOiJIUz...' 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"
}

View File

@@ -3,14 +3,14 @@ import os, json, re, time, requests, sys, threading
try: import mykey try: import mykey
except: raise Exception('[ERROR] mykey.py not found, please copy mykey_template.py to mykey.py and fill your LLM backend.') 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") proxy = mykeys.get("proxy", 'http://127.0.0.1:2082')
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')
proxies = {"http": proxy, "https": proxy} if proxy else None proxies = {"http": proxy, "https": proxy} if proxy else None
class SiderLLMSession: class SiderLLMSession:
@@ -56,7 +56,7 @@ class GeminiSession:
return iter([full_text]) if stream else full_text return iter([full_text]) if stream else full_text
class LLMSession: 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_key = api_key
self.api_base = api_base self.api_base = api_base
self.raw_msgs = [] self.raw_msgs = []
@@ -297,14 +297,16 @@ if __name__ == "__main__":
class MockMyKey: pass class MockMyKey: pass
mykey = MockMyKey() mykey = MockMyKey()
sider_cookie = get_config("sider_cookie") mykeys = vars(mykey)
oai_apikey = get_config("oai_apikey") sider_cookie = mykeys.get("sider_cookie")
oai_apibase = get_config("oai_apibase") oai_configs = {
oai_model = get_config("oai_model") k: v for k, v in vars(mykey).items() if k.startswith("oai_config") and v
google_api_key = get_config("google_api_key") }
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(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) #llmclient = ToolClient(SiderLLMSession().ask)
def get_final(gen): def get_final(gen):
try: try:

View File

@@ -83,7 +83,9 @@ function analyzeNode(node, pPathType='main') {
return; return;
} }
const pathType = (node.dataset.mark && !node.dataset.mark.includes(':main')) ? 'second' : pPathType; 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 (rectn.width < window.innerWidth * 0.8 && rectn.height < window.innerHeight * 0.8) return node;
if (node.tagName === 'TABLE') return; if (node.tagName === 'TABLE') return;
const children = Array.from(node.children); const children = Array.from(node.children);
@@ -901,33 +903,34 @@ def execute_js_rich(script, driver):
error_msg = str(error) error_msg = str(error)
print(f"❌ Error: {error_msg}") print(f"❌ Error: {error_msg}")
transients = get_temp_texts(driver)
if driver.default_session_id != curr_session: if driver.default_session_id != curr_session:
curr_session = driver.latest_session_id curr_session = driver.latest_session_id
print('Session changed') print('Session changed')
new_tab = True new_tab = True
rr = {
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 {
"status": "failed" if error_msg else "success", "status": "failed" if error_msg else "success",
"js_return": result, "js_return": result,
"error": error_msg,
"transients": transients,
"environment": { "environment": {
"new_tab": new_tab, "new_tab": new_tab,
"reloaded": reloaded "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