__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. # Copyright 2023 The HuggingFace Inc. team. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from typing import TYPE_CHECKING
  17. from ..utils import (
  18. OptionalDependencyNotAvailable,
  19. _LazyModule,
  20. is_torch_available,
  21. )
  22. _import_structure = {
  23. "agents": ["Agent", "CodeAgent", "ManagedAgent", "ReactAgent", "ReactCodeAgent", "ReactJsonAgent", "Toolbox"],
  24. "llm_engine": ["HfApiEngine", "TransformersEngine"],
  25. "monitoring": ["stream_to_gradio"],
  26. "tools": ["PipelineTool", "Tool", "ToolCollection", "launch_gradio_demo", "load_tool", "tool"],
  27. }
  28. try:
  29. if not is_torch_available():
  30. raise OptionalDependencyNotAvailable()
  31. except OptionalDependencyNotAvailable:
  32. pass
  33. else:
  34. _import_structure["default_tools"] = ["FinalAnswerTool", "PythonInterpreterTool"]
  35. _import_structure["document_question_answering"] = ["DocumentQuestionAnsweringTool"]
  36. _import_structure["image_question_answering"] = ["ImageQuestionAnsweringTool"]
  37. _import_structure["search"] = ["DuckDuckGoSearchTool", "VisitWebpageTool"]
  38. _import_structure["speech_to_text"] = ["SpeechToTextTool"]
  39. _import_structure["text_to_speech"] = ["TextToSpeechTool"]
  40. _import_structure["translation"] = ["TranslationTool"]
  41. if TYPE_CHECKING:
  42. from .agents import Agent, CodeAgent, ManagedAgent, ReactAgent, ReactCodeAgent, ReactJsonAgent, Toolbox
  43. from .llm_engine import HfApiEngine, TransformersEngine
  44. from .monitoring import stream_to_gradio
  45. from .tools import PipelineTool, Tool, ToolCollection, launch_gradio_demo, load_tool, tool
  46. try:
  47. if not is_torch_available():
  48. raise OptionalDependencyNotAvailable()
  49. except OptionalDependencyNotAvailable:
  50. pass
  51. else:
  52. from .default_tools import FinalAnswerTool, PythonInterpreterTool
  53. from .document_question_answering import DocumentQuestionAnsweringTool
  54. from .image_question_answering import ImageQuestionAnsweringTool
  55. from .search import DuckDuckGoSearchTool, VisitWebpageTool
  56. from .speech_to_text import SpeechToTextTool
  57. from .text_to_speech import TextToSpeechTool
  58. from .translation import TranslationTool
  59. else:
  60. import sys
  61. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)