Skip to content

Commit f0064e4

Browse files
committed
build and test
1 parent 2655ead commit f0064e4

File tree

11 files changed

+1057
-688
lines changed

11 files changed

+1057
-688
lines changed

dify-panel/app.py

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
44
提供Dify平台连接管理和功能导航
55
"""
6-
import streamlit as st
6+
77
import os
88
import sys
99
from pathlib import Path
10+
1011
import dotenv
12+
import streamlit as st
1113

1214
# 添加当前目录到Python路径
1315
current_dir = Path(__file__).parent
@@ -25,70 +27,76 @@
2527
page_title="Dify管理面板",
2628
page_icon="🤖",
2729
layout="wide",
28-
initial_sidebar_state="expanded"
30+
initial_sidebar_state="expanded",
2931
)
3032

33+
3134
def try_auto_connect():
3235
"""
3336
尝试使用环境变量中的默认值自动连接到Dify平台
34-
37+
3538
如果环境变量中存在必要的连接信息,且尚未连接,则尝试自动连接
36-
39+
3740
Returns:
3841
bool: 是否成功连接
3942
"""
4043
# 如果已经连接,不需要再次连接
4144
if DifyClient.is_connected():
4245
return True
43-
46+
4447
# 获取环境变量中的默认值
45-
default_base_url, default_email, default_password = DifyClient.get_default_connection_info()
46-
48+
default_base_url, default_email, default_password = (
49+
DifyClient.get_default_connection_info()
50+
)
51+
4752
# 如果环境变量中有完整的连接信息,尝试自动连接
4853
if default_base_url and default_email and default_password:
4954
return DifyClient.connect(default_base_url, default_email, default_password)
50-
55+
5156
return False
5257

58+
5359
def main():
5460
"""主函数"""
5561
# 页面标题
5662
page_header("Dify管理面板", "通过此面板管理Dify平台上的应用、API密钥、标签和工具")
57-
63+
5864
# 尝试自动连接
5965
auto_connected = try_auto_connect()
60-
66+
6167
# 侧边栏导航
6268
with st.sidebar:
6369
st.title("Dify管理面板")
6470
st.divider()
65-
71+
6672
# 显示连接状态
6773
if DifyClient.is_connected():
6874
st.success("已连接到Dify平台")
6975
st.write(f"服务器: {st.session_state.dify_base_url}")
7076
st.write(f"账号: {st.session_state.dify_email}")
71-
77+
7278
if st.button("断开连接"):
7379
DifyClient.disconnect()
7480
st.rerun()
7581
else:
7682
st.warning("未连接到Dify平台")
7783
st.info("请在右侧连接表单中输入Dify平台的连接信息")
78-
84+
7985
# 主内容区域
8086
if not DifyClient.is_connected():
8187
# 显示连接表单
8288
st.write("### 欢迎使用Dify管理面板")
8389
st.write("请先连接到Dify平台,然后继续管理您的应用和资源。")
84-
90+
8591
# 如果尝试自动连接过但失败,显示错误信息
8692
if auto_connected is False:
87-
st.warning("尝试使用环境变量中的连接信息自动连接失败,请手动输入正确的连接信息。")
88-
93+
st.warning(
94+
"尝试使用环境变量中的连接信息自动连接失败,请手动输入正确的连接信息。"
95+
)
96+
8997
# 显示连接表单
9098
base_url, email, password, submit = connection_form()
91-
99+
92100
if submit:
93101
with st.spinner("连接中..."):
94102
if DifyClient.connect(base_url, email, password):
@@ -97,72 +105,80 @@ def main():
97105
else:
98106
# 已连接状态,显示功能概览
99107
client = DifyClient.get_connection()
100-
108+
101109
# 获取应用信息
102110
try:
103111
apps = client.fetch_all_apps()
104112
st.write(f"### 平台概览")
105-
113+
106114
# 显示统计信息
107115
col1, col2, col3 = st.columns(3)
108116
with col1:
109117
st.metric("应用总数", len(apps))
110-
118+
111119
# 统计不同类型的应用数量
112120
app_types = {}
113121
for app in apps:
114-
mode = app.get('mode', 'unknown')
122+
mode = app.get("mode", "unknown")
115123
app_types[mode] = app_types.get(mode, 0) + 1
116-
124+
117125
with col2:
118-
st.metric("聊天应用", app_types.get('chat', 0) + app_types.get('agent-chat', 0))
119-
126+
st.metric(
127+
"聊天应用",
128+
app_types.get("chat", 0) + app_types.get("agent-chat", 0),
129+
)
130+
120131
with col3:
121-
st.metric("其他应用", len(apps) - app_types.get('chat', 0) - app_types.get('agent-chat', 0))
122-
132+
st.metric(
133+
"其他应用",
134+
len(apps)
135+
- app_types.get("chat", 0)
136+
- app_types.get("agent-chat", 0),
137+
)
138+
123139
# 显示功能导航
124140
st.divider()
125141
st.write("### 功能导航")
126-
142+
127143
# 创建三列导航区
128144
nav_col1, nav_col2, nav_col3 = st.columns(3)
129-
145+
130146
with nav_col1:
131147
st.subheader("应用管理")
132148
st.write("创建、编辑、删除应用,管理应用的DSL配置")
133149
if st.button("进入应用管理", key="nav_app"):
134150
# 跳转到应用管理页面
135151
st.switch_page("pages/app_management.py")
136-
152+
137153
with nav_col2:
138154
st.subheader("API密钥管理")
139155
st.write("管理应用的API密钥,创建新密钥或删除旧密钥")
140156
if st.button("进入API密钥管理", key="nav_api"):
141157
# 跳转到API密钥管理页面
142158
st.switch_page("pages/api_key_management.py")
143-
159+
144160
with nav_col3:
145161
st.subheader("标签管理")
146162
st.write("创建和管理标签,为应用添加或移除标签")
147163
if st.button("进入标签管理", key="nav_tags"):
148164
# 跳转到标签管理页面
149165
st.switch_page("pages/tag_management.py")
150-
166+
151167
# 第二行导航
152168
nav_col4, nav_col5, _ = st.columns(3)
153-
169+
154170
with nav_col4:
155171
st.subheader("工具管理")
156172
st.write("查看和管理工具提供者,更新工作流工具")
157173
if st.button("进入工具管理", key="nav_tools"):
158174
# 跳转到工具管理页面
159175
st.switch_page("pages/tool_management.py")
160-
176+
161177
except Exception as e:
162178
st.error(f"获取平台信息失败: {str(e)}")
163179
if st.button("重试"):
164180
st.rerun()
165181

182+
166183
if __name__ == "__main__":
167184
main()
168-

dify-panel/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
配置文件
33
"""
4+
45
import os
56

67
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
78

8-
DATABASE_PATH = os.path.join(BASE_DIR, 'database.db')
9-
9+
DATABASE_PATH = os.path.join(BASE_DIR, "database.db")

dify-panel/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from peewee import Model, CharField, SqliteDatabase
21
from config import DATABASE_PATH
2+
from peewee import CharField, Model, SqliteDatabase
33

44
db = SqliteDatabase(DATABASE_PATH)
55

6+
67
class BaseModel(Model):
78
class Meta:
89
database = db
9-
10+
11+
1012
class DifySite(BaseModel):
1113
base_url = CharField(max_length=255)
1214
email = CharField(max_length=255)
13-
password = CharField(max_length=255)
15+
password = CharField(max_length=255)

0 commit comments

Comments
 (0)