mirror of https://github.com/langgenius/dify.git
add agent app convert command
This commit is contained in:
parent
f11bf9153d
commit
7458fde5a5
|
|
@ -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, AppAnnotationSetting, MessageAnnotation
|
||||
from models.model import Account, App, AppMode, 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue