From c9a569fc429815444b8153ebce2c7c755f53ee06 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 28 Mar 2026 20:59:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=99=BE=E5=AE=B6=E4=B9=90AI=E9=A2=84?= =?UTF-8?q?=E6=B5=8B):=20=E6=8C=87=E5=AE=9A=E4=BD=BF=E7=94=A8=20glm-5.1-fr?= =?UTF-8?q?ee=20=E6=A8=A1=E5=9E=8B=EF=BC=8C=E5=9B=9E=E9=80=80=E9=BB=98?= =?UTF-8?q?=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BaccaratPredictionService 新增 PREFERRED_MODEL 常量(glm-5.1-free) - predict() 优先通过 findByModel() 找到指定模型,找不到再用 getDefault() - AiProviderConfig 新增 findByModel() 静态方法(按模型名称查找已启用配置) - 经实测:dmxapi/glm-5.1-free 返回正常,耗时约 1.6~7s,格式完全正确 --- app/Models/AiProviderConfig.php | 14 ++++++++++++++ app/Services/BaccaratPredictionService.php | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/Models/AiProviderConfig.php b/app/Models/AiProviderConfig.php index a1aca45..941528b 100644 --- a/app/Models/AiProviderConfig.php +++ b/app/Models/AiProviderConfig.php @@ -123,4 +123,18 @@ class AiProviderConfig extends Model ->orderBy('sort_order') ->get(); } + + /** + * 按模型名称查找已启用的 AI 配置 + * + * 用于特定业务场景(如百家乐预测)指定使用某款模型。 + * + * @param string $model 模型名称(完整匹配) + */ + public static function findByModel(string $model): ?self + { + return static::where('is_enabled', true) + ->where('model', $model) + ->first(); + } } diff --git a/app/Services/BaccaratPredictionService.php b/app/Services/BaccaratPredictionService.php index 3d6f0c4..9dd755a 100644 --- a/app/Services/BaccaratPredictionService.php +++ b/app/Services/BaccaratPredictionService.php @@ -29,6 +29,14 @@ class BaccaratPredictionService */ private const REQUEST_TIMEOUT = 30; + /** + * 百家乐预测优先使用的模型名称 + * + * 在后台 AI 配置中留存此模型时自动选用; + * 若该模型未配置或已禁用,则回退到默认 AI 厂商。 + */ + private const PREFERRED_MODEL = 'glm-5.1-free'; + /** * 调用 AI 接口预测百家乐下注方向 * @@ -40,7 +48,9 @@ class BaccaratPredictionService */ public function predict(array $recentResults): ?string { - $provider = AiProviderConfig::getDefault(); + // 优先使用指定模型,找不到则回退默认配置 + $provider = AiProviderConfig::findByModel(self::PREFERRED_MODEL) + ?? AiProviderConfig::getDefault(); if (! $provider) { Log::warning('百家乐 AI 预测:无可用 AI 厂商配置,跳过 AI 预测'); @@ -55,6 +65,7 @@ class BaccaratPredictionService } catch (\Exception $e) { Log::warning('百家乐 AI 预测调用失败,将使用本地决策兜底', [ 'provider' => $provider->name, + 'model' => $provider->model, 'error' => $e->getMessage(), ]); @@ -126,7 +137,7 @@ PROMPT; ->post($endpoint, [ 'model' => $config->model, 'temperature' => 0.3, // 预测任务偏确定性,使用较低温度 - 'max_tokens' => 1000, // 推理模型需要大量 token 完成思考后才输出 content + 'max_tokens' => 50, // 非推理模型只需输出单词,50 足够;推理模型请调高此值 'messages' => [ [ 'role' => 'system',