Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add app-id variable to headers #339

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/modules/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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秒")}
Expand Down Expand Up @@ -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秒)}
Expand Down
4 changes: 2 additions & 2 deletions erniebot-agent/cookbook/function_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions erniebot-agent/cookbook/local_tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions erniebot-agent/src/erniebot_agent/tools/baizhong_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions erniebot-agent/src/erniebot_agent/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {}

Expand Down
2 changes: 1 addition & 1 deletion erniebot-agent/src/erniebot_agent/tools/calculator_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion erniebot-agent/src/erniebot_agent/tools/chat_with_eb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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秒")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions erniebot-agent/src/erniebot_agent/tools/remote_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import logging
import os
from copy import deepcopy
from typing import Any, Dict, List, Optional, Type

Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion erniebot-agent/src/erniebot_agent/tools/tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<split>" in input_file_id:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "烟台":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion erniebot-agent/tests/unit_tests/tools/test_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down
Loading