From c165511a1d40db9519c1073a5961e9a26fc251c1 Mon Sep 17 00:00:00 2001 From: wj-Mcat <1435130236@qq.com> Date: Fri, 12 Apr 2024 17:49:20 +0800 Subject: [PATCH 1/3] add app-id variable to headers --- erniebot-agent/src/erniebot_agent/tools/remote_tool.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erniebot-agent/src/erniebot_agent/tools/remote_tool.py b/erniebot-agent/src/erniebot_agent/tools/remote_tool.py index 65f0e22e..a30a3ae9 100644 --- a/erniebot-agent/src/erniebot_agent/tools/remote_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/remote_tool.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import dataclasses import logging from copy import deepcopy @@ -118,6 +119,9 @@ async def send_request(self, tool_arguments: Dict[str, Any]) -> dict: headers = deepcopy(self.headers) headers["Content-Type"] = self.tool_view.parameters_content_type + if "EB_SDK_TRACE_APP_ID" in os.environ: + headers["X-EB-SDK-TRACE-APP-ID"] = os.getenv("EB_SDK_TRACE_APP_ID") + requests_inputs = { "headers": headers, } From ec1c7382074e90905bca0edddfa9ab6c0b1a022b Mon Sep 17 00:00:00 2001 From: wj-Mcat <1435130236@qq.com> Date: Fri, 12 Apr 2024 19:31:05 +0800 Subject: [PATCH 2/3] update output type --- docs/modules/tools.md | 4 ++-- erniebot-agent/cookbook/function_agent.ipynb | 4 ++-- erniebot-agent/cookbook/local_tool.ipynb | 4 ++-- .../erniebot_agent/agents/function_agent_with_retrieval.py | 2 +- erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py | 4 ++-- erniebot-agent/src/erniebot_agent/tools/base.py | 6 +++--- erniebot-agent/src/erniebot_agent/tools/calculator_tool.py | 2 +- erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py | 2 +- .../src/erniebot_agent/tools/current_time_tool.py | 2 +- .../src/erniebot_agent/tools/image_generation_tool.py | 2 +- .../src/erniebot_agent/tools/langchain_retrieval_tool.py | 2 +- .../src/erniebot_agent/tools/llama_index_retrieval_tool.py | 2 +- erniebot-agent/src/erniebot_agent/tools/tool_manager.py | 2 +- .../integration_tests/agents/test_agent_with_plugins.py | 4 ++-- .../integration_tests/agents/test_tool_choice_agent.py | 2 +- erniebot-agent/tests/unit_tests/testing_utils/components.py | 2 +- erniebot-agent/tests/unit_tests/tools/test_tool_manager.py | 2 +- 17 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/modules/tools.md b/docs/modules/tools.md index fbb04e6e..0e1b5fbd 100644 --- a/docs/modules/tools.md +++ b/docs/modules/tools.md @@ -17,7 +17,7 @@ Tool 模块分为 LocalTool 和 RemoteTool 两类,LocalTool 运行在本地的 ```python class CurrentTimeTool(Tool): description: str = "CurrentTimeTool 用于获取当前时间" - ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView + output_type: Type[ToolParameterView] = CurrentTimeToolOutputView async def __call__(self) -> Dict[str, str]: return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒")} @@ -103,7 +103,7 @@ class CurrentTimeToolOutputView(ToolParameterView): class CurrentTimeTool(Tool): description: str = "CurrentTimeTool 用于获取当前时间" - ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView + output_type: Type[ToolParameterView] = CurrentTimeToolOutputView async def __call__(self) -> Dict[str, str]: return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒)} diff --git a/erniebot-agent/cookbook/function_agent.ipynb b/erniebot-agent/cookbook/function_agent.ipynb index 756c0297..ceb8e049 100644 --- a/erniebot-agent/cookbook/function_agent.ipynb +++ b/erniebot-agent/cookbook/function_agent.ipynb @@ -101,7 +101,7 @@ "class ChatWithEB(Tool):\n", " description: str = \"ChatWithEB是一款根据用户的提供的单词,获取一个具体的单词描述、翻译以及例句的工具\"\n", " input_type: Type[ToolParameterView] = ChatWithEBInputView\n", - " ouptut_type: Type[ToolParameterView] = ChatWithEBOutputView\n", + " output_type: Type[ToolParameterView] = ChatWithEBOutputView\n", "\n", " def __init__(self, llm: ERNIEBot):\n", " self.llm = llm\n", @@ -143,7 +143,7 @@ "class AddWordTool(Tool):\n", " description: str = \"添加单词以及它的详细解释到词库当中\"\n", " input_type: Type[ToolParameterView] = AddWordInput\n", - " ouptut_type: Type[ToolParameterView] = AddWordOutput\n", + " output_type: Type[ToolParameterView] = AddWordOutput\n", "\n", " def __init__(self) -> None:\n", " self.word_books = {}\n", diff --git a/erniebot-agent/cookbook/local_tool.ipynb b/erniebot-agent/cookbook/local_tool.ipynb index 6e126c41..6a69d882 100644 --- a/erniebot-agent/cookbook/local_tool.ipynb +++ b/erniebot-agent/cookbook/local_tool.ipynb @@ -87,7 +87,7 @@ "class AddWordTool(Tool):\n", " description: str = \"添加单词到词库当中\"\n", " input_type: Type[ToolParameterView] = AddWordInput\n", - " ouptut_type: Type[ToolParameterView] = AddWordOutput\n", + " output_type: Type[ToolParameterView] = AddWordOutput\n", "\n", " def __init__(self) -> None:\n", " self.word_books = {}\n", @@ -183,7 +183,7 @@ "class AddWordTool(Tool):\n", " description: str = \"添加单词到词库当中\"\n", " input_type: Type[ToolParameterView] = AddWordInput\n", - " ouptut_type: Type[ToolParameterView] = AddWordOutput\n", + " output_type: Type[ToolParameterView] = AddWordOutput\n", "\n", " def __init__(self, file: str):\n", " self.file = file\n", diff --git a/erniebot-agent/src/erniebot_agent/agents/function_agent_with_retrieval.py b/erniebot-agent/src/erniebot_agent/agents/function_agent_with_retrieval.py index 27bc6280..e7f8e609 100644 --- a/erniebot-agent/src/erniebot_agent/agents/function_agent_with_retrieval.py +++ b/erniebot-agent/src/erniebot_agent/agents/function_agent_with_retrieval.py @@ -67,7 +67,7 @@ class KnowledgeBaseTool(Tool): tool_name: str = "KnowledgeBaseTool" description: str = "在知识库中检索与用户输入query相关的段落" input_type: Type[ToolParameterView] = KnowledgeBaseToolInputView - ouptut_type: Type[ToolParameterView] = KnowledgeBaseToolOutputView + output_type: Type[ToolParameterView] = KnowledgeBaseToolOutputView def __init__( self, diff --git a/erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py b/erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py index 337c4869..a83db598 100644 --- a/erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py @@ -28,7 +28,7 @@ class BaizhongSearchToolOutputView(ToolParameterView): class BaizhongSearchTool(Tool): description: str = "在知识库中检索与用户输入query相关的段落" input_type: Type[ToolParameterView] = BaizhongSearchToolInputView - ouptut_type: Type[ToolParameterView] = BaizhongSearchToolOutputView + output_type: Type[ToolParameterView] = BaizhongSearchToolOutputView def __init__( self, description, db, threshold: float = 0.0, input_type=None, output_type=None, examples=None @@ -40,7 +40,7 @@ def __init__( if input_type is not None: self.input_type = input_type if output_type is not None: - self.ouptut_type = output_type + self.output_type = output_type if examples is not None: self.few_shot_examples = examples self.threshold = threshold diff --git a/erniebot-agent/src/erniebot_agent/tools/base.py b/erniebot-agent/src/erniebot_agent/tools/base.py index 50af2d88..bd48f118 100644 --- a/erniebot-agent/src/erniebot_agent/tools/base.py +++ b/erniebot-agent/src/erniebot_agent/tools/base.py @@ -45,7 +45,7 @@ class Tool(BaseTool, ABC): description: str name: Optional[str] = None input_type: Optional[Type[ToolParameterView]] = None - ouptut_type: Optional[Type[ToolParameterView]] = None + output_type: Optional[Type[ToolParameterView]] = None def __str__(self) -> str: name = self.name if self.name else self.tool_name @@ -81,8 +81,8 @@ def function_call_schema(self) -> dict: else: inputs["parameters"] = {"type": "object", "properties": {}} - if self.ouptut_type is not None: - inputs["responses"] = self.ouptut_type.function_call_schema() + if self.output_type is not None: + inputs["responses"] = self.output_type.function_call_schema() return scrub_dict(inputs) or {} diff --git a/erniebot-agent/src/erniebot_agent/tools/calculator_tool.py b/erniebot-agent/src/erniebot_agent/tools/calculator_tool.py index e6299b90..e4a5468e 100644 --- a/erniebot-agent/src/erniebot_agent/tools/calculator_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/calculator_tool.py @@ -21,7 +21,7 @@ class CalculatorToolOutputView(ToolParameterView): class CalculatorTool(Tool): description: str = "CalculatorTool用于执行数学公式计算" input_type: Type[ToolParameterView] = CalculatorToolInputView - ouptut_type: Type[ToolParameterView] = CalculatorToolOutputView + output_type: Type[ToolParameterView] = CalculatorToolOutputView async def __call__(self, math_formula: str) -> Dict[str, float]: return {"formula_result": eval(math_formula)} diff --git a/erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py b/erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py index 6ba9645e..37f25bf1 100644 --- a/erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py +++ b/erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py @@ -21,7 +21,7 @@ class ChatWithEB(Tool): "ChatWithEB是一款根据用户的问题,向EB生成式大语言模型进行提问,并获取EB回答结果的工具。EB一般能解决知识型问答、文本创作、信息查询、信息检索等基础的文本生成和信息检索功能" ) input_type: Type[ToolParameterView] = ChatWithEBInputView - ouptut_type: Type[ToolParameterView] = ChatWithEBOutputView + output_type: Type[ToolParameterView] = ChatWithEBOutputView def __init__(self, llm: ERNIEBot): self.llm = llm diff --git a/erniebot-agent/src/erniebot_agent/tools/current_time_tool.py b/erniebot-agent/src/erniebot_agent/tools/current_time_tool.py index 6ab50bf1..7133f5e6 100644 --- a/erniebot-agent/src/erniebot_agent/tools/current_time_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/current_time_tool.py @@ -17,7 +17,7 @@ class CurrentTimeToolOutputView(ToolParameterView): class CurrentTimeTool(Tool): description: str = "CurrentTimeTool 用于获取当前时间" - ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView + output_type: Type[ToolParameterView] = CurrentTimeToolOutputView async def __call__(self) -> Dict[str, str]: return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒")} diff --git a/erniebot-agent/src/erniebot_agent/tools/image_generation_tool.py b/erniebot-agent/src/erniebot_agent/tools/image_generation_tool.py index b97ff1a9..7ae668df 100644 --- a/erniebot-agent/src/erniebot_agent/tools/image_generation_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/image_generation_tool.py @@ -41,7 +41,7 @@ class ImageGenerationOutputView(ToolParameterView): class ImageGenerationTool(Tool): description: str = "AI作图、生成图片、画图的工具" input_type: Type[ToolParameterView] = ImageGenerationInputView - ouptut_type: Type[ToolParameterView] = ImageGenerationOutputView + output_type: Type[ToolParameterView] = ImageGenerationOutputView def __init__( self, diff --git a/erniebot-agent/src/erniebot_agent/tools/langchain_retrieval_tool.py b/erniebot-agent/src/erniebot_agent/tools/langchain_retrieval_tool.py index b4a4bf79..66c285ba 100644 --- a/erniebot-agent/src/erniebot_agent/tools/langchain_retrieval_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/langchain_retrieval_tool.py @@ -38,7 +38,7 @@ def __init__( if input_type is not None: self.input_type = input_type if output_type is not None: - self.ouptut_type = output_type + self.output_type = output_type self.threshold = threshold async def __call__(self, query: str, top_k: int = 3, filters: Optional[Dict[str, Any]] = None): diff --git a/erniebot-agent/src/erniebot_agent/tools/llama_index_retrieval_tool.py b/erniebot-agent/src/erniebot_agent/tools/llama_index_retrieval_tool.py index 4c4d13fa..333e84f7 100644 --- a/erniebot-agent/src/erniebot_agent/tools/llama_index_retrieval_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/llama_index_retrieval_tool.py @@ -38,7 +38,7 @@ def __init__( if input_type is not None: self.input_type = input_type if output_type is not None: - self.ouptut_type = output_type + self.output_type = output_type self.threshold = threshold async def __call__(self, query: str, top_k: int = 3, filters: Optional[Dict[str, Any]] = None): diff --git a/erniebot-agent/src/erniebot_agent/tools/tool_manager.py b/erniebot-agent/src/erniebot_agent/tools/tool_manager.py index e8e44aa6..18578d54 100644 --- a/erniebot-agent/src/erniebot_agent/tools/tool_manager.py +++ b/erniebot-agent/src/erniebot_agent/tools/tool_manager.py @@ -124,7 +124,7 @@ async def create_tool_endpoint(__tool__, inputs): app.add_api_route( f"/erniebot-agent-tools/0.0/{tool_name}", endpoint=func, - response_model=tool.ouptut_type, + response_model=tool.output_type, description=tool.description, operation_id=tool.tool_name, methods=["POST"], diff --git a/erniebot-agent/tests/integration_tests/agents/test_agent_with_plugins.py b/erniebot-agent/tests/integration_tests/agents/test_agent_with_plugins.py index d9935c15..5af50916 100644 --- a/erniebot-agent/tests/integration_tests/agents/test_agent_with_plugins.py +++ b/erniebot-agent/tests/integration_tests/agents/test_agent_with_plugins.py @@ -25,7 +25,7 @@ class TextRepeaterToolOutputView(ToolParameterView): class TextRepeaterTool(Tool): description: str = "TextRepeaterTool用于将输入文件中的前10个字进行指定次数的重复并输出。" input_type: Type[ToolParameterView] = TextRepeaterToolInputView - ouptut_type: Type[ToolParameterView] = TextRepeaterToolOutputView + output_type: Type[ToolParameterView] = TextRepeaterToolOutputView async def __call__(self, input_file_id: str, repeat_times: int) -> Dict[str, Any]: if "" in input_file_id: @@ -79,7 +79,7 @@ class TextRepeaterNoFileToolOutputView(ToolParameterView): class TextRepeaterNoFileTool(Tool): description: str = "TextRepeaterNoFileTool用于将输入文本进行指定次数的重复并输出。" input_type: Type[ToolParameterView] = TextRepeaterNoFileToolInputView - ouptut_type: Type[ToolParameterView] = TextRepeaterNoFileToolOutputView + output_type: Type[ToolParameterView] = TextRepeaterNoFileToolOutputView async def __call__(self, text, repeat_times: int) -> Dict[str, Any]: text *= repeat_times diff --git a/erniebot-agent/tests/integration_tests/agents/test_tool_choice_agent.py b/erniebot-agent/tests/integration_tests/agents/test_tool_choice_agent.py index 83f252e4..c6539db8 100644 --- a/erniebot-agent/tests/integration_tests/agents/test_tool_choice_agent.py +++ b/erniebot-agent/tests/integration_tests/agents/test_tool_choice_agent.py @@ -28,7 +28,7 @@ class WeatherOutput(ToolParameterView): class WeatherTool(Tool): description: str = "获得指定地点的天气" input_type: Type[ToolParameterView] = WeatherInput - ouptut_type: Type[ToolParameterView] = WeatherOutput + output_type: Type[ToolParameterView] = WeatherOutput async def __call__(self, location: str, unit: str = "摄氏度") -> Dict[str, Any]: if location == "烟台": diff --git a/erniebot-agent/tests/unit_tests/testing_utils/components.py b/erniebot-agent/tests/unit_tests/testing_utils/components.py index 2f142009..b3fc2f02 100644 --- a/erniebot-agent/tests/unit_tests/testing_utils/components.py +++ b/erniebot-agent/tests/unit_tests/testing_utils/components.py @@ -54,7 +54,7 @@ class _OutputView(ToolParameterView): description = "该工具原样返回输入字符串" input_type = _InputView - ouptut_type = _OutputView + output_type = _OutputView async def __call__(self, input): return {"identity": input} diff --git a/erniebot-agent/tests/unit_tests/tools/test_tool_manager.py b/erniebot-agent/tests/unit_tests/tools/test_tool_manager.py index b1545ca3..017e1f64 100644 --- a/erniebot-agent/tests/unit_tests/tools/test_tool_manager.py +++ b/erniebot-agent/tests/unit_tests/tools/test_tool_manager.py @@ -78,7 +78,7 @@ async def test_plugin_schema(self): current_time = model_fields["current_time"] self.assertEqual(current_time.annotation, str) self.assertEqual( - current_time.description, CurrentTimeTool.ouptut_type.model_fields["current_time"].description + current_time.description, CurrentTimeTool.output_type.model_fields["current_time"].description ) From 58a65f27824afb32cacd61209a6e2fd940b64f0a Mon Sep 17 00:00:00 2001 From: wj-Mcat <1435130236@qq.com> Date: Fri, 12 Apr 2024 19:41:26 +0800 Subject: [PATCH 3/3] fix lint --- erniebot-agent/src/erniebot_agent/tools/remote_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erniebot-agent/src/erniebot_agent/tools/remote_tool.py b/erniebot-agent/src/erniebot_agent/tools/remote_tool.py index a30a3ae9..da5ffec6 100644 --- a/erniebot-agent/src/erniebot_agent/tools/remote_tool.py +++ b/erniebot-agent/src/erniebot_agent/tools/remote_tool.py @@ -1,8 +1,8 @@ from __future__ import annotations -import os import dataclasses import logging +import os from copy import deepcopy from typing import Any, Dict, List, Optional, Type