peichao.dong
commited on
Commit
·
eede2d8
1
Parent(s):
0040b8b
update python code tool
Browse files
agents/tools/python_code_tool.py
CHANGED
@@ -13,7 +13,7 @@ Please write Python script to fulfill the following requirement:
|
|
13 |
{input}
|
14 |
---
|
15 |
|
16 |
-
Only output the code section
|
17 |
"""
|
18 |
|
19 |
generate_python_code_promopt = PromptTemplate(input_variables=["input"], template=generate_python_code,)
|
@@ -26,10 +26,16 @@ def generate_and_excute_python_code(input: str) -> str:
|
|
26 |
'''useful for when you need to generate python code and excute it'''
|
27 |
answer_code = generate_code_chain.run(input)
|
28 |
print(answer_code)
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
print(code_content)
|
34 |
python_repl = PythonREPL()
|
35 |
result = python_repl.run(code_content)
|
|
|
13 |
{input}
|
14 |
---
|
15 |
|
16 |
+
Only output the code section with code block.
|
17 |
"""
|
18 |
|
19 |
generate_python_code_promopt = PromptTemplate(input_variables=["input"], template=generate_python_code,)
|
|
|
26 |
'''useful for when you need to generate python code and excute it'''
|
27 |
answer_code = generate_code_chain.run(input)
|
28 |
print(answer_code)
|
29 |
+
code_content = answer_code
|
30 |
+
if('```python' in answer_code):
|
31 |
+
start = answer_code.find('```python') + len('```python')
|
32 |
+
end = answer_code.rfind('```')
|
33 |
+
code_content = answer_code[start:end].strip()
|
34 |
+
elif("```" in answer_code):
|
35 |
+
start = answer_code.find('```') + len('```')
|
36 |
+
end = answer_code.rfind('```')
|
37 |
+
code_content = answer_code[start:end].strip()
|
38 |
+
|
39 |
print(code_content)
|
40 |
python_repl = PythonREPL()
|
41 |
result = python_repl.run(code_content)
|