Spaces:
Sleeping
Sleeping
Clarify prompt
Browse files
app.py
CHANGED
@@ -23,41 +23,6 @@ llm_engine = HfEngine(model="meta-llama/Meta-Llama-3-70B-Instruct")
|
|
23 |
|
24 |
authorized_imports = ["numpy"]
|
25 |
|
26 |
-
|
27 |
-
class PythonInterpreterTool(Tool):
|
28 |
-
name = "python_interpreter"
|
29 |
-
description = "This is a tool that evaluates python code. It can be used to perform calculations."
|
30 |
-
|
31 |
-
output_type = "text"
|
32 |
-
available_tools = BASE_PYTHON_TOOLS.copy()
|
33 |
-
|
34 |
-
def __init__(self, *args, authorized_imports, **kwargs):
|
35 |
-
self.authorized_imports = list(set(LIST_SAFE_MODULES) | set(authorized_imports))
|
36 |
-
self.inputs = {
|
37 |
-
"code": {
|
38 |
-
"type": "text",
|
39 |
-
"description": (
|
40 |
-
"The code snippet to evaluate. All variables used in this snippet must be defined in this same snippet, "
|
41 |
-
f"else you will get an error. This code can only import the following python libraries: {authorized_imports}."
|
42 |
-
"You should MAKE ALL NECESSARY IMPORTS WITHIN THIS CODE SNIPPET, else you will get an import error!"
|
43 |
-
),
|
44 |
-
}
|
45 |
-
}
|
46 |
-
super().__init__(*args, **kwargs)
|
47 |
-
|
48 |
-
def forward(self, code):
|
49 |
-
for module in authorized_imports:
|
50 |
-
code = "import " + module + "\n" + code
|
51 |
-
output = str(
|
52 |
-
evaluate_python_code(
|
53 |
-
code,
|
54 |
-
tools=self.available_tools,
|
55 |
-
authorized_imports=self.authorized_imports,
|
56 |
-
)
|
57 |
-
)
|
58 |
-
return output
|
59 |
-
|
60 |
-
|
61 |
agent = ReactCodeAgent(
|
62 |
llm_engine=llm_engine,
|
63 |
tools=[],
|
@@ -65,7 +30,6 @@ agent = ReactCodeAgent(
|
|
65 |
max_iterations=10,
|
66 |
)
|
67 |
|
68 |
-
|
69 |
class FinalAnswerToolWithVerification(Tool):
|
70 |
name = "final_answer"
|
71 |
description = "Provides a final answer to the given problem"
|
@@ -94,7 +58,7 @@ task = """I will give you a basic function that I've created.
|
|
94 |
Now I want you to generate a set of unit tests for these functions, check that they run, and give them to me.
|
95 |
|
96 |
Please follow these steps in order:
|
97 |
-
1.
|
98 |
2. Generate one test function as a python blob, with assert statements
|
99 |
3. Run the test function in a code snippet and make sure the tests pass
|
100 |
4. Return to me the complete TEST function (not the original function) as a string code snippet.
|
@@ -167,6 +131,9 @@ def interact_with_agent(prompt):
|
|
167 |
|
168 |
|
169 |
with gr.Blocks(theme="soft") as demo:
|
|
|
|
|
|
|
170 |
with gr.Row():
|
171 |
with gr.Column():
|
172 |
text_input = gr.Textbox(
|
|
|
23 |
|
24 |
authorized_imports = ["numpy"]
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
agent = ReactCodeAgent(
|
27 |
llm_engine=llm_engine,
|
28 |
tools=[],
|
|
|
30 |
max_iterations=10,
|
31 |
)
|
32 |
|
|
|
33 |
class FinalAnswerToolWithVerification(Tool):
|
34 |
name = "final_answer"
|
35 |
description = "Provides a final answer to the given problem"
|
|
|
58 |
Now I want you to generate a set of unit tests for these functions, check that they run, and give them to me.
|
59 |
|
60 |
Please follow these steps in order:
|
61 |
+
1. Define and run the function given o you, so that it gets defined in your interpreter.
|
62 |
2. Generate one test function as a python blob, with assert statements
|
63 |
3. Run the test function in a code snippet and make sure the tests pass
|
64 |
4. Return to me the complete TEST function (not the original function) as a string code snippet.
|
|
|
131 |
|
132 |
|
133 |
with gr.Blocks(theme="soft") as demo:
|
134 |
+
gr.Markdown("""### Python test generator
|
135 |
+
|
136 |
+
Write your function in the left textbox, and the agent on the right will generate tests for you!""")
|
137 |
with gr.Row():
|
138 |
with gr.Column():
|
139 |
text_input = gr.Textbox(
|