Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
1cf5f510
Unverified
Commit
1cf5f510
authored
Mar 06, 2024
by
Bowen Liang
Committed by
GitHub
Mar 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add qrcode tool for QR code generation (#2699)
parent
526c874c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
1 deletion
+100
-1
_position.yaml
api/core/tools/provider/_position.yaml
+1
-0
icon.svg
api/core/tools/provider/builtin/qrcode/_assets/icon.svg
+8
-0
qrcode.py
api/core/tools/provider/builtin/qrcode/qrcode.py
+16
-0
qrcode.yaml
api/core/tools/provider/builtin/qrcode/qrcode.yaml
+12
-0
qrcode_generator.py
...e/tools/provider/builtin/qrcode/tools/qrcode_generator.py
+35
-0
qrcode_generator.yaml
...tools/provider/builtin/qrcode/tools/qrcode_generator.yaml
+26
-0
requirements.txt
api/requirements.txt
+2
-1
No files found.
api/core/tools/provider/_position.yaml
View file @
1cf5f510
...
...
@@ -18,3 +18,4 @@
-
vectorizer
-
gaode
-
wecom
-
qrcode
api/core/tools/provider/builtin/qrcode/_assets/icon.svg
0 → 100644
View file @
1cf5f510
<?xml version="1.0" encoding="utf-8"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<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>
\ No newline at end of file
api/core/tools/provider/builtin/qrcode/qrcode.py
0 → 100644
View file @
1cf5f510
from
typing
import
Any
from
core.tools.errors
import
ToolProviderCredentialValidationError
from
core.tools.provider.builtin.qrcode.tools.qrcode_generator
import
QRCodeGeneratorTool
from
core.tools.provider.builtin_tool_provider
import
BuiltinToolProviderController
class
QRCodeProvider
(
BuiltinToolProviderController
):
def
_validate_credentials
(
self
,
credentials
:
dict
[
str
,
Any
])
->
None
:
try
:
QRCodeGeneratorTool
()
.
invoke
(
user_id
=
''
,
tool_parameters
=
{
'content'
:
'Dify 123 😊'
})
except
Exception
as
e
:
raise
ToolProviderCredentialValidationError
(
str
(
e
))
api/core/tools/provider/builtin/qrcode/qrcode.yaml
0 → 100644
View file @
1cf5f510
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
api/core/tools/provider/builtin/qrcode/tools/qrcode_generator.py
0 → 100644
View file @
1cf5f510
import
io
import
logging
from
typing
import
Any
,
Union
import
qrcode
from
qrcode.image.pure
import
PyPNGImage
from
core.tools.entities.tool_entities
import
ToolInvokeMessage
from
core.tools.tool.builtin_tool
import
BuiltinTool
class
QRCodeGeneratorTool
(
BuiltinTool
):
def
_invoke
(
self
,
user_id
:
str
,
tool_parameters
:
dict
[
str
,
Any
],
)
->
Union
[
ToolInvokeMessage
,
list
[
ToolInvokeMessage
]]:
"""
invoke tools
"""
# get expression
content
=
tool_parameters
.
get
(
'content'
,
''
)
if
not
content
:
return
self
.
create_text_message
(
'Invalid parameter content'
)
try
:
img
=
qrcode
.
make
(
data
=
content
,
image_factory
=
PyPNGImage
)
byte_stream
=
io
.
BytesIO
()
img
.
save
(
byte_stream
)
byte_array
=
byte_stream
.
getvalue
()
return
self
.
create_blob_message
(
blob
=
byte_array
,
meta
=
{
'mime_type'
:
'image/png'
},
save_as
=
self
.
VARIABLE_KEY
.
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'
)
api/core/tools/provider/builtin/qrcode/tools/qrcode_generator.yaml
0 → 100644
View file @
1cf5f510
identity
:
name
:
qrcode_generator
author
:
Bowen Liang
label
:
en_US
:
QR Code Generator
zh_Hans
:
二维码生成器
pt_BR
:
QR Code Generator
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
api/requirements.txt
View file @
1cf5f510
...
...
@@ -70,3 +70,4 @@ numexpr~=2.9.0
duckduckgo-search==4.4.3
arxiv==2.1.0
yarl~=1.9.4
qrcode~=7.4.2
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment