This commit is contained in:
wyn
2026-05-21 17:28:36 +08:00
parent f118a799c2
commit 44f3383887
3 changed files with 37 additions and 60 deletions

View File

@@ -20,7 +20,8 @@ class LLMService
$this->url = trim((string)Env::get('promotion.promotion_llm_url', ''));
$this->model = trim((string)Env::get('promotion.promotion_llm_model', ''));
$this->apiKey = trim((string)Env::get('promotion.promotion_llm_api_key', ''));
$this->timeout = max(30, intval(Env::get('promotion.promotion_llm_timeout', 120)));
// 引用校对 system 提示词较长,请求常超过 30s至少 120s
$this->timeout = max(120, intval(Env::get('promotion.promotion_llm_timeout', 120)));
}
/**
@@ -34,9 +35,8 @@ class LLMService
'confidence' => 0.0,
'reason' => 'LLM not configured or request failed',
];
\think\Log::info('llmUrl:'.$this->url);
var_dump("in URL====".$this->url);
if ($this->url === '' || $this->model === '') {
\think\Log::warning('ReferenceCheck LLM: url or model not configured');
return $fallback;
}
@@ -73,11 +73,13 @@ class LLMService
$content = $this->postChat($payload);
if ($content === null) {
\think\Log::warning('ReferenceCheck LLM: postChat returned null');
return $fallback;
}
$parsed = $this->parseJson($content);
if ($parsed === null) {
\think\Log::warning('ReferenceCheck LLM: parseJson failed, raw=' . mb_substr($content, 0, 500));
return $fallback;
}
@@ -86,7 +88,11 @@ class LLMService
$this->normalizeConfidence(isset($parsed['confidence']) ? $parsed['confidence'] : 0),
$isMatch
);
\think\Log::info("confidence:".$confidence,[
'is_match' => $isMatch,
'confidence' => $confidence,
'reason' => $this->cleanReason((string)(isset($parsed['reason']) ? $parsed['reason'] : '')),
]);
return [
'is_match' => $isMatch,
'confidence' => $confidence,
@@ -763,13 +769,14 @@ PROMPT;
$raw = curl_exec($ch);
if ($raw === false) {
\think\Log::warning('ReferenceCheck LLM curl error: ' . curl_error($ch));
curl_close($ch);
return null;
}
$httpCode = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
\think\Log::info('httpCode:'.$httpCode);
curl_close($ch);
if ($httpCode < 200 || $httpCode >= 300) {
\think\Log::warning('ReferenceCheck LLM http ' . $httpCode . ': ' . mb_substr((string)$raw, 0, 500));
return null;
}
@@ -783,8 +790,8 @@ PROMPT;
if (isset($data['content'])) {
return (string)$data['content'];
}
}catch (Exception $exception){
var_dump($exception->getMessage());
} catch (Exception $exception) {
\think\Log::warning('ReferenceCheck LLM exception: ' . $exception->getMessage());
}
return null;