This commit is contained in:
Cai
2025-09-21 14:04:05 +08:00
88 changed files with 1743 additions and 448 deletions

View File

@@ -96,49 +96,50 @@ class ChatManager:
def change_language(self, id, language):
self.ase_client.send_text('language', language)
def sample_judge(self, id, bb):
self.function_manager.call_function('sample_judge', {'bb': bb})
def sample_judge(self, id, bb):
with self.app.app_context():
try:
print(bb.get_active_file_reletive_path())
assert bb is not None and bb.active_file_path != "" , "no path specified"
if bb.get_active_file_reletive_path().endswith(".py"):
self.socketio.emit('terminal', {'data': f"python {bb.get_active_file_reletive_path()}"}, room=id, namespace='/vscode')
self.socketio.emit('system_message', "代码试运行尚在建设,推荐直接通过命令行执行!", room=id, namespace='/agent')
return FunctionResponse("sample_judge", True, "代码试运行命令已发送请于Terminal查看结果")
else:
self.socketio.emit('system_message', "代码试运行尚仅支持python文件", room=id, namespace='/agent')
return FunctionResponse("sample_judge", False, "代码试运行尚仅支持python文件")
except Exception as e:
print(e)
if (str(e) == "no path specified"):
self.socketio.emit("system_message", "未加载IDE文件同步请尝试重新打开IDE文件或刷新页面并确保插件已连接", room=id, namespace='/agent')
return FunctionResponse("sample_judge", False, "未加载IDE文件同步请尝试重新打开IDE文件或刷新页面并确保插件已连接")
def judge(self, id, bb):
agent = self.agents[id]
with self.app.app_context():
try:
if (agent.chapter_chain[agent.chapter_chain_now].append_tools is not None and len(agent.chapter_chain[agent.chapter_chain_now].append_tools)):
for tool, tool_kwargs in agent.chapter_chain[agent.chapter_chain_now].append_tools:
if (self.chapter_chain[self.chapter_chain_now].append_tools is not None and len(self.chapter_chain[self.chapter_chain_now].append_tools)):
for tool, tool_kwargs in self.chapter_chain[self.chapter_chain_now].append_tools:
if tool.__name__ == "judge":
print(bb.get_active_file_reletive_path())
assert bb is not None and bb.active_file_path != "" , "no path specified"
if bb.get_active_file_reletive_path().endswith(".py"):
# self.socketio.emit('terminal', {'data': f"python {bb.get_active_file_reletive_path()}"}, room=id, namespace='/vscode')
self.socketio.emit('system_message', "代码评测中,请稍后", room=id, namespace='/agent')
agent.function_call({'name':'judge','arguments':{'filepath': bb.get_active_file_reletive_path()}})
return self.function_call('judge',{'filepath': bb.get_active_file_reletive_path(),'name':tool_kwargs['name']})
else:
self.socketio.emit('system_message', "代码评测尚仅支持python文件", room=id, namespace='/agent')
return FunctionResponse("judge", False, "代码评测尚仅支持python文件")
else:
with self.app.app_context():
self.socketio.emit("system_message", "本章学习无需评测", room=id, namespace='/agent')
return FunctionResponse("judge", False, "本章学习无需评测")
else:
with self.app.app_context():
self.socketio.emit("system_message", "本章学习无需评测", room=id, namespace='/agent')
return FunctionResponse("judge", False, "本章学习无需评测")
except Exception as e:
if (str(e) == "no path specified"):
self.socketio.emit("system_message", "未加载IDE文件同步请尝试重新打开IDE文件或刷新页面并确保插件已连接", room=id, namespace='/agent')
self.socketio.emit("system_message", "未加载IDE文件同步请尝试重新打开IDE文件或刷新页面,并确保插件已连接", room=id, namespace='/agent')
return FunctionResponse("judge", False, "未加载IDE文件同步请尝试重新打开IDE文件或刷新页面并确保插件已连接")