Files
syops/backend/insert_agents.py
T

71 lines
2.6 KiB
Python

from app import create_app, db
from app.models import Agent
import uuid
app = create_app()
with app.app_context():
# 1. 方式一:嵌入到网站中 (Iframe)
# <iframe src=" http://192.168.100.230:8882/chatbot/imrmbYyasJUHjXQg " style="width: 100%; height: 100%; min-height: 700px" frameborder="0" allow="microphone"> </iframe>
agent_iframe = Agent.query.filter_by(name='人事规章(网页版)').first()
iframe_url = 'http://192.168.100.230:8882/chatbot/imrmbYyasJUHjXQg'
if not agent_iframe:
agent_iframe = Agent(
name='人事规章(网页版)',
description='嵌入式人事规章助手',
dify_app_id=str(uuid.uuid4()),
dify_api_key='placeholder',
type='iframe',
extra_config={'iframe_url': iframe_url},
icon_url='ri-article-line',
agent_code='generic',
runtime_provider='iframe',
conversation_mode='embedded',
iframe_url=iframe_url,
)
db.session.add(agent_iframe)
print('Added Iframe Agent')
else:
agent_iframe.type = 'iframe'
agent_iframe.extra_config = {'iframe_url': iframe_url}
agent_iframe.icon_url = 'ri-article-line'
agent_iframe.agent_code = 'generic'
agent_iframe.runtime_provider = 'iframe'
agent_iframe.conversation_mode = 'embedded'
agent_iframe.iframe_url = iframe_url
print('Updated Iframe Agent')
# 2. 方式二:API
# 基础URL: http://127.0.0.1:5001/v1
# API密钥:app-xdiejQibWQy8ZQWXcdxJjS9I
agent_api = Agent.query.filter_by(name='人事规章(API版)').first()
if not agent_api:
agent_api = Agent(
name='人事规章(API版)',
description='API调用人事规章助手',
dify_app_id=str(uuid.uuid4()),
dify_api_key='app-xdiejQibWQy8ZQWXcdxJjS9I',
type='api',
api_base_url='http://127.0.0.1:5001/v1',
icon_url='ri-robot-line',
agent_code='generic',
runtime_provider='dify',
conversation_mode='chat',
)
db.session.add(agent_api)
print('Added API Agent')
else:
agent_api.type = 'api'
agent_api.dify_api_key = 'app-xdiejQibWQy8ZQWXcdxJjS9I'
agent_api.api_base_url = 'http://127.0.0.1:5001/v1'
agent_api.icon_url = 'ri-robot-line'
agent_api.agent_code = 'generic'
agent_api.runtime_provider = 'dify'
agent_api.conversation_mode = 'chat'
print('Updated API Agent')
db.session.commit()