fix/hard-code #62

Merged
cfy777 merged 10 commits from fix/hard-code into develop 2026-06-14 12:31:55 +08:00
Showing only changes of commit aae0629b2d - Show all commits

View File

@@ -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},
} }
} }