fix: TTS 服务去除重复默认值,新增 httpClientTimeout 参数
- 去除 model/voice/endpoint 的 fallback 默认值 - HTTP Client 超时从 config 传入
This commit is contained in:
@@ -27,20 +27,16 @@ type MiMoService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMiMoService 创建 MiMo TTS 服务。
|
// NewMiMoService 创建 MiMo TTS 服务。
|
||||||
func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec int, logger *zap.SugaredLogger) *MiMoService {
|
// model、voice、endpoint 由 config 层保证非空。
|
||||||
if model == "" {
|
func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *MiMoService {
|
||||||
model = "mimo-v2.5-tts"
|
|
||||||
}
|
|
||||||
if voice == "" {
|
|
||||||
voice = "冰糖"
|
|
||||||
}
|
|
||||||
if endpoint == "" {
|
|
||||||
endpoint = "https://api.xiaomimimo.com/v1"
|
|
||||||
}
|
|
||||||
timeout := time.Duration(timeoutSec) * time.Second
|
timeout := time.Duration(timeoutSec) * time.Second
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
timeout = 5 * time.Second
|
timeout = 5 * time.Second
|
||||||
}
|
}
|
||||||
|
httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second
|
||||||
|
if httpClientTimeout <= 0 {
|
||||||
|
httpClientTimeout = 30 * time.Second
|
||||||
|
}
|
||||||
return &MiMoService{
|
return &MiMoService{
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
model: model,
|
model: model,
|
||||||
@@ -48,7 +44,7 @@ func NewMiMoService(apiKey, model, voice, endpoint string, timeoutSec int, logge
|
|||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
client: &http.Client{Timeout: 30 * time.Second},
|
client: &http.Client{Timeout: httpClientTimeout},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,23 +25,19 @@ type OpenAIService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewOpenAIService 创建 OpenAI TTS 服务。
|
// NewOpenAIService 创建 OpenAI TTS 服务。
|
||||||
func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, timeoutSec int, logger *zap.SugaredLogger) *OpenAIService {
|
// model、voice、endpoint 由 config 层保证非空。
|
||||||
if model == "" {
|
func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *OpenAIService {
|
||||||
model = "tts-1"
|
|
||||||
}
|
|
||||||
if voice == "" {
|
|
||||||
voice = "alloy"
|
|
||||||
}
|
|
||||||
if speed <= 0 {
|
if speed <= 0 {
|
||||||
speed = 1.0
|
speed = 1.0
|
||||||
}
|
}
|
||||||
if endpoint == "" {
|
|
||||||
endpoint = "https://api.openai.com/v1"
|
|
||||||
}
|
|
||||||
timeout := time.Duration(timeoutSec) * time.Second
|
timeout := time.Duration(timeoutSec) * time.Second
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
timeout = 5 * time.Second
|
timeout = 5 * time.Second
|
||||||
}
|
}
|
||||||
|
httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second
|
||||||
|
if httpClientTimeout <= 0 {
|
||||||
|
httpClientTimeout = 30 * time.Second
|
||||||
|
}
|
||||||
return &OpenAIService{
|
return &OpenAIService{
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
model: model,
|
model: model,
|
||||||
@@ -50,7 +46,7 @@ func NewOpenAIService(apiKey, model, voice, endpoint string, speed float64, time
|
|||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
client: &http.Client{Timeout: 30 * time.Second},
|
client: &http.Client{Timeout: httpClientTimeout},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user