mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-25 05:25:23 -04:00
refactor: update type hints to use union syntax and improve import order
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from dify_plugin import Plugin, DifyPluginEnv
|
||||
from dify_plugin import DifyPluginEnv, Plugin
|
||||
|
||||
plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=120))
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
plugin.run()
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import json
|
||||
from collections.abc import Generator
|
||||
from datetime import datetime
|
||||
from typing import Any, Generator
|
||||
from typing import Any
|
||||
from urllib.parse import quote
|
||||
|
||||
import requests
|
||||
from dify_plugin.entities.tool import ToolInvokeMessage
|
||||
|
||||
from dify_plugin import Tool
|
||||
from dify_plugin.entities.tool import ToolInvokeMessage
|
||||
|
||||
|
||||
class GithubRepositoriesTool(Tool):
|
||||
@@ -69,4 +72,4 @@ class GithubRepositoriesTool(Tool):
|
||||
else:
|
||||
yield self.create_text_message(response.json().get("message"))
|
||||
except Exception as e:
|
||||
yield self.create_text_message("GitHub API Key and Api Version is invalid. {}".format(e))
|
||||
yield self.create_text_message(f"GitHub API Key and Api Version is invalid. {e}")
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import base64
|
||||
from typing import Any, Generator
|
||||
from collections.abc import Generator
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
from dify_plugin import Tool
|
||||
from dify_plugin.entities.tool import ToolInvokeMessage
|
||||
from dify_plugin.errors.model import InvokeError
|
||||
|
||||
|
||||
class GithubRepositoryReadmeTool(Tool):
|
||||
def _invoke(
|
||||
self, tool_parameters: dict[str, Any]
|
||||
) -> Generator[ToolInvokeMessage, None, None]:
|
||||
def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage, None, None]:
|
||||
"""
|
||||
invoke tools
|
||||
"""
|
||||
@@ -48,14 +48,15 @@ class GithubRepositoryReadmeTool(Tool):
|
||||
)
|
||||
response_data = response.json()
|
||||
if response.status_code == 200:
|
||||
if "base64" != response_data.get("encoding"):
|
||||
if response_data.get("encoding") != "base64":
|
||||
raise InvokeError(
|
||||
f"Can not get base64 encoded readme, response encoding is {response_data.get('encoding')}")
|
||||
f"Can not get base64 encoded readme, response encoding is {response_data.get('encoding')}"
|
||||
)
|
||||
content = response_data.get("content")
|
||||
if not content:
|
||||
raise InvokeError("README content is empty")
|
||||
decoded_bytes = base64.b64decode(content)
|
||||
decoded_str = decoded_bytes.decode('utf-8')
|
||||
decoded_str = decoded_bytes.decode("utf-8")
|
||||
yield self.create_text_message(decoded_str)
|
||||
else:
|
||||
raise InvokeError(f"Request failed: {response.status_code} {response_data.get('message')}")
|
||||
|
||||
Reference in New Issue
Block a user