task:str,) ->str:"""Generate and Execute Python code."""code = self.write_code(task)try:returnself.execute_code(code,"main.py")exceptExceptionasex:returnstr(ex)defexecute_code(self, code:str, filename:str) ->str:"""Execute a python code."""try:withset_directory(Path(self.path)):...
# 导入所需的类和枚举 from langchain.text_splitter import RecursiveCharacterTextSplitter, Language # 定义一个包含Python代码的字符串 PYTHON_CODE = """ def hello_world(): print("Hello, World!") # Call the function hello_world() """ # 使用from_language方法创建一个针对Python语言的RecursiveCharac...
14. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>" 15. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>" 16. Execute Python File: "execute_python_file", args: "...
from openai import OpenAIclient = OpenAI(api_key="your key",base_url="https://api.openai-hk.com/v1")tool = """1 tool: python_interpreter, description: use it to execute python code2 tool: web_access, description: use it to get realtime info, input is the question or query"""reac...
{ "prompts": [ "Human: You are an agent designed to write and execute python code to answer questions.\nYou have access to a python REPL, which you can use to execute python code.\nIf you get an error, debug your code and try again.\nOnly use the output of your code to answer ...
PYTHON,chunk_size=50,chunk_overlap=0)python_docs=python_splitter.create_documents([PYTHON_CODE])...
text_splitter import ( RecursiveCharacterTextSplitter, Language, ) #支持解析的编程语言 #[e.value for e in Language] #要切割的代码文档 PYTHON_CODE = """ def hello_world(): print("Hello, World!") #调用函数 hello_world() """ py_spliter = RecursiveCharacterTextSplitter.from_language( ...
""13. Analyze Code: "analyze_code", args: "code": ""14. Get Improved Code: "improve_code", args: "suggestions": "", "code": ""15. Write Tests: "write_tests", args: "code": "", "focus": ""16. Execute Python File: "execute_python_file", args: "file": ""17. Generate ...
点击右侧的“HTTP Request”配置URL地址 你可以点击“Execute Code”查看输出,如下所示:右侧显示生成了...
The name of the file to be executed")@tool(args_schema=PythonFileInput)defwrite_file(filename, source_code):""" Generate python files based on input source code """withopen(filename,"w")as f: f.write(source_code)@tool(args_schema=PytestFileName)defexecute_test_file(filename...