mirror of
https://github.com/huggingface/transformers.git
synced 2025-08-02 03:01:07 +06:00
Ability to override clean_code_for_run (#28783)
* Add clean_code_for_run function * Call clean_code_for_run from agent method
This commit is contained in:
parent
c430d6eaee
commit
0466fd5ca2
@ -315,6 +315,13 @@ class Agent:
|
|||||||
self.chat_state = {}
|
self.chat_state = {}
|
||||||
self.cached_tools = None
|
self.cached_tools = None
|
||||||
|
|
||||||
|
def clean_code_for_run(self, result):
|
||||||
|
"""
|
||||||
|
Override this method if you want to change the way the code is
|
||||||
|
cleaned for the `run` method.
|
||||||
|
"""
|
||||||
|
return clean_code_for_run(result)
|
||||||
|
|
||||||
def run(self, task, *, return_code=False, remote=False, **kwargs):
|
def run(self, task, *, return_code=False, remote=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
Sends a request to the agent.
|
Sends a request to the agent.
|
||||||
@ -339,7 +346,7 @@ class Agent:
|
|||||||
"""
|
"""
|
||||||
prompt = self.format_prompt(task)
|
prompt = self.format_prompt(task)
|
||||||
result = self.generate_one(prompt, stop=["Task:"])
|
result = self.generate_one(prompt, stop=["Task:"])
|
||||||
explanation, code = clean_code_for_run(result)
|
explanation, code = self.clean_code_for_run(result)
|
||||||
|
|
||||||
self.log(f"==Explanation from the agent==\n{explanation}")
|
self.log(f"==Explanation from the agent==\n{explanation}")
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from .agents import BASE_PYTHON_TOOLS, clean_code_for_chat, clean_code_for_run
|
from .agents import BASE_PYTHON_TOOLS, clean_code_for_chat
|
||||||
from .python_interpreter import InterpretorError, evaluate
|
from .python_interpreter import InterpretorError, evaluate
|
||||||
|
|
||||||
|
|
||||||
@ -554,7 +554,7 @@ def evaluate_agent(agent, batch_size=8, verbose=False, return_errors=False):
|
|||||||
problem = EVALUATION_TASKS[eval_idx[start_idx + idx]]
|
problem = EVALUATION_TASKS[eval_idx[start_idx + idx]]
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"====Task {start_idx + idx}====\n{batch_tasks[idx]}\n")
|
print(f"====Task {start_idx + idx}====\n{batch_tasks[idx]}\n")
|
||||||
explanation, code = clean_code_for_run(result)
|
explanation, code = agent.clean_code_for_run(result)
|
||||||
|
|
||||||
# Evaluate agent answer and code answer
|
# Evaluate agent answer and code answer
|
||||||
agent_answer = evaluate_code(code, problem.inputs, verbose=verbose)
|
agent_answer = evaluate_code(code, problem.inputs, verbose=verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user