30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from .base import PWABridge, best_response
|
|
|
|
class Mammouth(PWABridge):
|
|
name = "mammouth"
|
|
url = "https://mammouth.ai/app"
|
|
use_firefox = True
|
|
proxy = "socks5://host.docker.internal:1080"
|
|
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"
|
|
|
|
async def login_status(self):
|
|
p = await self.get_page()
|
|
try:
|
|
await p.wait_for_load_state("domcontentloaded", timeout=30000)
|
|
return {"logged_in": "/login" not in p.url, "url": p.url}
|
|
except Exception as e: return {"logged_in": False, "error": str(e)}
|
|
|
|
async def chat(self, prompt: str, model: str = "auto") -> str:
|
|
async with await self.lock():
|
|
p = await self.get_page()
|
|
try: await p.wait_for_load_state("domcontentloaded", timeout=30000)
|
|
except Exception: pass
|
|
if "/login" in p.url: return "[mammouth login wall — proxy check]"
|
|
ta = await p.wait_for_selector('textarea, div[contenteditable="true"]', timeout=30000)
|
|
await ta.click(); await ta.fill(prompt); await p.wait_for_timeout(800)
|
|
await self.start_capture(p)
|
|
await p.keyboard.press("Enter")
|
|
await p.wait_for_timeout(18000)
|
|
captured = await self.end_capture(p)
|
|
return best_response(captured, prompt) or "[no response]"
|