Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# app.py
|
| 2 |
-
# app.py
|
| 3 |
from __future__ import annotations
|
| 4 |
import os
|
| 5 |
import traceback
|
|
@@ -108,25 +107,20 @@ def handle(user_msg: str, history_messages: List[Dict[str, str]], files: list) -
|
|
| 108 |
# --- AGGRESSIVE PROMPT ENGINEERING FIX ---
|
| 109 |
# This new prefix explicitly forbids the LLM from outputting an Action and a Final Answer simultaneously.
|
| 110 |
AGENT_PREFIX = """
|
| 111 |
-
You are a data analysis agent
|
| 112 |
-
You
|
| 113 |
-
|
| 114 |
-
Your response MUST strictly follow one of two formats:
|
| 115 |
-
|
| 116 |
-
FORMAT 1: To think and execute code.
|
| 117 |
-
Thought: Your reasoning for the next step. This is mandatory.
|
| 118 |
-
Action: The tool to use, which is always `python_repl_ast`.
|
| 119 |
-
Action Input: The single-line Python code to execute.
|
| 120 |
|
| 121 |
-
FORMAT
|
| 122 |
-
Thought:
|
| 123 |
-
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
|
|
|
| 130 |
"""
|
| 131 |
|
| 132 |
# Create the pandas DataFrame agent with our new, stricter prefix
|
|
@@ -137,7 +131,7 @@ Begin!
|
|
| 137 |
verbose=True,
|
| 138 |
allow_dangerous_code=True,
|
| 139 |
handle_parsing_errors=True,
|
| 140 |
-
prefix=AGENT_PREFIX
|
| 141 |
)
|
| 142 |
|
| 143 |
# Run the agent with the user's scenario text.
|
|
|
|
| 1 |
# app.py
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
import os
|
| 4 |
import traceback
|
|
|
|
| 107 |
# --- AGGRESSIVE PROMPT ENGINEERING FIX ---
|
| 108 |
# This new prefix explicitly forbids the LLM from outputting an Action and a Final Answer simultaneously.
|
| 109 |
AGENT_PREFIX = """
|
| 110 |
+
You are a data analysis agent. You have a pandas dataframe named `df`.
|
| 111 |
+
You MUST respond in one of two formats.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
FORMAT 1: To perform a task. Your response must be a single block of text with ONLY these three sections:
|
| 114 |
+
Thought: Your step-by-step reasoning.
|
| 115 |
+
Action: python_repl_ast
|
| 116 |
+
Action Input: The Python code to run.
|
| 117 |
|
| 118 |
+
FORMAT 2: To give the final answer. Your response must be a single block of text with ONLY these two sections:
|
| 119 |
+
Thought: I can now answer the user's query.
|
| 120 |
+
Final Answer: The complete answer.
|
| 121 |
|
| 122 |
+
CRITICAL RULE: NEVER, EVER, combine `Action` and `Final Answer` in the same response. Choose one format.
|
| 123 |
+
Begin by analyzing the user's query and provide your first thought and action using FORMAT 1.
|
| 124 |
"""
|
| 125 |
|
| 126 |
# Create the pandas DataFrame agent with our new, stricter prefix
|
|
|
|
| 131 |
verbose=True,
|
| 132 |
allow_dangerous_code=True,
|
| 133 |
handle_parsing_errors=True,
|
| 134 |
+
prefix=AGENT_PREFIX
|
| 135 |
)
|
| 136 |
|
| 137 |
# Run the agent with the user's scenario text.
|