diff --git a/api/core/tools/provider/builtin/aliyuque/tools/base.py b/api/core/tools/provider/builtin/aliyuque/tools/base.py index fb7e219bff..edfb9fea8e 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/base.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/base.py @@ -1,10 +1,3 @@ -""" -语雀客户端 -""" - -__author__ = "佐井" -__created__ = "2024-06-01 09:45:20" - from typing import Any import requests @@ -29,14 +22,13 @@ class AliYuqueTool: session = requests.Session() session.headers.update({"accept": "application/json", "X-Auth-Token": token}) new_params = {**tool_parameters} - # 找出需要替换的变量 + replacements = {k: v for k, v in new_params.items() if f"{{{k}}}" in path} - # 替换 path 中的变量 for key, value in replacements.items(): path = path.replace(f"{{{key}}}", str(value)) - del new_params[key] # 从 kwargs 中删除已经替换的变量 - # 请求接口 + del new_params[key] + if method.upper() in {"POST", "PUT"}: session.headers.update( { diff --git a/api/core/tools/provider/builtin/aliyuque/tools/create_document.py b/api/core/tools/provider/builtin/aliyuque/tools/create_document.py index feadc29258..01080fd1d5 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/create_document.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/create_document.py @@ -1,10 +1,3 @@ -""" -创建文档 -""" - -__author__ = "佐井" -__created__ = "2024-06-01 10:45:20" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml index b9d1c60327..6ac8ae6696 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml @@ -13,7 +13,7 @@ description: parameters: - name: book_id - type: number + type: string required: true form: llm label: diff --git a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py index 74c731a944..84237cec30 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py @@ -1,11 +1,3 @@ -#!/usr/bin/env python3 -""" -删除文档 -""" - -__author__ = "佐井" -__created__ = "2024-09-17 22:04" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml index 87372c5350..dddd62d304 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml @@ -13,7 +13,7 @@ description: parameters: - name: book_id - type: number + type: string required: true form: llm label: diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py index 02bf603a24..c23d30059a 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py @@ -1,10 +1,3 @@ -""" -获取知识库首页 -""" - -__author__ = "佐井" -__created__ = "2024-06-01 22:57:14" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py index fcfe449c6d..36f8c10d6f 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py @@ -1,11 +1,3 @@ -#!/usr/bin/env python3 -""" -获取知识库目录 -""" - -__author__ = "佐井" -__created__ = "2024-09-17 15:17:11" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml index 0c2bd22132..0a481b59eb 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml @@ -13,7 +13,7 @@ description: parameters: - name: book_id - type: number + type: string required: true form: llm label: diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py index 1e70593879..a69bf121f7 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py @@ -1,10 +1,3 @@ -""" -获取文档 -""" - -__author__ = "佐井" -__created__ = "2024-06-02 07:11:45" - import json from typing import Any, Union from urllib.parse import urlparse @@ -37,7 +30,6 @@ class AliYuqueDescribeDocumentContentTool(AliYuqueTool, BuiltinTool): book_slug = path_parts[-2] group_id = path_parts[-3] - # 1. 请求首页信息,获取book_id new_params["group_login"] = group_id new_params["book_slug"] = book_slug index_page = json.loads( @@ -46,7 +38,7 @@ class AliYuqueDescribeDocumentContentTool(AliYuqueTool, BuiltinTool): book_id = index_page.get("data", {}).get("book", {}).get("id") if not book_id: raise Exception(f"can not parse book_id from {index_page}") - # 2. 获取文档内容 + new_params["book_id"] = book_id new_params["id"] = doc_id data = self.request("GET", token, new_params, "/api/v2/repos/{book_id}/docs/{id}") diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py index ed1b2a8643..7a45684bed 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py @@ -1,10 +1,3 @@ -""" -获取文档 -""" - -__author__ = "佐井" -__created__ = "2024-06-01 10:45:20" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml index 5156345d71..0b14c1afba 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml @@ -14,7 +14,7 @@ description: parameters: - name: book_id - type: number + type: string required: true form: llm label: diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py index 932559445e..ca0a3909f8 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py @@ -1,11 +1,3 @@ -#!/usr/bin/env python3 -""" -获取知识库目录 -""" - -__author__ = "佐井" -__created__ = "2024-09-17 15:17:11" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml index f0c0024f17..f85970348b 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml @@ -13,7 +13,7 @@ description: parameters: - name: book_id - type: number + type: string required: true form: llm label: diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_document.py b/api/core/tools/provider/builtin/aliyuque/tools/update_document.py index 0c6e0205e1..d7eba46ad9 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/update_document.py +++ b/api/core/tools/provider/builtin/aliyuque/tools/update_document.py @@ -1,10 +1,3 @@ -""" -更新文档 -""" - -__author__ = "佐井" -__created__ = "2024-06-19 16:50:07" - from typing import Any, Union from core.tools.entities.tool_entities import ToolInvokeMessage diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml index 87f88c9b1b..c2da6b179a 100644 --- a/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml +++ b/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml @@ -12,7 +12,7 @@ description: llm: Update doc in a knowledge base via ID/path. parameters: - name: book_id - type: number + type: string required: true form: llm label: