Add OpenClaw skills, platform kit, and template docs
Made-with: Cursor
This commit is contained in:
48
llm-manager/scripts/engines/kimi.py
Normal file
48
llm-manager/scripts/engines/kimi.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import asyncio
|
||||
from .base import BaseEngine
|
||||
|
||||
|
||||
class KimiEngine(BaseEngine):
|
||||
async def generate(self, prompt: str) -> str:
|
||||
await self.page.goto("https://kimi.moonshot.cn/")
|
||||
await self.page.wait_for_load_state("networkidle")
|
||||
|
||||
# 登录检测:等待输入框出现,超时则未登录
|
||||
try:
|
||||
editor = self.page.locator(".chat-input-editor").first
|
||||
await editor.wait_for(state="visible", timeout=10000)
|
||||
except Exception:
|
||||
return "ERROR:REQUIRE_LOGIN"
|
||||
|
||||
# 输入提示词(insert_text 避免换行符被误触发)
|
||||
await editor.click()
|
||||
await self.page.keyboard.insert_text(prompt)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
# 点击发送按钮
|
||||
await self.page.locator(".send-button-container").first.click()
|
||||
|
||||
print("💡 [llm-manager/kimi] 已发送提示词,等待 Kimi 生成响应...")
|
||||
|
||||
# 等待 2 秒让发送按钮进入"生成中"状态
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# 等待 Send SVG 图标重新出现(表示生成完毕)
|
||||
try:
|
||||
send_icon = self.page.locator('.send-button-container svg[name="Send"]')
|
||||
await send_icon.wait_for(state="visible", timeout=150000)
|
||||
except Exception:
|
||||
return "ERROR:Kimi 生成超时(150秒未见完成标志),可能网络卡住或内容被拦截。"
|
||||
|
||||
# 稳妥起见多等 2 秒,让复制按钮完全渲染
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# 点击最后一条回复的复制按钮,通过剪贴板取完整文本
|
||||
try:
|
||||
copy_btn = self.page.locator('svg[name="Copy"]').last
|
||||
await copy_btn.click()
|
||||
await asyncio.sleep(0.5)
|
||||
result = await self.page.evaluate("navigator.clipboard.readText()")
|
||||
return result.strip()
|
||||
except Exception as e:
|
||||
return f"ERROR:抓取 Kimi 内容时异常:{e}"
|
||||
Reference in New Issue
Block a user