Add SceneXplain Tool (#3752)

This commit is contained in:
Zander Chase
2023-04-28 17:01:54 -07:00
committed by GitHub
parent 72c5c15f7f
commit 6c2b16e465
5 changed files with 214 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ from langchain.tools.playwright import (
NavigateTool,
)
from langchain.tools.plugin import AIPluginTool
from langchain.tools.scenexplain.tool import SceneXplainTool
from langchain.tools.shell.tool import ShellTool
__all__ = [
@@ -59,4 +60,6 @@ __all__ = [
"ReadFileTool",
"ShellTool",
"WriteFileTool",
"BaseTool",
"SceneXplainTool",
]

View File

@@ -0,0 +1 @@
"""SceneXplain API toolkit."""

View File

@@ -0,0 +1,26 @@
"""Tool for the SceneXplain API."""
from pydantic import Field
from langchain.tools.base import BaseTool
from langchain.utilities.scenexplain import SceneXplainAPIWrapper
class SceneXplainTool(BaseTool):
"""Tool that adds the capability to explain images."""
name = "Image Explainer"
description = (
"An Image Captioning Tool: Use this tool to generate a detailed caption "
"for an image. The input can be an image file of any format, and "
"the output will be a text description that covers every detail of the image."
)
api_wrapper: SceneXplainAPIWrapper = Field(default_factory=SceneXplainAPIWrapper)
def _run(self, query: str) -> str:
"""Use the tool."""
return self.api_wrapper.run(query)
async def _arun(self, query: str) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError("SceneXplainTool does not support async")