feat(model): 增加模型管理和测试功能

- 新增模型删除功能
- 实现模型测试连接功能
- 优化模型选择器组件
- 更新模型相关API和数据库操作
This commit is contained in:
JefferyHcool
2025-05-26 23:16:49 +08:00
parent 9b298d3094
commit be3db5faaf
2 changed files with 27 additions and 2 deletions

View File

@@ -14,6 +14,15 @@ def init_model_table():
conn.commit()
conn.close()
def get_model_by_provider_and_name(provider_id: int, model_name: str):
conn = get_connection()
cursor = conn.execute(
"SELECT * FROM models WHERE provider_id = ? AND model_name = ?",
(provider_id, model_name)
)
row = cursor.fetchone()
return row
# 插入模型
def insert_model(provider_id: int, model_name: str):
conn = get_connection()

View File

@@ -19,7 +19,16 @@ def model_list():
return R.success(modelService.get_all_models(True),msg="获取模型列表成功")
except Exception as e:
return R.error(e)
@router.get("/models/delete/{model_id}")
def delete_model(model_id: int):
try:
success = modelService.delete_model_by_id(model_id)
if success:
return R.success(msg="模型删除成功")
else:
return R.error("模型不存在或删除失败")
except Exception as e:
return R.error(f"删除模型失败: {e}")
@router.get("/model_list/{provider_id}")
def model_list(provider_id):
try:
@@ -31,6 +40,13 @@ def model_list(provider_id):
def create_model(data: CreateModelRequest):
success = ModelService.add_new_model(data.provider_id, data.model_name)
if not success:
raise R.error("模型添加失败")
return R.error("模型添加失败")
return R.success(msg="模型添加成功")
@router.get("/model_enable/{provider_id}")
def get_enabled_models_by_provider(provider_id: str):
try:
models = modelService.get_enabled_models_by_provider(provider_id)
return R.success(models, msg="获取启用模型成功")
except Exception as e:
return R.error(f"获取启用模型失败: {e}")