fix: LLM 服务去除重复默认值,新增 httpClientTimeout 参数
- 去除 model/endpoint 的 fallback 默认值 - HTTP Client 超时从 config 传入
This commit is contained in:
@@ -26,24 +26,23 @@ type OpenAIService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewOpenAIService 创建 OpenAI LLM 服务。
|
// NewOpenAIService 创建 OpenAI LLM 服务。
|
||||||
func NewOpenAIService(apiKey, model, endpoint string, timeoutSec int, logger *zap.SugaredLogger) *OpenAIService {
|
// model、endpoint 由 config 层保证非空。
|
||||||
if model == "" {
|
func NewOpenAIService(apiKey, model, endpoint string, timeoutSec, httpClientTimeoutSec int, logger *zap.SugaredLogger) *OpenAIService {
|
||||||
model = "gpt-4o"
|
|
||||||
}
|
|
||||||
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 = 10 * time.Second
|
timeout = 10 * time.Second
|
||||||
}
|
}
|
||||||
|
httpClientTimeout := time.Duration(httpClientTimeoutSec) * time.Second
|
||||||
|
if httpClientTimeout <= 0 {
|
||||||
|
httpClientTimeout = 60 * time.Second
|
||||||
|
}
|
||||||
return &OpenAIService{
|
return &OpenAIService{
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
model: model,
|
model: model,
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
client: &http.Client{Timeout: 60 * time.Second}, // HTTP client timeout > LLM timeout
|
client: &http.Client{Timeout: httpClientTimeout},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user