-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
749 additions
and
117 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
langchain_zhipuai/agent_toolkits/all_tools/drawing_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union | ||
|
||
from langchain_core.agents import AgentAction | ||
from langchain_core.callbacks import ( | ||
AsyncCallbackManagerForChainRun, | ||
AsyncCallbackManagerForToolRun, | ||
CallbackManagerForToolRun, | ||
) | ||
|
||
from langchain_zhipuai.agent_toolkits import AdapterAllTool | ||
from langchain_zhipuai.agent_toolkits.all_tools.struct_type import AdapterAllToolStructType | ||
from langchain_zhipuai.agent_toolkits.all_tools.tool import ( | ||
AllToolExecutor, | ||
BaseToolOutput, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DrawingToolOutput(BaseToolOutput): | ||
platform_params: Dict[str, Any] | ||
|
||
def __init__( | ||
self, | ||
data: Any, | ||
platform_params: Dict[str, Any], | ||
**extras: Any, | ||
) -> None: | ||
super().__init__(data, "", "", **extras) | ||
self.platform_params = platform_params | ||
|
||
|
||
@dataclass | ||
class DrawingAllToolExecutor(AllToolExecutor): | ||
"""platform adapter tool for code interpreter tool""" | ||
|
||
name: str | ||
|
||
def run( | ||
self, | ||
tool: str, | ||
tool_input: str, | ||
log: str, | ||
outputs: List[Union[str, dict]] = None, | ||
run_manager: Optional[CallbackManagerForToolRun] = None, | ||
) -> DrawingToolOutput: | ||
if outputs is None or str(outputs).strip() == "": | ||
raise ValueError( | ||
f"Tool {self.name} is server error" | ||
) | ||
|
||
return DrawingToolOutput( | ||
data=f"""Access:{tool}, Message: {tool_input},{log}""", | ||
platform_params=self.platform_params, | ||
) | ||
|
||
async def arun( | ||
self, | ||
tool: str, | ||
tool_input: str, | ||
log: str, | ||
outputs: List[Union[str, dict]] = None, | ||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None, | ||
) -> DrawingToolOutput: | ||
"""Use the tool asynchronously.""" | ||
if outputs is None or str(outputs).strip() == "" or len(outputs) == 0: | ||
raise ValueError( | ||
f"Tool {self.name} is server error" | ||
) | ||
|
||
return DrawingToolOutput( | ||
data=f"""Access:{tool}, Message: {tool_input},{log}""", | ||
platform_params=self.platform_params, | ||
) | ||
|
||
|
||
class DrawingAdapterAllTool(AdapterAllTool[DrawingAllToolExecutor]): | ||
@classmethod | ||
def get_type(cls) -> str: | ||
return "DrawingAdapterAllTool" | ||
|
||
def _build_adapter_all_tool( | ||
self, platform_params: Dict[str, Any] | ||
) -> DrawingAllToolExecutor: | ||
return DrawingAllToolExecutor( | ||
name=AdapterAllToolStructType.DRAWING_TOOL, platform_params=platform_params | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
langchain_zhipuai/agent_toolkits/all_tools/web_browser_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union | ||
|
||
from langchain_core.agents import AgentAction | ||
from langchain_core.callbacks import ( | ||
AsyncCallbackManagerForChainRun, | ||
AsyncCallbackManagerForToolRun, | ||
CallbackManagerForToolRun, | ||
) | ||
|
||
from langchain_zhipuai.agent_toolkits import AdapterAllTool | ||
from langchain_zhipuai.agent_toolkits.all_tools.struct_type import AdapterAllToolStructType | ||
from langchain_zhipuai.agent_toolkits.all_tools.tool import ( | ||
AllToolExecutor, | ||
BaseToolOutput, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WebBrowserToolOutput(BaseToolOutput): | ||
platform_params: Dict[str, Any] | ||
|
||
def __init__( | ||
self, | ||
data: Any, | ||
platform_params: Dict[str, Any], | ||
**extras: Any, | ||
) -> None: | ||
super().__init__(data, "", "", **extras) | ||
self.platform_params = platform_params | ||
|
||
|
||
@dataclass | ||
class WebBrowserAllToolExecutor(AllToolExecutor): | ||
"""platform adapter tool for code interpreter tool""" | ||
|
||
name: str | ||
|
||
def run( | ||
self, | ||
tool: str, | ||
tool_input: str, | ||
log: str, | ||
outputs: List[Union[str, dict]] = None, | ||
run_manager: Optional[CallbackManagerForToolRun] = None, | ||
) -> WebBrowserToolOutput: | ||
if outputs is None or str(outputs).strip() == "": | ||
raise ValueError( | ||
f"Tool {self.name} is server error" | ||
) | ||
|
||
return WebBrowserToolOutput( | ||
data=f"""Access:{tool}, Message: {tool_input},{log}""", | ||
platform_params=self.platform_params, | ||
) | ||
|
||
async def arun( | ||
self, | ||
tool: str, | ||
tool_input: str, | ||
log: str, | ||
outputs: List[Union[str, dict]] = None, | ||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None, | ||
) -> WebBrowserToolOutput: | ||
"""Use the tool asynchronously.""" | ||
if outputs is None or str(outputs).strip() == "" or len(outputs) == 0: | ||
raise ValueError( | ||
f"Tool {self.name} is server error" | ||
) | ||
|
||
return WebBrowserToolOutput( | ||
data=f"""Access:{tool}, Message: {tool_input},{log}""", | ||
platform_params=self.platform_params, | ||
) | ||
|
||
|
||
class WebBrowserAdapterAllTool(AdapterAllTool[WebBrowserAllToolExecutor]): | ||
@classmethod | ||
def get_type(cls) -> str: | ||
return "WebBrowserAdapterAllTool" | ||
|
||
def _build_adapter_all_tool( | ||
self, platform_params: Dict[str, Any] | ||
) -> WebBrowserAllToolExecutor: | ||
return WebBrowserAllToolExecutor( | ||
name=AdapterAllToolStructType.WEB_BROWSER, platform_params=platform_params | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from zhipuai.core import BaseModel | ||
from typing import Optional, Dict, Any | ||
|
||
|
||
class AllToolsMessageToolCall(BaseModel): | ||
name: Optional[str] | ||
args: Optional[Dict[str, Any]] | ||
id: Optional[str] | ||
|
||
|
||
class AllToolsMessageToolCallChunk(BaseModel): | ||
name: Optional[str] | ||
args: Optional[Dict[str, Any]] | ||
id: Optional[str] | ||
index: Optional[int] |
Oops, something went wrong.