Skip to content

Commit

Permalink
feat: add lark tools
Browse files Browse the repository at this point in the history
  • Loading branch information
黎斌 committed Nov 4, 2024
1 parent f5d1c7c commit 15b0d3c
Show file tree
Hide file tree
Showing 113 changed files with 4,693 additions and 18 deletions.
7 changes: 7 additions & 0 deletions api/core/tools/provider/_position.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
- feishu_task
- feishu_calendar
- feishu_spreadsheet
- lark_base
- lark_document
- lark_message_and_group
- lark_wiki
- lark_task
- lark_calendar
- lark_spreadsheet
- slack
- twilio
- wecom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ parameters:
Page size, default value: 20, maximum value: 100.
zh_Hans: 分页大小,默认值:20,最大值:100。
llm_description: 分页大小,默认值:20,最大值:100。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ parameters:
Page size, default value: 20, maximum value: 500.
zh_Hans: 分页大小,默认值:20,最大值:500。
llm_description: 分页大小,默认值:20,最大值:500。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ parameters:
en_US: The page size, i.e., the number of data entries returned in a single request. The default value is 50, and the value range is [50,1000].
zh_Hans: 分页大小,即单次请求所返回的数据条目数。默认值为 50,取值范围为 [50,1000]。
llm_description: 分页大小,即单次请求所返回的数据条目数。默认值为 50,取值范围为 [50,1000]。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ parameters:
en_US: The page size, i.e., the number of data entries returned in a single request. The default value is 20, and the value range is [10,100].
zh_Hans: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [10,100]。
llm_description: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [10,100]。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ parameters:
en_US: Paging size, the default and maximum value is 500.
zh_Hans: 分页大小, 默认值和最大值为 500。
llm_description: 分页大小, 表示一次请求最多返回多少条数据,默认值和最大值为 500。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ parameters:
en_US: The page size, i.e., the number of data entries returned in a single request. The default value is 20, and the value range is [1,50].
zh_Hans: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [1,50]。
llm_description: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [1,50]。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ parameters:
en_US: The page size, i.e., the number of data entries returned in a single request. The default value is 20, and the value range is [1,50].
zh_Hans: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [1,50]。
llm_description: 分页大小,即单次请求所返回的数据条目数。默认值为 20,取值范围为 [1,50]。
form: llm
form: form

- name: page_token
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parameters:
en_US: Number of columns to add, range (0-5000].
zh_Hans: 要增加的列数,范围(0-5000]。
llm_description: 要增加的列数,范围(0-5000]。
form: llm
form: form

- name: values
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parameters:
en_US: Number of rows to add, range (0-5000].
zh_Hans: 要增加行数,范围(0-5000]。
llm_description: 要增加行数,范围(0-5000]。
form: llm
form: form

- name: values
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ parameters:
en_US: Starting column number, starting from 1.
zh_Hans: 起始列号,从 1 开始。
llm_description: 起始列号,从 1 开始。
form: llm
form: form

- name: num_cols
type: number
Expand All @@ -94,4 +94,4 @@ parameters:
en_US: Number of columns to read.
zh_Hans: 读取列数
llm_description: 读取列数
form: llm
form: form
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ parameters:
en_US: Starting row number, starting from 1.
zh_Hans: 起始行号,从 1 开始。
llm_description: 起始行号,从 1 开始。
form: llm
form: form

- name: num_rows
type: number
Expand All @@ -94,4 +94,4 @@ parameters:
en_US: Number of rows to read.
zh_Hans: 读取行数
llm_description: 读取行数
form: llm
form: form
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ parameters:
en_US: Starting row number, starting from 1.
zh_Hans: 起始行号,从 1 开始。
llm_description: 起始行号,从 1 开始。
form: llm
form: form

- name: num_rows
type: number
Expand All @@ -94,7 +94,7 @@ parameters:
en_US: Number of rows to read.
zh_Hans: 读取行数
llm_description: 读取行数
form: llm
form: form

- name: range
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ parameters:
en_US: The size of each page, with a maximum value of 50.
zh_Hans: 分页大小,最大值 50。
llm_description: 分页大小,最大值 50。
form: llm
form: form

- name: page_token
type: string
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions api/core/tools/provider/builtin/lark_base/lark_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
from core.tools.utils.lark_api_utils import lark_auth


class LarkBaseProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict) -> None:
lark_auth(credentials)
36 changes: 36 additions & 0 deletions api/core/tools/provider/builtin/lark_base/lark_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
identity:
author: Doug Lea
name: lark_base
label:
en_US: Lark Base
zh_Hans: Lark 多维表格
description:
en_US: |
Lark base, requires the following permissions: bitable:app.
zh_Hans: |
Lark 多维表格,需要开通以下权限: bitable:app。
icon: icon.png
tags:
- social
- productivity
credentials_for_provider:
app_id:
type: text-input
required: true
label:
en_US: APP ID
placeholder:
en_US: Please input your Lark app id
zh_Hans: 请输入你的 Lark app id
help:
en_US: Get your app_id and app_secret from Lark
zh_Hans: 从 Lark 获取您的 app_id 和 app_secret
url: https://open.larksuite.com/app
app_secret:
type: secret-input
required: true
label:
en_US: APP Secret
placeholder:
en_US: Please input your app secret
zh_Hans: 请输入你的 Lark app secret
21 changes: 21 additions & 0 deletions api/core/tools/provider/builtin/lark_base/tools/add_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Any

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.lark_api_utils import LarkRequest


class AddRecordsTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = LarkRequest(app_id, app_secret)

app_token = tool_parameters.get("app_token")
table_id = tool_parameters.get("table_id")
table_name = tool_parameters.get("table_name")
records = tool_parameters.get("records")
user_id_type = tool_parameters.get("user_id_type", "open_id")

res = client.add_records(app_token, table_id, table_name, records, user_id_type)
return self.create_json_message(res)
91 changes: 91 additions & 0 deletions api/core/tools/provider/builtin/lark_base/tools/add_records.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
identity:
name: add_records
author: Doug Lea
label:
en_US: Add Records
zh_Hans: 新增多条记录
description:
human:
en_US: Add Multiple Records to Multidimensional Table
zh_Hans: 在多维表格数据表中新增多条记录
llm: A tool for adding multiple records to a multidimensional table. (在多维表格数据表中新增多条记录)
parameters:
- name: app_token
type: string
required: true
label:
en_US: app_token
zh_Hans: app_token
human_description:
en_US: Unique identifier for the multidimensional table, supports inputting document URL.
zh_Hans: 多维表格的唯一标识符,支持输入文档 URL。
llm_description: 多维表格的唯一标识符,支持输入文档 URL。
form: llm

- name: table_id
type: string
required: false
label:
en_US: table_id
zh_Hans: table_id
human_description:
en_US: Unique identifier for the multidimensional table data, either table_id or table_name must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的唯一标识符,table_id 和 table_name 至少需要提供一个,不能同时为空。
form: llm

- name: table_name
type: string
required: false
label:
en_US: table_name
zh_Hans: table_name
human_description:
en_US: Name of the multidimensional table data, either table_name or table_id must be provided, cannot be empty simultaneously.
zh_Hans: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
llm_description: 多维表格数据表的名称,table_name 和 table_id 至少需要提供一个,不能同时为空。
form: llm

- name: records
type: string
required: true
label:
en_US: records
zh_Hans: 记录列表
human_description:
en_US: |
List of records to be added in this request. Example value: [{"multi-line-text":"text content","single_select":"option 1","date":1674206443000}]
For supported field types, refer to the integration guide (https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification). For data structures of different field types, refer to the data structure overview (https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure).
zh_Hans: |
本次请求将要新增的记录列表,示例值:[{"多行文本":"文本内容","单选":"选项 1","日期":1674206443000}]。
当前接口支持的字段类型请参考接入指南(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification),不同类型字段的数据结构请参考数据结构概述(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure)。
llm_description: |
本次请求将要新增的记录列表,示例值:[{"多行文本":"文本内容","单选":"选项 1","日期":1674206443000}]。
当前接口支持的字段类型请参考接入指南(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/notification),不同类型字段的数据结构请参考数据结构概述(https://open.larkoffice.com/document/server-docs/docs/bitable-v1/bitable-structure)。
form: llm

- name: user_id_type
type: select
required: false
options:
- value: open_id
label:
en_US: open_id
zh_Hans: open_id
- value: union_id
label:
en_US: union_id
zh_Hans: union_id
- value: user_id
label:
en_US: user_id
zh_Hans: user_id
default: "open_id"
label:
en_US: user_id_type
zh_Hans: 用户 ID 类型
human_description:
en_US: User ID type, optional values are open_id, union_id, user_id, with a default value of open_id.
zh_Hans: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
llm_description: 用户 ID 类型,可选值有 open_id、union_id、user_id,默认值为 open_id。
form: form
18 changes: 18 additions & 0 deletions api/core/tools/provider/builtin/lark_base/tools/create_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.lark_api_utils import LarkRequest


class CreateBaseTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = LarkRequest(app_id, app_secret)

name = tool_parameters.get("name")
folder_token = tool_parameters.get("folder_token")

res = client.create_base(name, folder_token)
return self.create_json_message(res)
42 changes: 42 additions & 0 deletions api/core/tools/provider/builtin/lark_base/tools/create_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
identity:
name: create_base
author: Doug Lea
label:
en_US: Create Base
zh_Hans: 创建多维表格
description:
human:
en_US: Create Multidimensional Table in Specified Directory
zh_Hans: 在指定目录下创建多维表格
llm: A tool for creating a multidimensional table in a specified directory. (在指定目录下创建多维表格)
parameters:
- name: name
type: string
required: false
label:
en_US: name
zh_Hans: 多维表格 App 名字
human_description:
en_US: |
Name of the multidimensional table App. Example value: "A new multidimensional table".
zh_Hans: 多维表格 App 名字,示例值:"一篇新的多维表格"。
llm_description: 多维表格 App 名字,示例值:"一篇新的多维表格"。
form: llm

- name: folder_token
type: string
required: false
label:
en_US: folder_token
zh_Hans: 多维表格 App 归属文件夹
human_description:
en_US: |
Folder where the multidimensional table App belongs. Default is empty, meaning the table will be created in the root directory of the cloud space. Example values: Lf8uf6BoAlWkUfdGtpMjUV0PpZd or https://lark-japan.jp.larksuite.com/drive/folder/Lf8uf6BoAlWkUfdGtpMjUV0PpZd.
The folder_token must be an existing folder and supports inputting folder token or folder URL.
zh_Hans: |
多维表格 App 归属文件夹。默认为空,表示多维表格将被创建在云空间根目录。示例值: Lf8uf6BoAlWkUfdGtpMjUV0PpZd 或者 https://lark-japan.jp.larksuite.com/drive/folder/Lf8uf6BoAlWkUfdGtpMjUV0PpZd。
folder_token 必须是已存在的文件夹,支持输入文件夹 token 或者文件夹 URL。
llm_description: |
多维表格 App 归属文件夹。默认为空,表示多维表格将被创建在云空间根目录。示例值: Lf8uf6BoAlWkUfdGtpMjUV0PpZd 或者 https://lark-japan.jp.larksuite.com/drive/folder/Lf8uf6BoAlWkUfdGtpMjUV0PpZd。
folder_token 必须是已存在的文件夹,支持输入文件夹 token 或者文件夹 URL。
form: llm
20 changes: 20 additions & 0 deletions api/core/tools/provider/builtin/lark_base/tools/create_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any

from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.utils.lark_api_utils import LarkRequest


class CreateTableTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
app_id = self.runtime.credentials.get("app_id")
app_secret = self.runtime.credentials.get("app_secret")
client = LarkRequest(app_id, app_secret)

app_token = tool_parameters.get("app_token")
table_name = tool_parameters.get("table_name")
default_view_name = tool_parameters.get("default_view_name")
fields = tool_parameters.get("fields")

res = client.create_table(app_token, table_name, default_view_name, fields)
return self.create_json_message(res)
Loading

0 comments on commit 15b0d3c

Please sign in to comment.