Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions astrbot/dashboard/routes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,30 @@ def __init__(
"/config/provider/list": ("GET", self.get_provider_config_list),
"/config/provider/model_list": ("GET", self.get_provider_model_list),
"/config/provider/get_embedding_dim": ("POST", self.get_embedding_dim),
"/config/provider_sources/<provider_source_id>/models": (
"/config/provider_sources/models": (
"GET",
self.get_provider_source_models,
),
"/config/provider_sources/<provider_source_id>/update": (
"/config/provider_sources/update": (
"POST",
self.update_provider_source,
),
"/config/provider_sources/<provider_source_id>/delete": (
"/config/provider_sources/delete": (
"POST",
self.delete_provider_source,
),
}
self.register_routes()

async def delete_provider_source(self, provider_source_id: str):
async def delete_provider_source(self):
"""删除 provider_source,并更新关联的 providers"""
post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__

provider_source_id = post_data.get("id")
if not provider_source_id:
return Response().error("缺少 provider_source_id").__dict__
Comment on lines +205 to +211
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: 建议将标识符字段命名与其他 provider source 相关端点保持一致。

当前处理函数从 JSON body 中的 id 读取标识符,而 get_provider_source_models 现在使用查询参数中的 source_id。对同一个概念使用不同的字段名,随着调用方增多,容易造成困惑并引入隐蔽问题。建议在所有 provider source 相关端点中统一字段名(例如统一使用 source_id)。

Suggested change
post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__
provider_source_id = post_data.get("id")
if not provider_source_id:
return Response().error("缺少 provider_source_id").__dict__
post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__
# 与其他 provider_source 接口保持字段命名一致,优先使用 source_id
provider_source_id = post_data.get("source_id") or post_data.get("id")
if not provider_source_id:
return Response().error("缺少 source_id").__dict__
Original comment in English

suggestion: Consider aligning identifier field naming with other provider source endpoints.

This handler reads the identifier from id in the JSON body, while get_provider_source_models now uses source_id as a query parameter. Using different names for the same concept can cause confusion and subtle bugs as more callers are added. Consider standardizing on one field name (e.g., source_id) across all provider source endpoints.

Suggested change
post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__
provider_source_id = post_data.get("id")
if not provider_source_id:
return Response().error("缺少 provider_source_id").__dict__
post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__
# 与其他 provider_source 接口保持字段命名一致,优先使用 source_id
provider_source_id = post_data.get("source_id") or post_data.get("id")
if not provider_source_id:
return Response().error("缺少 source_id").__dict__


provider_sources = self.config.get("provider_sources", [])
target_idx = next(
Expand Down Expand Up @@ -235,15 +242,16 @@ async def delete_provider_source(self, provider_source_id: str):

return Response().ok(message="删除 provider source 成功").__dict__

async def update_provider_source(self, provider_source_id: str):
async def update_provider_source(self):
"""更新或新增 provider_source,并重载关联的 providers"""

post_data = await request.json
if not post_data:
return Response().error("缺少配置数据").__dict__

new_source_config = post_data.get("config") or post_data
original_id = provider_source_id
original_id = post_data.get("original_id")
if not original_id:
return Response().error("缺少 original_id").__dict__

if not isinstance(new_source_config, dict):
return Response().error("缺少或错误的配置数据").__dict__
Expand Down Expand Up @@ -684,11 +692,15 @@ async def get_embedding_dim(self):
logger.error(traceback.format_exc())
return Response().error(f"获取嵌入维度失败: {e!s}").__dict__

async def get_provider_source_models(self, provider_source_id: str):
async def get_provider_source_models(self):
"""获取指定 provider_source 支持的模型列表

本质上会临时初始化一个 Provider 实例,调用 get_models() 获取模型列表,然后销毁实例
"""
provider_source_id = request.args.get("source_id")
if not provider_source_id:
return Response().error("缺少参数 source_id").__dict__
Comment on lines +695 to +702
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: 请在各个端点之间明确统一是通过查询参数还是通过请求体传递 source id。

这个端点从查询字符串中读取 source_id,而 delete_provider_sourceupdate_provider_source 则期望在 JSON body 中获取相同的标识符。在相关端点之间对同一个资源 ID 使用不同的传递方式,会降低 API 的可预测性。建议在这些端点之间统一约定 provider source id 的传递方式。

Suggested change
async def get_provider_source_models(self):
"""获取指定 provider_source 支持的模型列表
本质上会临时初始化一个 Provider 实例调用 get_models() 获取模型列表然后销毁实例
"""
provider_source_id = request.args.get("source_id")
if not provider_source_id:
return Response().error("缺少参数 source_id").__dict__
async def get_provider_source_models(self):
"""获取指定 provider_source 支持的模型列表
本质上会临时初始化一个 Provider 实例调用 get_models() 获取模型列表然后销毁实例
为了与 delete_provider_source / update_provider_source 等接口保持一致
此处从 JSON Body 中读取 source_id而不是使用查询参数
"""
post_data = request.get_json(silent=True) or {}
provider_source_id = post_data.get("source_id")
if not provider_source_id:
return Response().error("缺少参数 source_id").__dict__
Original comment in English

suggestion: Clarify the choice of using query param vs body for source id across endpoints.

This endpoint reads source_id from the query string, while delete_provider_source and update_provider_source expect the same identifier in the JSON body. Using different locations for the same resource id across related endpoints makes the API less predictable. Please consider aligning these endpoints on a single convention for where the provider source id is supplied.

Suggested change
async def get_provider_source_models(self):
"""获取指定 provider_source 支持的模型列表
本质上会临时初始化一个 Provider 实例调用 get_models() 获取模型列表然后销毁实例
"""
provider_source_id = request.args.get("source_id")
if not provider_source_id:
return Response().error("缺少参数 source_id").__dict__
async def get_provider_source_models(self):
"""获取指定 provider_source 支持的模型列表
本质上会临时初始化一个 Provider 实例调用 get_models() 获取模型列表然后销毁实例
为了与 delete_provider_source / update_provider_source 等接口保持一致
此处从 JSON Body 中读取 source_id而不是使用查询参数
"""
post_data = request.get_json(silent=True) or {}
provider_source_id = post_data.get("source_id")
if not provider_source_id:
return Response().error("缺少参数 source_id").__dict__


try:
from astrbot.core.provider.register import provider_cls_map

Expand Down
8 changes: 5 additions & 3 deletions dashboard/src/composables/useProviderSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
if (!confirm(tm('providerSources.deleteConfirm', { id: source.id }))) return

try {
await axios.post(`/api/config/provider_sources/${source.id}/delete`)
await axios.post('/api/config/provider_sources/delete', { id: source.id })

providers.value = providers.value.filter((p) => p.provider_source_id !== source.id)
providerSources.value = providerSources.value.filter((s) => s.id !== source.id)
Expand All @@ -423,7 +423,7 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
savingSource.value = true
const originalId = selectedProviderSourceOriginalId.value || selectedProviderSource.value.id
try {
const response = await axios.post(`/api/config/provider_sources/${originalId}/update`, {
const response = await axios.post('/api/config/provider_sources/update', {
config: editableProviderSource.value,
original_id: originalId
})
Expand Down Expand Up @@ -478,7 +478,9 @@ export function useProviderSources(options: UseProviderSourcesOptions) {
loadingModels.value = true
try {
const sourceId = editableProviderSource.value?.id || selectedProviderSource.value.id
const response = await axios.get(`/api/config/provider_sources/${sourceId}/models`)
const response = await axios.get('/api/config/provider_sources/models', {
params: { source_id: sourceId }
})
if (response.data.status === 'ok') {
const metadataMap = response.data.data.model_metadata || {}
modelMetadata.value = metadataMap
Expand Down