bugfix
This commit is contained in:
parent
ea1e64ad3e
commit
86dae10616
@ -103,12 +103,12 @@ class IndustrialSkillEngine:
|
||||
req_file = skill_md.parent / "requirements.txt"
|
||||
has_deps = req_file.exists()
|
||||
|
||||
self.registry[name] = {
|
||||
self.registry[name] = DictObject(**{
|
||||
"root": skill_md.parent,
|
||||
"meta": meta,
|
||||
"content": content,
|
||||
"has_deps": has_deps
|
||||
}
|
||||
})
|
||||
await env.session_setvalue(key, self.registry)
|
||||
|
||||
# --- 2. 自动化依赖环境隔离 (venv 思想) ---
|
||||
@ -145,12 +145,8 @@ class IndustrialSkillEngine:
|
||||
print(f"⚠️ 执行失败,尝试让 AI 自愈修复参数...")
|
||||
new_prompt = f"命令 '{command}' 失败,错误信息: {res.stderr}。请根据错误重新生成正确的命令,或提示用户补全参数。"
|
||||
# 这里会递归调用逻辑进行修复
|
||||
return await self.run(new_prompt, is_retry=True)
|
||||
return await self._run(new_prompt, is_retry=True)
|
||||
|
||||
await self.write_output({
|
||||
"status": "FAILED",
|
||||
"error": f"Error: {res.stderr}"
|
||||
})
|
||||
raise Exception(f"Error: {res.stderr}")
|
||||
|
||||
return res.stdout
|
||||
@ -175,10 +171,11 @@ class IndustrialSkillEngine:
|
||||
choice = await self.llm(f"上下文:{context or ''}\n用户问题: {user_prompt}\n可选深入文档: {found_docs}\n需要读取哪个?(仅返回路径,不需则返回 None)")
|
||||
if choice != "None" and any(choice in doc for doc in found_docs):
|
||||
with open(skill["root"] / choice, 'r') as f:
|
||||
await self.write_output({
|
||||
output = {
|
||||
"status": "PROCESSING",
|
||||
"hint": f"📂 深度加载: {choice}"
|
||||
})
|
||||
}
|
||||
await self.write_output(output)
|
||||
base_content += f"\n\n--- 深度参考 ({choice}) ---\n{f.read()}"
|
||||
|
||||
return base_content
|
||||
@ -190,20 +187,33 @@ class IndustrialSkillEngine:
|
||||
data = await self.task_queue.get()
|
||||
if not data:
|
||||
break;
|
||||
debug(f'{data=}, {type(data)=}')
|
||||
yield data
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
# --- 5. 主运行接口 ---
|
||||
async def run(self, user_prompt: str, context=None, is_retry=False):
|
||||
async def run(self, parmas_kw):
|
||||
try:
|
||||
user_input = json.dumps(params_kw, ensure_ascii=False)
|
||||
await self._run(user_input)
|
||||
except Exception as e:
|
||||
await self.write_output({
|
||||
'status': 'FAILED',
|
||||
'error': f"{e}'
|
||||
})
|
||||
self.write_output(None)
|
||||
|
||||
async def _run(self, user_prompt: str, context=None, is_retry=False):
|
||||
# 如果是重试,跳过技能选择
|
||||
await self.boot()
|
||||
debug(f'{self.registry=}')
|
||||
if not is_retry:
|
||||
await self.write_output({
|
||||
"status": "PROCESSING",
|
||||
"hint": "寻找合适的skill"
|
||||
})
|
||||
skill_map = {n: v["description"] for n, v in self.registry.items()}
|
||||
skill_map = {n: v.meta.description for n, v in self.registry.items()}
|
||||
target = await self.llm(f"用户意图: {user_prompt}\n可选技能清单: {skill_map}\n请返回匹配的技能名:")
|
||||
self.state["current_skill"] = target
|
||||
await self.write_output({
|
||||
@ -213,11 +223,7 @@ class IndustrialSkillEngine:
|
||||
|
||||
skill_name = self.state["current_skill"]
|
||||
if skill_name not in self.registry:
|
||||
await self.write_output({
|
||||
"status": "FAILED",
|
||||
"error": f"技能名{skill_name}未注册"
|
||||
})
|
||||
raise Exception("Skill not found.")
|
||||
raise Exception(f"技能名{skill_name}未注册")
|
||||
|
||||
# 获取递归上下文
|
||||
context = await self._get_expanded_context(skill_name, user_prompt, context=context)
|
||||
@ -240,7 +246,7 @@ class IndustrialSkillEngine:
|
||||
asyncio.sleep(0.5)
|
||||
user_reply = await env.session_getvalue(sessionkey)
|
||||
prompt = f"{user_prompt}\n补充输入:{user_reply}"
|
||||
await self.run(prompt, context=context, is_retry=True)
|
||||
await self._run(prompt, context=context, is_retry=True)
|
||||
return
|
||||
if "EXEC:" in decision:
|
||||
cmd = decision.split("EXEC:")[1].strip()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user