-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a new built-in tool of Yunzhijia Group Robot
- Loading branch information
LuZhuJun
committed
Dec 19, 2024
1 parent
56cfdce
commit cb0aeb7
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
api/core/tools/provider/builtin/yunzhijia/tools/yunzhijia_group_robot.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,41 @@ | ||
from typing import Any, Union | ||
|
||
import httpx | ||
|
||
from core.tools.entities.tool_entities import ToolInvokeMessage | ||
from core.tools.tool.builtin_tool import BuiltinTool | ||
|
||
|
||
class YunzhijiaGroupRobotTool(BuiltinTool): | ||
def _invoke( | ||
self, user_id: str, tool_parameters: dict[str, Any] | ||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]: | ||
""" | ||
invoke tools | ||
""" | ||
content = tool_parameters.get("content", "") | ||
if not content: | ||
return self.create_text_message("Invalid parameter content") | ||
|
||
webhook_url = tool_parameters.get("webhook_url", "") | ||
if not webhook_url: | ||
return self.create_text_message("Invalid parameter webhook_url") | ||
|
||
payload = { | ||
"content": content, | ||
} | ||
headers = { | ||
"Content-Type": "application/json", | ||
} | ||
params = {} | ||
|
||
try: | ||
res = httpx.post(webhook_url, headers=headers, params=params, json=payload) | ||
if res.is_success: | ||
return self.create_text_message("Text message sent successfully") | ||
else: | ||
return self.create_text_message( | ||
f"Failed to send the text message, status code: {res.status_code}, response: {res.text}" | ||
) | ||
except Exception as e: | ||
return self.create_text_message("Failed to send message to group robot. {}".format(e)) |
41 changes: 41 additions & 0 deletions
41
api/core/tools/provider/builtin/yunzhijia/tools/yunzhijia_group_robot.yaml
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,41 @@ | ||
identity: | ||
name: yunzhijia_group_robot | ||
author: Zhujun Lu | ||
label: | ||
en_US: Send Group Robot Message | ||
zh_Hans: 发送群组消息 | ||
pt_BR: Send Group Robot Message | ||
icon: icon.svg | ||
description: | ||
human: | ||
en_US: Sending a group message on Yunzhijia via the webhook of group Robot | ||
zh_Hans: 通过云之家的群组机器人webhook发送群消息 | ||
pt_BR: Sending a group message on Yunzhijia via the webhook of group Robot | ||
llm: A tool for sending messages to a chat group on Yunzhijia(云之家) . | ||
parameters: | ||
- name: webhook_url | ||
type: string | ||
required: true | ||
label: | ||
en_US: Webhook URL | ||
zh_Hans: 群组机器人Webhook | ||
pt_BR: Webhook URL | ||
human_description: | ||
en_US: Webhook URL. | ||
zh_Hans: 群组机器人Webhook | ||
pt_BR: Webhook URL. | ||
llm_description: Webhook URL | ||
form: form | ||
- name: content | ||
type: string | ||
required: true | ||
label: | ||
en_US: content | ||
zh_Hans: 消息内容 | ||
pt_BR: content | ||
human_description: | ||
en_US: Content to sent to the group. | ||
zh_Hans: 群消息文本 | ||
pt_BR: Content to sent to the group. | ||
llm_description: Content of the message | ||
form: llm |
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,6 @@ | ||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController | ||
|
||
|
||
class YunzhijiaProvider(BuiltinToolProviderController): | ||
def _validate_credentials(self, credentials: dict) -> None: | ||
pass |
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,14 @@ | ||
identity: | ||
author: ZhuJun Lu | ||
name: yunzhijia | ||
label: | ||
en_US: CloudHub | ||
zh_Hans: 云之家 | ||
pt_BR: CloudHub | ||
description: | ||
en_US: CloudHub open api | ||
zh_Hans: 云之家相关开放能力 | ||
pt_BR: CloudHub open api | ||
icon: icon.jpg | ||
tags: | ||
- social |