diff --git a/agents/__init__.py b/agents/__init__.py deleted file mode 100644 index c2b44e2..0000000 --- a/agents/__init__.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 - -# Copyright 2023 The HuggingFace Inc. team. All rights reserved. -# -# 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. -from typing import TYPE_CHECKING - -from transformers.utils import ( - OptionalDependencyNotAvailable, - _LazyModule, - is_torch_available, -) - - -_import_structure = { - "agents": [ - "Agent", - "CodeAgent", - "ManagedAgent", - "ReactAgent", - "CodeAgent", - "JsonAgent", - "Toolbox", - ], - "llm_engine": ["HfApiEngine", "TransformersEngine"], - "monitoring": ["stream_to_gradio"], - "tools": [ - "PipelineTool", - "Tool", - "ToolCollection", - "launch_gradio_demo", - "load_tool", - "tool", - ], -} - -try: - if not is_torch_available(): - raise OptionalDependencyNotAvailable() -except OptionalDependencyNotAvailable: - pass -else: - _import_structure["default_tools"] = ["FinalAnswerTool", "PythonInterpreterTool"] - _import_structure["document_question_answering"] = ["DocumentQuestionAnsweringTool"] - _import_structure["image_question_answering"] = ["ImageQuestionAnsweringTool"] - _import_structure["search"] = ["DuckDuckGoSearchTool", "VisitWebpageTool"] - _import_structure["speech_to_text"] = ["SpeechToTextTool"] - _import_structure["text_to_speech"] = ["TextToSpeechTool"] - _import_structure["translation"] = ["TranslationTool"] - -if TYPE_CHECKING: - from .agents import ( - Agent, - ManagedAgent, - ReactAgent, - CodeAgent, - JsonAgent, - Toolbox, - ) - from .llm_engine import HfApiEngine, TransformersEngine - from .monitoring import stream_to_gradio - from .tools import ( - PipelineTool, - Tool, - ToolCollection, - launch_gradio_demo, - load_tool, - tool, - ) - - try: - if not is_torch_available(): - raise OptionalDependencyNotAvailable() - except OptionalDependencyNotAvailable: - pass - else: - from .default_tools import FinalAnswerTool, PythonInterpreterTool - from .tools.document_question_answering import DocumentQuestionAnsweringTool - from .tools.image_question_answering import ImageQuestionAnsweringTool - from .tools.search import DuckDuckGoSearchTool, VisitWebpageTool - from .tools.speech_to_text import SpeechToTextTool - from .tools.text_to_speech import TextToSpeechTool - from .tools.translation import TranslationTool -else: - import sys - - sys.modules[__name__] = _LazyModule( - __name__, globals()["__file__"], _import_structure, module_spec=__spec__ - ) diff --git a/pyproject.toml b/pyproject.toml index 6cbb33d..c1a18ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,3 @@ dependencies = [ "duckduckgo-search>=6.3.7", "python-dotenv>=1.0.1" ] - -[tool.setuptools] -packages = ["agents"] \ No newline at end of file diff --git a/src/agents/__init__.py b/src/agents/__init__.py new file mode 100644 index 0000000..fe61d95 --- /dev/null +++ b/src/agents/__init__.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding=utf-8 + +# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# +# 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. +from typing import TYPE_CHECKING + +from transformers.utils import ( + OptionalDependencyNotAvailable, + _LazyModule, + is_torch_available, +) +from transformers.utils.import_utils import define_import_structure + + +if TYPE_CHECKING: + from .agents import * + from .llm_engine import * + from .monitoring import * + from .tools import * +else: + import sys + + _file = globals()["__file__"] + sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) diff --git a/agents/agent_types.py b/src/agents/agent_types.py similarity index 99% rename from agents/agent_types.py rename to src/agents/agent_types.py index 39f0d3d..99007c8 100644 --- a/agents/agent_types.py +++ b/src/agents/agent_types.py @@ -266,3 +266,5 @@ def handle_agent_outputs(output, output_type=None): if isinstance(output, _k): return _v(output) return output + +__all__ = ["AgentType", "AgentImage", "AgentText", "AgentAudio"] \ No newline at end of file diff --git a/agents/agents.py b/src/agents/agents.py similarity index 99% rename from agents/agents.py rename to src/agents/agents.py index db02088..e7292eb 100644 --- a/agents/agents.py +++ b/src/agents/agents.py @@ -1073,3 +1073,5 @@ And even if your task resolution is not successful, please return as much contex return answer else: return output + +__all__ = ["BaseAgent", "ManagedAgent", "ReactAgent", "CodeAgent", "JsonAgent", "Toolbox"] \ No newline at end of file diff --git a/agents/default_tools.py b/src/agents/default_tools.py similarity index 98% rename from agents/default_tools.py rename to src/agents/default_tools.py index 1c06e3f..7e50fcd 100644 --- a/agents/default_tools.py +++ b/src/agents/default_tools.py @@ -183,3 +183,5 @@ class UserInputTool(Tool): def forward(self, question): user_input = input(f"{question} => ") return user_input + +__all__ = ["PythonInterpreterTool", "FinalAnswerTool", "UserInputTool"] \ No newline at end of file diff --git a/agents/gradio_ui.py b/src/agents/gradio_ui.py similarity index 98% rename from agents/gradio_ui.py rename to src/agents/gradio_ui.py index b7ac7ab..8daccd1 100644 --- a/agents/gradio_ui.py +++ b/src/agents/gradio_ui.py @@ -110,3 +110,5 @@ class GradioUI: ).then(self.interact_with_agent, [stored_message, chatbot], [chatbot]) demo.launch() + +__all__ = ["stream_to_gradio", "GradioUI"] \ No newline at end of file diff --git a/agents/llm_engine.py b/src/agents/llm_engine.py similarity index 98% rename from agents/llm_engine.py rename to src/agents/llm_engine.py index 76cd692..3f1f52a 100644 --- a/agents/llm_engine.py +++ b/src/agents/llm_engine.py @@ -268,3 +268,5 @@ DEFAULT_CODEAGENT_REGEX_GRAMMAR = { "type": "regex", "value": "Thought: .+?\\nCode:\\n```(?:py|python)?\\n(?:.|\\s)+?\\n```", } + +__all__ = ["MessageRole", "llama_role_conversions", "get_clean_message_list", "HfEngine", "TransformersEngine", "HfApiEngine"] \ No newline at end of file diff --git a/agents/monitoring.py b/src/agents/monitoring.py similarity index 98% rename from agents/monitoring.py rename to src/agents/monitoring.py index 9c53e44..e1e9882 100644 --- a/agents/monitoring.py +++ b/src/agents/monitoring.py @@ -43,3 +43,5 @@ class Monitor: ) console.print(f"- Input tokens: {self.total_input_token_count:,}") console.print(f"- Output tokens: {self.total_output_token_count:,}") + +__all__ = ["Monitor"] \ No newline at end of file diff --git a/agents/prompts.py b/src/agents/prompts.py similarity index 99% rename from agents/prompts.py rename to src/agents/prompts.py index 1112238..ac4dd25 100644 --- a/agents/prompts.py +++ b/src/agents/prompts.py @@ -490,3 +490,5 @@ Here is my new/updated plan of action to solve the task: ``` {plan_update} ```""" + +__all__ = ["USER_PROMPT_PLAN_UPDATE", "PLAN_UPDATE_FINAL_PLAN_REDACTION", "ONESHOT_CODE_SYSTEM_PROMPT", "CODE_SYSTEM_PROMPT", "JSON_SYSTEM_PROMPT"] \ No newline at end of file diff --git a/agents/python_interpreter.py b/src/agents/python_interpreter.py similarity index 99% rename from agents/python_interpreter.py rename to src/agents/python_interpreter.py index 2f6e273..90f8345 100644 --- a/agents/python_interpreter.py +++ b/src/agents/python_interpreter.py @@ -1001,3 +1001,5 @@ def evaluate_python_code( msg = truncate_content(PRINT_OUTPUTS, max_length=MAX_LEN_OUTPUT) msg += f"EXECUTION FAILED:\nEvaluation stopped at line '{ast.get_source_segment(code, node)}' because of the following error:\n{e}" raise InterpreterError(msg) + +__all__ = ["evaluate_python_code"] \ No newline at end of file diff --git a/agents/search.py b/src/agents/search.py similarity index 98% rename from agents/search.py rename to src/agents/search.py index b5a3aa6..837d6b0 100644 --- a/agents/search.py +++ b/src/agents/search.py @@ -77,3 +77,5 @@ class VisitWebpageTool(Tool): return f"Error fetching the webpage: {str(e)}" except Exception as e: return f"An unexpected error occurred: {str(e)}" + +__all__ = ["DuckDuckGoSearchTool", "VisitWebpageTool"] \ No newline at end of file diff --git a/agents/tools.py b/src/agents/tools.py similarity index 99% rename from agents/tools.py rename to src/agents/tools.py index ac78b8e..ab8edca 100644 --- a/agents/tools.py +++ b/src/agents/tools.py @@ -1185,3 +1185,5 @@ class Toolbox: for tool in self._tools.values(): toolbox_description += f"\t{tool.name}: {tool.description}\n" return toolbox_description + +__all__ = ["Tool", "tool", "load_tool", "launch_gradio_demo", "Toolbox"] \ No newline at end of file diff --git a/agents/utils.py b/src/agents/utils.py similarity index 99% rename from agents/utils.py rename to src/agents/utils.py index bc00abd..bd4d02c 100644 --- a/agents/utils.py +++ b/src/agents/utils.py @@ -109,3 +109,5 @@ def truncate_content( + f"\n..._This content has been truncated to stay below {max_length} characters_...\n" + content[-MAX_LENGTH_TRUNCATE_CONTENT // 2 :] ) + +__all__ = [] \ No newline at end of file