- 删 CheckTenantBalance/DeductBalance/GetTenantSurplus(admin-go 租户余额退出 model-gateway) - 新增 pricing_client.go:门禁 config/get + calcModelCost 调 shop-user-trade /calc 算费 - sync/stream/async 三处 Cost 改为按用量调 /calc(媒体类型映射 text/audio/video/image) - 删 price.go 本地 PriceConfig 换算体系与 entity/dto 的 price_config 字段 Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
modelUtils "model-gateway/service/utils"
|
|
)
|
|
|
|
// DetectMediaType 按模型业务字段映射从请求体推导输入媒体类型(替代硬编码的 media.type 路径):
|
|
// - reference_audio 映射路径在请求体中有值 → "audio"
|
|
// - reference_video 映射路径在请求体中有值 → "has_video"
|
|
// - 否则 → "no_video"
|
|
//
|
|
// 判定完全由模型配置(RequestBusinessFieldMapping,业务字段名见 ChatFieldsReq/VideoFields)驱动,
|
|
// 无请求结构硬编码;映射路径值即 GetByPathAll 路径(如 input.media?type=audio&url=#)。
|
|
// 媒体类型仅供 shop-user-trade 算费用量(见 pricing_client.go mgMediaTypeToShop)。
|
|
func DetectMediaType(reqBizMapping map[string]string, reqParams map[string]any) string {
|
|
if hasMediaValue(reqBizMapping, reqParams, "reference_audio") {
|
|
return "audio"
|
|
}
|
|
if hasMediaValue(reqBizMapping, reqParams, "reference_video") {
|
|
return "has_video"
|
|
}
|
|
return "no_video"
|
|
}
|
|
|
|
// hasMediaValue 业务字段映射路径在请求体中是否命中值
|
|
func hasMediaValue(reqBizMapping map[string]string, reqParams map[string]any, bizField string) bool {
|
|
path := reqBizMapping[bizField]
|
|
if path == "" {
|
|
return false
|
|
}
|
|
return len(modelUtils.GetByPathAll(reqParams, path)) > 0
|
|
}
|