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
30b18df9
Commit
30b18df9
authored
Feb 25, 2024
by
takatost
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add agent app convert command
parent
8e5bd054
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
4 deletions
+61
-4
commands.py
api/commands.py
+54
-1
workflow.py
api/controllers/console/app/workflow.py
+4
-1
workflow_service.py
api/services/workflow_service.py
+3
-2
No files found.
api/commands.py
View file @
30b18df9
...
...
@@ -15,7 +15,7 @@ from libs.rsa import generate_key_pair
from
models.account
import
Tenant
from
models.dataset
import
Dataset
,
DatasetCollectionBinding
,
DocumentSegment
from
models.dataset
import
Document
as
DatasetDocument
from
models.model
import
Account
,
App
,
App
AnnotationSetting
,
MessageAnnotation
from
models.model
import
Account
,
App
,
App
Mode
,
AppModelConfig
,
AppAnnotationSetting
,
Conversation
,
MessageAnnotation
from
models.provider
import
Provider
,
ProviderModel
...
...
@@ -370,8 +370,61 @@ def migrate_knowledge_vector_database():
fg
=
'green'
))
@
click
.
command
(
'convert-to-agent-apps'
,
help
=
'Convert Agent Assistant to Agent App.'
)
def
convert_to_agent_apps
():
"""
Convert Agent Assistant to Agent App.
"""
click
.
echo
(
click
.
style
(
'Start convert to agent apps.'
,
fg
=
'green'
))
proceeded_app_ids
=
[]
while
True
:
# fetch first 1000 apps
sql_query
=
"""SELECT a.id AS id FROM apps a
INNER JOIN app_model_configs am ON a.app_model_config_id=am.id
WHERE a.mode = 'chat' AND am.agent_mode is not null
and (am.agent_mode like '
%
"strategy": "function_call"
%
' or am.agent_mode like '
%
"strategy": "react"
%
')
and am.agent_mode like '{"enabled": true
%
' ORDER BY a.created_at DESC LIMIT 1000"""
with
db
.
engine
.
begin
()
as
conn
:
rs
=
conn
.
execute
(
db
.
text
(
sql_query
))
apps
=
[]
for
i
in
rs
:
app_id
=
str
(
i
.
id
)
if
app_id
not
in
proceeded_app_ids
:
proceeded_app_ids
.
append
(
app_id
)
app
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
app_id
)
.
first
()
apps
.
append
(
app
)
if
len
(
apps
)
==
0
:
break
for
app
in
apps
:
click
.
echo
(
'Converting app: {}'
.
format
(
app
.
id
))
try
:
app
.
mode
=
AppMode
.
AGENT
.
value
db
.
session
.
commit
()
# update conversation mode to agent
db
.
session
.
query
(
Conversation
)
.
filter
(
Conversation
.
app_id
==
app
.
id
)
.
update
(
{
Conversation
.
mode
:
AppMode
.
AGENT
.
value
}
)
db
.
session
.
commit
()
click
.
echo
(
click
.
style
(
'Converted app: {}'
.
format
(
app
.
id
),
fg
=
'green'
))
except
Exception
as
e
:
click
.
echo
(
click
.
style
(
'Convert app error: {} {}'
.
format
(
e
.
__class__
.
__name__
,
str
(
e
)),
fg
=
'red'
))
click
.
echo
(
click
.
style
(
'Congratulations! Converted {} agent apps.'
.
format
(
len
(
proceeded_app_ids
)),
fg
=
'green'
))
def
register_commands
(
app
):
app
.
cli
.
add_command
(
reset_password
)
app
.
cli
.
add_command
(
reset_email
)
app
.
cli
.
add_command
(
reset_encrypt_key_pair
)
app
.
cli
.
add_command
(
vdb_migrate
)
app
.
cli
.
add_command
(
convert_to_agent_apps
)
api/controllers/console/app/workflow.py
View file @
30b18df9
...
...
@@ -77,7 +77,10 @@ class ConvertToWorkflowApi(Resource):
"""
# convert to workflow mode
workflow_service
=
WorkflowService
()
workflow
=
workflow_service
.
chatbot_convert_to_workflow
(
app_model
=
app_model
)
workflow
=
workflow_service
.
chatbot_convert_to_workflow
(
app_model
=
app_model
,
account
=
current_user
)
# return workflow
return
workflow
...
...
api/services/workflow_service.py
View file @
30b18df9
...
...
@@ -65,11 +65,12 @@ class WorkflowService:
# return default block config
return
default_block_configs
def
chatbot_convert_to_workflow
(
self
,
app_model
:
App
)
->
Workflow
:
def
chatbot_convert_to_workflow
(
self
,
app_model
:
App
,
account
:
Account
)
->
Workflow
:
"""
basic mode of chatbot app to workflow
:param app_model: App instance
:param account: Account instance
:return:
"""
# check if chatbot app is in basic mode
...
...
@@ -78,6 +79,6 @@ class WorkflowService:
# convert to workflow mode
workflow_converter
=
WorkflowConverter
()
workflow
=
workflow_converter
.
convert_to_workflow
(
app_model
=
app_model
)
workflow
=
workflow_converter
.
convert_to_workflow
(
app_model
=
app_model
,
account
=
account
)
return
workflow
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