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
27e67848
Unverified
Commit
27e67848
authored
Mar 07, 2024
by
Yeuoly
Committed by
GitHub
Mar 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feat: AIPPT & DynamicToolParamter (#2725)
parent
70525653
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
720 additions
and
11 deletions
+720
-11
_position.yaml
api/core/tools/provider/_position.yaml
+1
-0
icon.png
api/core/tools/provider/builtin/aippt/_assets/icon.png
+0
-0
aippt.py
api/core/tools/provider/builtin/aippt/aippt.py
+11
-0
aippt.yaml
api/core/tools/provider/builtin/aippt/aippt.yaml
+42
-0
aippt.py
api/core/tools/provider/builtin/aippt/tools/aippt.py
+509
-0
aippt.yaml
api/core/tools/provider/builtin/aippt/tools/aippt.yaml
+54
-0
stable_diffusion.py
...rovider/builtin/stablediffusion/tools/stable_diffusion.py
+60
-6
tools_manage_service.py
api/services/tools_manage_service.py
+43
-5
No files found.
api/core/tools/provider/_position.yaml
View file @
27e67848
...
...
@@ -9,6 +9,7 @@
-
azuredalle
-
stablediffusion
-
webscraper
-
aippt
-
youtube
-
wolframalpha
-
maths
...
...
api/core/tools/provider/builtin/aippt/_assets/icon.png
0 → 100644
View file @
27e67848
1.92 KB
api/core/tools/provider/builtin/aippt/aippt.py
0 → 100644
View file @
27e67848
from
core.tools.errors
import
ToolProviderCredentialValidationError
from
core.tools.provider.builtin.aippt.tools.aippt
import
AIPPTGenerateTool
from
core.tools.provider.builtin_tool_provider
import
BuiltinToolProviderController
class
AIPPTProvider
(
BuiltinToolProviderController
):
def
_validate_credentials
(
self
,
credentials
:
dict
)
->
None
:
try
:
AIPPTGenerateTool
.
_get_api_token
(
credentials
,
user_id
=
'__dify_system__'
)
except
Exception
as
e
:
raise
ToolProviderCredentialValidationError
(
str
(
e
))
api/core/tools/provider/builtin/aippt/aippt.yaml
0 → 100644
View file @
27e67848
identity
:
author
:
Dify
name
:
aippt
label
:
en_US
:
AIPPT
zh_Hans
:
AIPPT
description
:
en_US
:
AI-generated PPT with one click, input your content topic, and let AI serve you one-stop
zh_Hans
:
AI一键生成PPT,输入你的内容主题,让AI为你一站式服务到底
icon
:
icon.png
credentials_for_provider
:
aippt_access_key
:
type
:
secret-input
required
:
true
label
:
en_US
:
AIPPT API key
zh_Hans
:
AIPPT API key
pt_BR
:
AIPPT API key
help
:
en_US
:
Please input your AIPPT API key
zh_Hans
:
请输入你的 AIPPT API key
pt_BR
:
Please input your AIPPT API key
placeholder
:
en_US
:
Please input your AIPPT API key
zh_Hans
:
请输入你的 AIPPT API key
pt_BR
:
Please input your AIPPT API key
url
:
https://www.aippt.cn
aippt_secret_key
:
type
:
secret-input
required
:
true
label
:
en_US
:
AIPPT Secret key
zh_Hans
:
AIPPT Secret key
pt_BR
:
AIPPT Secret key
help
:
en_US
:
Please input your AIPPT Secret key
zh_Hans
:
请输入你的 AIPPT Secret key
pt_BR
:
Please input your AIPPT Secret key
placeholder
:
en_US
:
Please input your AIPPT Secret key
zh_Hans
:
请输入你的 AIPPT Secret key
pt_BR
:
Please input your AIPPT Secret key
api/core/tools/provider/builtin/aippt/tools/aippt.py
0 → 100644
View file @
27e67848
This diff is collapsed.
Click to expand it.
api/core/tools/provider/builtin/aippt/tools/aippt.yaml
0 → 100644
View file @
27e67848
identity
:
name
:
aippt
author
:
Dify
label
:
en_US
:
AIPPT
zh_Hans
:
AIPPT
description
:
human
:
en_US
:
AI-generated PPT with one click, input your content topic, and let AI serve you one-stop
zh_Hans
:
AI一键生成PPT,输入你的内容主题,让AI为你一站式服务到底
llm
:
A tool used to generate PPT with AI, input your content topic, and let AI generate PPT for you.
parameters
:
-
name
:
title
type
:
string
required
:
true
label
:
en_US
:
Title
zh_Hans
:
标题
human_description
:
en_US
:
The title of the PPT.
zh_Hans
:
PPT的标题。
llm_description
:
The title of the PPT, which will be used to generate the PPT outline.
form
:
llm
-
name
:
outline
type
:
string
required
:
false
label
:
en_US
:
Outline
zh_Hans
:
大纲
human_description
:
en_US
:
The outline of the PPT
zh_Hans
:
PPT的大纲
llm_description
:
The outline of the PPT, which will be used to generate the PPT content. provide it if you have.
form
:
llm
-
name
:
llm
type
:
select
required
:
true
label
:
en_US
:
LLM model
zh_Hans
:
生成大纲的LLM
options
:
-
value
:
aippt
label
:
en_US
:
AIPPT default model
zh_Hans
:
AIPPT默认模型
-
value
:
wenxin
label
:
en_US
:
Wenxin ErnieBot
zh_Hans
:
文心一言
default
:
aippt
human_description
:
en_US
:
The LLM model used for generating PPT outline.
zh_Hans
:
用于生成PPT大纲的LLM模型。
form
:
form
api/core/tools/provider/builtin/stablediffusion/tools/stable_diffusion.py
View file @
27e67848
...
...
@@ -2,11 +2,11 @@ import io
import
json
from
base64
import
b64decode
,
b64encode
from
copy
import
deepcopy
from
os.path
import
join
from
typing
import
Any
,
Union
from
httpx
import
get
,
post
from
PIL
import
Image
from
yarl
import
URL
from
core.tools.entities.common_entities
import
I18nObject
from
core.tools.entities.tool_entities
import
ToolInvokeMessage
,
ToolParameter
,
ToolParameterOption
...
...
@@ -79,7 +79,7 @@ class StableDiffusionTool(BuiltinTool):
# set model
try
:
url
=
join
(
base_url
,
'sdapi/v1/
options'
)
url
=
str
(
URL
(
base_url
)
/
'sdapi'
/
'v1'
/
'
options'
)
response
=
post
(
url
,
data
=
json
.
dumps
({
'sd_model_checkpoint'
:
model
}))
...
...
@@ -153,8 +153,21 @@ class StableDiffusionTool(BuiltinTool):
if
not
model
:
raise
ToolProviderCredentialValidationError
(
'Please input model'
)
response
=
get
(
url
=
f
'{base_url}/sdapi/v1/sd-models'
,
timeout
=
120
)
if
response
.
status_code
!=
200
:
api_url
=
str
(
URL
(
base_url
)
/
'sdapi'
/
'v1'
/
'sd-models'
)
response
=
get
(
url
=
api_url
,
timeout
=
10
)
if
response
.
status_code
==
404
:
# try draw a picture
self
.
_invoke
(
user_id
=
'test'
,
tool_parameters
=
{
'prompt'
:
'a cat'
,
'width'
:
1024
,
'height'
:
1024
,
'steps'
:
1
,
'lora'
:
''
,
}
)
elif
response
.
status_code
!=
200
:
raise
ToolProviderCredentialValidationError
(
'Failed to get models'
)
else
:
models
=
[
d
[
'model_name'
]
for
d
in
response
.
json
()]
...
...
@@ -165,6 +178,23 @@ class StableDiffusionTool(BuiltinTool):
except
Exception
as
e
:
raise
ToolProviderCredentialValidationError
(
f
'Failed to get models, {e}'
)
def
get_sd_models
(
self
)
->
list
[
str
]:
"""
get sd models
"""
try
:
base_url
=
self
.
runtime
.
credentials
.
get
(
'base_url'
,
None
)
if
not
base_url
:
return
[]
api_url
=
str
(
URL
(
base_url
)
/
'sdapi'
/
'v1'
/
'sd-models'
)
response
=
get
(
url
=
api_url
,
timeout
=
10
)
if
response
.
status_code
!=
200
:
return
[]
else
:
return
[
d
[
'model_name'
]
for
d
in
response
.
json
()]
except
Exception
as
e
:
return
[]
def
img2img
(
self
,
base_url
:
str
,
lora
:
str
,
image_binary
:
bytes
,
prompt
:
str
,
negative_prompt
:
str
,
width
:
int
,
height
:
int
,
steps
:
int
)
\
...
...
@@ -192,7 +222,7 @@ class StableDiffusionTool(BuiltinTool):
draw_options
[
'prompt'
]
=
prompt
try
:
url
=
join
(
base_url
,
'sdapi/v1/
img2img'
)
url
=
str
(
URL
(
base_url
)
/
'sdapi'
/
'v1'
/
'
img2img'
)
response
=
post
(
url
,
data
=
json
.
dumps
(
draw_options
),
timeout
=
120
)
if
response
.
status_code
!=
200
:
return
self
.
create_text_message
(
'Failed to generate image'
)
...
...
@@ -225,7 +255,7 @@ class StableDiffusionTool(BuiltinTool):
draw_options
[
'negative_prompt'
]
=
negative_prompt
try
:
url
=
join
(
base_url
,
'sdapi/v1/
txt2img'
)
url
=
str
(
URL
(
base_url
)
/
'sdapi'
/
'v1'
/
'
txt2img'
)
response
=
post
(
url
,
data
=
json
.
dumps
(
draw_options
),
timeout
=
120
)
if
response
.
status_code
!=
200
:
return
self
.
create_text_message
(
'Failed to generate image'
)
...
...
@@ -270,4 +300,28 @@ class StableDiffusionTool(BuiltinTool):
)
for
i
in
self
.
list_default_image_variables
()])
)
if
self
.
runtime
.
credentials
:
try
:
models
=
self
.
get_sd_models
()
if
len
(
models
)
!=
0
:
parameters
.
append
(
ToolParameter
(
name
=
'model'
,
label
=
I18nObject
(
en_US
=
'Model'
,
zh_Hans
=
'Model'
),
human_description
=
I18nObject
(
en_US
=
'Model of Stable Diffusion, you can check the official documentation of Stable Diffusion'
,
zh_Hans
=
'Stable Diffusion 的模型,您可以查看 Stable Diffusion 的官方文档'
,
),
type
=
ToolParameter
.
ToolParameterType
.
SELECT
,
form
=
ToolParameter
.
ToolParameterForm
.
FORM
,
llm_description
=
'Model of Stable Diffusion, you can check the official documentation of Stable Diffusion'
,
required
=
True
,
default
=
models
[
0
],
options
=
[
ToolParameterOption
(
value
=
i
,
label
=
I18nObject
(
en_US
=
i
,
zh_Hans
=
i
)
)
for
i
in
models
])
)
except
:
pass
return
parameters
api/services/tools_manage_service.py
View file @
27e67848
...
...
@@ -9,6 +9,7 @@ from core.tools.entities.tool_entities import (
ApiProviderAuthType
,
ApiProviderSchemaType
,
ToolCredentialsOption
,
ToolParameter
,
ToolProviderCredentials
,
)
from
core.tools.entities.user_entities
import
UserTool
,
UserToolProvider
...
...
@@ -73,15 +74,52 @@ class ToolManageService:
provider_controller
:
ToolProviderController
=
ToolManager
.
get_builtin_provider
(
provider
)
tools
=
provider_controller
.
get_tools
()
result
=
[
UserTool
(
tool_provider_configurations
=
ToolConfiguration
(
tenant_id
=
tenant_id
,
provider_controller
=
provider_controller
)
# check if user has added the provider
builtin_provider
:
BuiltinToolProvider
=
db
.
session
.
query
(
BuiltinToolProvider
)
.
filter
(
BuiltinToolProvider
.
tenant_id
==
tenant_id
,
BuiltinToolProvider
.
provider
==
provider
,
)
.
first
()
credentials
=
{}
if
builtin_provider
is
not
None
:
# get credentials
credentials
=
builtin_provider
.
credentials
credentials
=
tool_provider_configurations
.
decrypt_tool_credentials
(
credentials
)
result
=
[]
for
tool
in
tools
:
# fork tool runtime
tool
=
tool
.
fork_tool_runtime
(
meta
=
{
'credentials'
:
credentials
,
'tenant_id'
:
tenant_id
,
})
# get tool parameters
parameters
=
tool
.
parameters
or
[]
# get tool runtime parameters
runtime_parameters
=
tool
.
get_runtime_parameters
()
# override parameters
current_parameters
=
parameters
.
copy
()
for
runtime_parameter
in
runtime_parameters
:
found
=
False
for
index
,
parameter
in
enumerate
(
current_parameters
):
if
parameter
.
name
==
runtime_parameter
.
name
and
parameter
.
form
==
runtime_parameter
.
form
:
current_parameters
[
index
]
=
runtime_parameter
found
=
True
break
if
not
found
and
runtime_parameter
.
form
==
ToolParameter
.
ToolParameterForm
.
FORM
:
current_parameters
.
append
(
runtime_parameter
)
user_tool
=
UserTool
(
author
=
tool
.
identity
.
author
,
name
=
tool
.
identity
.
name
,
label
=
tool
.
identity
.
label
,
description
=
tool
.
description
.
human
,
parameters
=
tool
.
parameters
or
[]
)
for
tool
in
tools
]
parameters
=
current_parameters
)
result
.
append
(
user_tool
)
return
json
.
loads
(
serialize_base_model_array
(
result
)
...
...
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