mirror of
https://github.com/langgenius/dify.git
synced 2024-11-15 19:22:36 +08:00
Merge branch 'fix/chore-fix' into dev/plugin-deploy
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
This commit is contained in:
parent
cc28dafede
commit
59b76900d7
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<g>
|
|
||||||
<path fill="none" d="M0 0h24v24H0z"/>
|
|
||||||
<path d="M16 17v-1h-3v-3h3v2h2v2h-1v2h-2v2h-2v-3h2v-1h1zm5 4h-4v-2h2v-2h2v4zM3 3h8v8H3V3zm2 2v4h4V5H5zm8-2h8v8h-8V3zm2 2v4h4V5h-4zM3 13h8v8H3v-8zm2 2v4h4v-4H5zm13-2h3v2h-3v-2zM6 6h2v2H6V6zm0 10h2v2H6v-2zM16 6h2v2h-2V6z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 428 B |
|
@ -1,8 +0,0 @@
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from core.tools.builtin_tool.provider import BuiltinToolProviderController
|
|
||||||
|
|
||||||
|
|
||||||
class QRCodeProvider(BuiltinToolProviderController):
|
|
||||||
def _validate_credentials(self, user_id: str, credentials: dict[str, Any]) -> None:
|
|
||||||
pass
|
|
|
@ -1,14 +0,0 @@
|
||||||
identity:
|
|
||||||
author: Bowen Liang
|
|
||||||
name: qrcode
|
|
||||||
label:
|
|
||||||
en_US: QRCode
|
|
||||||
zh_Hans: 二维码工具
|
|
||||||
pt_BR: QRCode
|
|
||||||
description:
|
|
||||||
en_US: A tool for generating QR code (quick-response code) image.
|
|
||||||
zh_Hans: 一个二维码工具
|
|
||||||
pt_BR: A tool for generating QR code (quick-response code) image.
|
|
||||||
icon: icon.svg
|
|
||||||
tags:
|
|
||||||
- utilities
|
|
|
@ -1,70 +0,0 @@
|
||||||
import io
|
|
||||||
import logging
|
|
||||||
from typing import Any, Union
|
|
||||||
|
|
||||||
from qrcode.constants import ERROR_CORRECT_H, ERROR_CORRECT_L, ERROR_CORRECT_M, ERROR_CORRECT_Q
|
|
||||||
from qrcode.image.base import BaseImage
|
|
||||||
from qrcode.image.pure import PyPNGImage
|
|
||||||
from qrcode.main import QRCode
|
|
||||||
|
|
||||||
from core.tools.builtin_tool.tool import BuiltinTool
|
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
|
||||||
|
|
||||||
|
|
||||||
class QRCodeGeneratorTool(BuiltinTool):
|
|
||||||
error_correction_levels: dict[str, int] = {
|
|
||||||
"L": ERROR_CORRECT_L, # <=7%
|
|
||||||
"M": ERROR_CORRECT_M, # <=15%
|
|
||||||
"Q": ERROR_CORRECT_Q, # <=25%
|
|
||||||
"H": ERROR_CORRECT_H, # <=30%
|
|
||||||
}
|
|
||||||
|
|
||||||
def _invoke(
|
|
||||||
self,
|
|
||||||
user_id: str,
|
|
||||||
tool_parameters: dict[str, Any],
|
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
|
||||||
"""
|
|
||||||
invoke tools
|
|
||||||
"""
|
|
||||||
# get text content
|
|
||||||
content = tool_parameters.get("content", "")
|
|
||||||
if not content:
|
|
||||||
return self.create_text_message("Invalid parameter content")
|
|
||||||
|
|
||||||
# get border size
|
|
||||||
border = tool_parameters.get("border", 0)
|
|
||||||
if border < 0 or border > 100:
|
|
||||||
return self.create_text_message("Invalid parameter border")
|
|
||||||
|
|
||||||
# get error_correction
|
|
||||||
error_correction = tool_parameters.get("error_correction", "")
|
|
||||||
if error_correction not in self.error_correction_levels:
|
|
||||||
return self.create_text_message("Invalid parameter error_correction")
|
|
||||||
|
|
||||||
try:
|
|
||||||
image = self._generate_qrcode(content, border, error_correction)
|
|
||||||
image_bytes = self._image_to_byte_array(image)
|
|
||||||
return self.create_blob_message(
|
|
||||||
blob=image_bytes, meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
logging.exception(f"Failed to generate QR code for content: {content}")
|
|
||||||
return self.create_text_message("Failed to generate QR code")
|
|
||||||
|
|
||||||
def _generate_qrcode(self, content: str, border: int, error_correction: str) -> BaseImage:
|
|
||||||
qr = QRCode(
|
|
||||||
image_factory=PyPNGImage,
|
|
||||||
error_correction=self.error_correction_levels.get(error_correction),
|
|
||||||
border=border,
|
|
||||||
)
|
|
||||||
qr.add_data(data=content)
|
|
||||||
qr.make(fit=True)
|
|
||||||
img = qr.make_image()
|
|
||||||
return img
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _image_to_byte_array(image: BaseImage) -> bytes:
|
|
||||||
byte_stream = io.BytesIO()
|
|
||||||
image.save(byte_stream)
|
|
||||||
return byte_stream.getvalue()
|
|
|
@ -1,76 +0,0 @@
|
||||||
identity:
|
|
||||||
name: qrcode_generator
|
|
||||||
author: Bowen Liang
|
|
||||||
label:
|
|
||||||
en_US: Generate QR Code
|
|
||||||
zh_Hans: 生成二维码
|
|
||||||
pt_BR: Generate QR Code
|
|
||||||
description:
|
|
||||||
human:
|
|
||||||
en_US: A tool for generating QR code image
|
|
||||||
zh_Hans: 一个用于生成二维码的工具
|
|
||||||
pt_BR: A tool for generating QR code image
|
|
||||||
llm: A tool for generating QR code image
|
|
||||||
parameters:
|
|
||||||
- name: content
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
label:
|
|
||||||
en_US: content text for QR code
|
|
||||||
zh_Hans: 二维码文本内容
|
|
||||||
pt_BR: content text for QR code
|
|
||||||
human_description:
|
|
||||||
en_US: content text for QR code
|
|
||||||
zh_Hans: 二维码文本内容
|
|
||||||
pt_BR: 二维码文本内容
|
|
||||||
form: llm
|
|
||||||
- name: error_correction
|
|
||||||
type: select
|
|
||||||
required: true
|
|
||||||
default: M
|
|
||||||
label:
|
|
||||||
en_US: Error Correction
|
|
||||||
zh_Hans: 容错等级
|
|
||||||
pt_BR: Error Correction
|
|
||||||
human_description:
|
|
||||||
en_US: Error Correction in L, M, Q or H, from low to high, the bigger size of generated QR code with the better error correction effect
|
|
||||||
zh_Hans: 容错等级,可设置为低、中、偏高或高,从低到高,生成的二维码越大且容错效果越好
|
|
||||||
pt_BR: Error Correction in L, M, Q or H, from low to high, the bigger size of generated QR code with the better error correction effect
|
|
||||||
options:
|
|
||||||
- value: L
|
|
||||||
label:
|
|
||||||
en_US: Low
|
|
||||||
zh_Hans: 低
|
|
||||||
pt_BR: Low
|
|
||||||
- value: M
|
|
||||||
label:
|
|
||||||
en_US: Medium
|
|
||||||
zh_Hans: 中
|
|
||||||
pt_BR: Medium
|
|
||||||
- value: Q
|
|
||||||
label:
|
|
||||||
en_US: Quartile
|
|
||||||
zh_Hans: 偏高
|
|
||||||
pt_BR: Quartile
|
|
||||||
- value: H
|
|
||||||
label:
|
|
||||||
en_US: High
|
|
||||||
zh_Hans: 高
|
|
||||||
pt_BR: High
|
|
||||||
form: form
|
|
||||||
- name: border
|
|
||||||
type: number
|
|
||||||
required: true
|
|
||||||
default: 2
|
|
||||||
min: 0
|
|
||||||
max: 100
|
|
||||||
label:
|
|
||||||
en_US: border size
|
|
||||||
zh_Hans: 边框粗细
|
|
||||||
pt_BR: border size
|
|
||||||
human_description:
|
|
||||||
en_US: border size(default to 2)
|
|
||||||
zh_Hans: 边框粗细的格数(默认为2)
|
|
||||||
pt_BR: border size(default to 2)
|
|
||||||
llm: border size, default to 2
|
|
||||||
form: form
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from pytz import timezone as pytz_timezone
|
from pytz import timezone as pytz_timezone
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ class CurrentTimeTool(BuiltinTool):
|
||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
tool_parameters: dict[str, Any],
|
tool_parameters: dict[str, Any],
|
||||||
|
conversation_id: Optional[str] = None,
|
||||||
|
app_id: Optional[str] = None,
|
||||||
|
message_id: Optional[str] = None,
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||||
"""
|
"""
|
||||||
invoke tools
|
invoke tools
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ class LocaltimeToTimestampTool(BuiltinTool):
|
||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
tool_parameters: dict[str, Any],
|
tool_parameters: dict[str, Any],
|
||||||
|
conversation_id: Optional[str] = None,
|
||||||
|
app_id: Optional[str] = None,
|
||||||
|
message_id: Optional[str] = None,
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||||
"""
|
"""
|
||||||
Convert localtime to timestamp
|
Convert localtime to timestamp
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ class TimestampToLocaltimeTool(BuiltinTool):
|
||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
tool_parameters: dict[str, Any],
|
tool_parameters: dict[str, Any],
|
||||||
|
conversation_id: Optional[str] = None,
|
||||||
|
app_id: Optional[str] = None,
|
||||||
|
message_id: Optional[str] = None,
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||||
"""
|
"""
|
||||||
Convert timestamp to localtime
|
Convert timestamp to localtime
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ class TimezoneConversionTool(BuiltinTool):
|
||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
tool_parameters: dict[str, Any],
|
tool_parameters: dict[str, Any],
|
||||||
|
conversation_id: Optional[str] = None,
|
||||||
|
app_id: Optional[str] = None,
|
||||||
|
message_id: Optional[str] = None,
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||||
"""
|
"""
|
||||||
Convert time to equivalent time zone
|
Convert time to equivalent time zone
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import calendar
|
import calendar
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from core.tools.builtin_tool.tool import BuiltinTool
|
from core.tools.builtin_tool.tool import BuiltinTool
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
|
@ -11,6 +11,9 @@ class WeekdayTool(BuiltinTool):
|
||||||
self,
|
self,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
tool_parameters: dict[str, Any],
|
tool_parameters: dict[str, Any],
|
||||||
|
conversation_id: Optional[str] = None,
|
||||||
|
app_id: Optional[str] = None,
|
||||||
|
message_id: Optional[str] = None,
|
||||||
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
|
||||||
"""
|
"""
|
||||||
Calculate the day of the week for a given date
|
Calculate the day of the week for a given date
|
||||||
|
|
|
@ -90,14 +90,16 @@ class ToolEngine:
|
||||||
conversation_id=message.conversation_id,
|
conversation_id=message.conversation_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
message_list = list(messages)
|
||||||
|
|
||||||
# extract binary data from tool invoke message
|
# extract binary data from tool invoke message
|
||||||
binary_files = ToolEngine._extract_tool_response_binary(messages)
|
binary_files = ToolEngine._extract_tool_response_binary_and_text(message_list)
|
||||||
# create message file
|
# create message file
|
||||||
message_files = ToolEngine._create_message_files(
|
message_files = ToolEngine._create_message_files(
|
||||||
tool_messages=binary_files, agent_message=message, invoke_from=invoke_from, user_id=user_id
|
tool_messages=binary_files, agent_message=message, invoke_from=invoke_from, user_id=user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
plain_text = ToolEngine._convert_tool_response_to_str(messages)
|
plain_text = ToolEngine._convert_tool_response_to_str(message_list)
|
||||||
|
|
||||||
meta = invocation_meta_dict["meta"]
|
meta = invocation_meta_dict["meta"]
|
||||||
|
|
||||||
|
@ -219,7 +221,7 @@ class ToolEngine:
|
||||||
yield meta
|
yield meta
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _convert_tool_response_to_str(tool_response: Generator[ToolInvokeMessage, None, None]) -> str:
|
def _convert_tool_response_to_str(tool_response: list[ToolInvokeMessage]) -> str:
|
||||||
"""
|
"""
|
||||||
Handle tool response
|
Handle tool response
|
||||||
"""
|
"""
|
||||||
|
@ -246,8 +248,8 @@ class ToolEngine:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_tool_response_binary(
|
def _extract_tool_response_binary_and_text(
|
||||||
tool_response: Generator[ToolInvokeMessage, None, None],
|
tool_response: list[ToolInvokeMessage],
|
||||||
) -> Generator[ToolInvokeMessageBinary, None, None]:
|
) -> Generator[ToolInvokeMessageBinary, None, None]:
|
||||||
"""
|
"""
|
||||||
Extract tool response binary
|
Extract tool response binary
|
||||||
|
|
32676
web/pnpm-lock.yaml
32676
web/pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user