mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-20 04:58:22 +06:00

* Create CodeAgent and ReactAgent * Fix formatting errors * Update documentation for agents * Add custom errors, improve logging * Support variable usage in ReactAgent * add messages * Add message passing format * Create React Code Agent * Update * Refactoring * Fix errors * Improve python interpreter * Only non-tensor inputs should be sent to device * Calculator tool slight refactor * Improve docstrings * Refactor * Fix tests * Fix more tests * Fix even more tests * Fix tests by replacing output and input types * Fix operand type issue * two small fixes * EM TTS * Fix agent running type errors * Change text to speech tests to allow changed outputs * Update doc with new agent types * Improve code interpreter * If max iterations reached, provide a real answer instead of an error * Add edge case in interpreter * Add safe imports to the interpreter * Interpreter tweaks: tuples and listcomp * Make style * Make quality * Add dictcomp to interpreter * Rename ReactJSONAgent to ReactJsonAgent * Misc changes * ToolCollection * Rename agent's logger to self.logger * Add while loops to interpreter * Update doc with new tools. still need to mention collections * Add collections to the doc * Small fixes on logs and interpretor * Fix toolbox return type * Docs + fixup * Skip doctests * Correct prompts with improved examples and formatting * Update prompt * Remove outdated docs * Change agent to accept Toolbox object for tools * Remove calculator tool * Propagate removal of calculator in doc * Fix 2 failing workflows * Simplify additional argument passing * AgentType audio * Minor changes: function name, types * Remove calculator tests * Fix test * Fix torch requirement * Fix final answer tests * Style fixes * Fix tests * Update docstrings with calculator removal * Small type hint fixes * Update tests/agents/test_translation.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update tests/agents/test_python_interpreter.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/default_tools.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/tools.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update tests/agents/test_agents.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/bert/configuration_bert.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/tools.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/speech_to_text.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update tests/agents/test_speech_to_text.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update tests/agents/test_tools_common.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * pygments * Answer comments * Cleaning up * Simplifying init for all agents * Improving prompts and making code nicer * Style fixes * Add multiple comparator test in interpreter * Style fixes * Improve BERT example in documentation * Add examples to doc * Fix python interpreter quality * Logging improvements * Change test flag to agents * Quality fix * Add example for HfEngine * Improve conversation example for HfEngine * typo fix * Verify doc * Update docs/source/en/agents.md Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/agents.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/prompts.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/agents/python_interpreter.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update docs/source/en/agents.md Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Fix style issues * local s2t tool --------- Co-authored-by: Cyril Kondratenko <kkn1993@gmail.com> Co-authored-by: Lysandre <lysandre@huggingface.co> Co-authored-by: Lysandre <lysandre.debut@reseau.eseo.fr> Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# coding=utf-8
|
|
# Copyright 2024 HuggingFace Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import unittest
|
|
|
|
from transformers import load_tool
|
|
from transformers.agents.agent_types import AGENT_TYPE_MAPPING
|
|
|
|
from .test_tools_common import ToolTesterMixin, output_type
|
|
|
|
|
|
class TranslationToolTester(unittest.TestCase, ToolTesterMixin):
|
|
def setUp(self):
|
|
self.tool = load_tool("translation")
|
|
self.tool.setup()
|
|
self.remote_tool = load_tool("translation", remote=True)
|
|
|
|
def test_exact_match_arg(self):
|
|
result = self.tool("Hey, what's up?", src_lang="English", tgt_lang="French")
|
|
self.assertEqual(result, "- Hé, comment ça va?")
|
|
|
|
def test_exact_match_kwarg(self):
|
|
result = self.tool(text="Hey, what's up?", src_lang="English", tgt_lang="French")
|
|
self.assertEqual(result, "- Hé, comment ça va?")
|
|
|
|
def test_call(self):
|
|
inputs = ["Hey, what's up?", "English", "Spanish"]
|
|
output = self.tool(*inputs)
|
|
|
|
self.assertEqual(output_type(output), self.tool.output_type)
|
|
|
|
def test_agent_type_output(self):
|
|
inputs = ["Hey, what's up?", "English", "Spanish"]
|
|
output = self.tool(*inputs)
|
|
|
|
output_type = AGENT_TYPE_MAPPING[self.tool.output_type]
|
|
self.assertTrue(isinstance(output, output_type))
|
|
|
|
def test_agent_types_inputs(self):
|
|
example_inputs = {
|
|
"text": "Hey, what's up?",
|
|
"src_lang": "English",
|
|
"tgt_lang": "Spanish",
|
|
}
|
|
|
|
_inputs = []
|
|
for input_name in example_inputs.keys():
|
|
example_input = example_inputs[input_name]
|
|
input_description = self.tool.inputs[input_name]
|
|
input_type = input_description["type"]
|
|
_inputs.append(AGENT_TYPE_MAPPING[input_type](example_input))
|
|
|
|
# Should not raise an error
|
|
output = self.tool(**example_inputs)
|
|
output_type = AGENT_TYPE_MAPPING[self.tool.output_type]
|
|
self.assertTrue(isinstance(output, output_type))
|