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',