Skip to content

Commit c97b9f9

Browse files
authored
add app-id variable to headers (#339)
* add app-id variable to headers * update output type * fix lint
1 parent 6910387 commit c97b9f9

18 files changed

+28
-24
lines changed

docs/modules/tools.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Tool 模块分为 LocalTool 和 RemoteTool 两类,LocalTool 运行在本地的
1717
```python
1818
class CurrentTimeTool(Tool):
1919
description: str = "CurrentTimeTool 用于获取当前时间"
20-
ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView
20+
output_type: Type[ToolParameterView] = CurrentTimeToolOutputView
2121

2222
async def __call__(self) -> Dict[str, str]:
2323
return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒")}
@@ -103,7 +103,7 @@ class CurrentTimeToolOutputView(ToolParameterView):
103103

104104
class CurrentTimeTool(Tool):
105105
description: str = "CurrentTimeTool 用于获取当前时间"
106-
ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView
106+
output_type: Type[ToolParameterView] = CurrentTimeToolOutputView
107107

108108
async def __call__(self) -> Dict[str, str]:
109109
return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒)}

erniebot-agent/cookbook/function_agent.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"class ChatWithEB(Tool):\n",
102102
" description: str = \"ChatWithEB是一款根据用户的提供的单词,获取一个具体的单词描述、翻译以及例句的工具\"\n",
103103
" input_type: Type[ToolParameterView] = ChatWithEBInputView\n",
104-
" ouptut_type: Type[ToolParameterView] = ChatWithEBOutputView\n",
104+
" output_type: Type[ToolParameterView] = ChatWithEBOutputView\n",
105105
"\n",
106106
" def __init__(self, llm: ERNIEBot):\n",
107107
" self.llm = llm\n",
@@ -143,7 +143,7 @@
143143
"class AddWordTool(Tool):\n",
144144
" description: str = \"添加单词以及它的详细解释到词库当中\"\n",
145145
" input_type: Type[ToolParameterView] = AddWordInput\n",
146-
" ouptut_type: Type[ToolParameterView] = AddWordOutput\n",
146+
" output_type: Type[ToolParameterView] = AddWordOutput\n",
147147
"\n",
148148
" def __init__(self) -> None:\n",
149149
" self.word_books = {}\n",

erniebot-agent/cookbook/local_tool.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"class AddWordTool(Tool):\n",
8888
" description: str = \"添加单词到词库当中\"\n",
8989
" input_type: Type[ToolParameterView] = AddWordInput\n",
90-
" ouptut_type: Type[ToolParameterView] = AddWordOutput\n",
90+
" output_type: Type[ToolParameterView] = AddWordOutput\n",
9191
"\n",
9292
" def __init__(self) -> None:\n",
9393
" self.word_books = {}\n",
@@ -183,7 +183,7 @@
183183
"class AddWordTool(Tool):\n",
184184
" description: str = \"添加单词到词库当中\"\n",
185185
" input_type: Type[ToolParameterView] = AddWordInput\n",
186-
" ouptut_type: Type[ToolParameterView] = AddWordOutput\n",
186+
" output_type: Type[ToolParameterView] = AddWordOutput\n",
187187
"\n",
188188
" def __init__(self, file: str):\n",
189189
" self.file = file\n",

erniebot-agent/src/erniebot_agent/agents/function_agent_with_retrieval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class KnowledgeBaseTool(Tool):
6767
tool_name: str = "KnowledgeBaseTool"
6868
description: str = "在知识库中检索与用户输入query相关的段落"
6969
input_type: Type[ToolParameterView] = KnowledgeBaseToolInputView
70-
ouptut_type: Type[ToolParameterView] = KnowledgeBaseToolOutputView
70+
output_type: Type[ToolParameterView] = KnowledgeBaseToolOutputView
7171

7272
def __init__(
7373
self,

erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BaizhongSearchToolOutputView(ToolParameterView):
2828
class BaizhongSearchTool(Tool):
2929
description: str = "在知识库中检索与用户输入query相关的段落"
3030
input_type: Type[ToolParameterView] = BaizhongSearchToolInputView
31-
ouptut_type: Type[ToolParameterView] = BaizhongSearchToolOutputView
31+
output_type: Type[ToolParameterView] = BaizhongSearchToolOutputView
3232

3333
def __init__(
3434
self, description, db, threshold: float = 0.0, input_type=None, output_type=None, examples=None
@@ -40,7 +40,7 @@ def __init__(
4040
if input_type is not None:
4141
self.input_type = input_type
4242
if output_type is not None:
43-
self.ouptut_type = output_type
43+
self.output_type = output_type
4444
if examples is not None:
4545
self.few_shot_examples = examples
4646
self.threshold = threshold

erniebot-agent/src/erniebot_agent/tools/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Tool(BaseTool, ABC):
4545
description: str
4646
name: Optional[str] = None
4747
input_type: Optional[Type[ToolParameterView]] = None
48-
ouptut_type: Optional[Type[ToolParameterView]] = None
48+
output_type: Optional[Type[ToolParameterView]] = None
4949

5050
def __str__(self) -> str:
5151
name = self.name if self.name else self.tool_name
@@ -81,8 +81,8 @@ def function_call_schema(self) -> dict:
8181
else:
8282
inputs["parameters"] = {"type": "object", "properties": {}}
8383

84-
if self.ouptut_type is not None:
85-
inputs["responses"] = self.ouptut_type.function_call_schema()
84+
if self.output_type is not None:
85+
inputs["responses"] = self.output_type.function_call_schema()
8686

8787
return scrub_dict(inputs) or {}
8888

erniebot-agent/src/erniebot_agent/tools/calculator_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CalculatorToolOutputView(ToolParameterView):
2121
class CalculatorTool(Tool):
2222
description: str = "CalculatorTool用于执行数学公式计算"
2323
input_type: Type[ToolParameterView] = CalculatorToolInputView
24-
ouptut_type: Type[ToolParameterView] = CalculatorToolOutputView
24+
output_type: Type[ToolParameterView] = CalculatorToolOutputView
2525

2626
async def __call__(self, math_formula: str) -> Dict[str, float]:
2727
return {"formula_result": eval(math_formula)}

erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ChatWithEB(Tool):
2121
"ChatWithEB是一款根据用户的问题,向EB生成式大语言模型进行提问,并获取EB回答结果的工具。EB一般能解决知识型问答、文本创作、信息查询、信息检索等基础的文本生成和信息检索功能"
2222
)
2323
input_type: Type[ToolParameterView] = ChatWithEBInputView
24-
ouptut_type: Type[ToolParameterView] = ChatWithEBOutputView
24+
output_type: Type[ToolParameterView] = ChatWithEBOutputView
2525

2626
def __init__(self, llm: ERNIEBot):
2727
self.llm = llm

erniebot-agent/src/erniebot_agent/tools/current_time_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CurrentTimeToolOutputView(ToolParameterView):
1717

1818
class CurrentTimeTool(Tool):
1919
description: str = "CurrentTimeTool 用于获取当前时间"
20-
ouptut_type: Type[ToolParameterView] = CurrentTimeToolOutputView
20+
output_type: Type[ToolParameterView] = CurrentTimeToolOutputView
2121

2222
async def __call__(self) -> Dict[str, str]:
2323
return {"current_time": datetime.strftime(datetime.now(), "%Y年%m月%d日 %H时%M分%S秒")}

erniebot-agent/src/erniebot_agent/tools/image_generation_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ImageGenerationOutputView(ToolParameterView):
4141
class ImageGenerationTool(Tool):
4242
description: str = "AI作图、生成图片、画图的工具"
4343
input_type: Type[ToolParameterView] = ImageGenerationInputView
44-
ouptut_type: Type[ToolParameterView] = ImageGenerationOutputView
44+
output_type: Type[ToolParameterView] = ImageGenerationOutputView
4545

4646
def __init__(
4747
self,

erniebot-agent/src/erniebot_agent/tools/langchain_retrieval_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
if input_type is not None:
3939
self.input_type = input_type
4040
if output_type is not None:
41-
self.ouptut_type = output_type
41+
self.output_type = output_type
4242
self.threshold = threshold
4343

4444
async def __call__(self, query: str, top_k: int = 3, filters: Optional[Dict[str, Any]] = None):

erniebot-agent/src/erniebot_agent/tools/llama_index_retrieval_tool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
if input_type is not None:
3939
self.input_type = input_type
4040
if output_type is not None:
41-
self.ouptut_type = output_type
41+
self.output_type = output_type
4242
self.threshold = threshold
4343

4444
async def __call__(self, query: str, top_k: int = 3, filters: Optional[Dict[str, Any]] = None):

erniebot-agent/src/erniebot_agent/tools/remote_tool.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dataclasses
44
import logging
5+
import os
56
from copy import deepcopy
67
from typing import Any, Dict, List, Optional, Type
78

@@ -118,6 +119,9 @@ async def send_request(self, tool_arguments: Dict[str, Any]) -> dict:
118119
headers = deepcopy(self.headers)
119120
headers["Content-Type"] = self.tool_view.parameters_content_type
120121

122+
if "EB_SDK_TRACE_APP_ID" in os.environ:
123+
headers["X-EB-SDK-TRACE-APP-ID"] = os.getenv("EB_SDK_TRACE_APP_ID")
124+
121125
requests_inputs = {
122126
"headers": headers,
123127
}

erniebot-agent/src/erniebot_agent/tools/tool_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def create_tool_endpoint(__tool__, inputs):
124124
app.add_api_route(
125125
f"/erniebot-agent-tools/0.0/{tool_name}",
126126
endpoint=func,
127-
response_model=tool.ouptut_type,
127+
response_model=tool.output_type,
128128
description=tool.description,
129129
operation_id=tool.tool_name,
130130
methods=["POST"],

erniebot-agent/tests/integration_tests/agents/test_agent_with_plugins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TextRepeaterToolOutputView(ToolParameterView):
2525
class TextRepeaterTool(Tool):
2626
description: str = "TextRepeaterTool用于将输入文件中的前10个字进行指定次数的重复并输出。"
2727
input_type: Type[ToolParameterView] = TextRepeaterToolInputView
28-
ouptut_type: Type[ToolParameterView] = TextRepeaterToolOutputView
28+
output_type: Type[ToolParameterView] = TextRepeaterToolOutputView
2929

3030
async def __call__(self, input_file_id: str, repeat_times: int) -> Dict[str, Any]:
3131
if "<split>" in input_file_id:
@@ -79,7 +79,7 @@ class TextRepeaterNoFileToolOutputView(ToolParameterView):
7979
class TextRepeaterNoFileTool(Tool):
8080
description: str = "TextRepeaterNoFileTool用于将输入文本进行指定次数的重复并输出。"
8181
input_type: Type[ToolParameterView] = TextRepeaterNoFileToolInputView
82-
ouptut_type: Type[ToolParameterView] = TextRepeaterNoFileToolOutputView
82+
output_type: Type[ToolParameterView] = TextRepeaterNoFileToolOutputView
8383

8484
async def __call__(self, text, repeat_times: int) -> Dict[str, Any]:
8585
text *= repeat_times

erniebot-agent/tests/integration_tests/agents/test_tool_choice_agent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class WeatherOutput(ToolParameterView):
2828
class WeatherTool(Tool):
2929
description: str = "获得指定地点的天气"
3030
input_type: Type[ToolParameterView] = WeatherInput
31-
ouptut_type: Type[ToolParameterView] = WeatherOutput
31+
output_type: Type[ToolParameterView] = WeatherOutput
3232

3333
async def __call__(self, location: str, unit: str = "摄氏度") -> Dict[str, Any]:
3434
if location == "烟台":

erniebot-agent/tests/unit_tests/testing_utils/components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _OutputView(ToolParameterView):
5454

5555
description = "该工具原样返回输入字符串"
5656
input_type = _InputView
57-
ouptut_type = _OutputView
57+
output_type = _OutputView
5858

5959
async def __call__(self, input):
6060
return {"identity": input}

erniebot-agent/tests/unit_tests/tools/test_tool_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def test_plugin_schema(self):
7878
current_time = model_fields["current_time"]
7979
self.assertEqual(current_time.annotation, str)
8080
self.assertEqual(
81-
current_time.description, CurrentTimeTool.ouptut_type.model_fields["current_time"].description
81+
current_time.description, CurrentTimeTool.output_type.model_fields["current_time"].description
8282
)
8383

8484

0 commit comments

Comments
 (0)