feat(百家乐AI预测): 指定使用 glm-5.1-free 模型,回退默认

- BaccaratPredictionService 新增 PREFERRED_MODEL 常量(glm-5.1-free)
- predict() 优先通过 findByModel() 找到指定模型,找不到再用 getDefault()
- AiProviderConfig 新增 findByModel() 静态方法(按模型名称查找已启用配置)
- 经实测:dmxapi/glm-5.1-free 返回正常,耗时约 1.6~7s,格式完全正确
This commit is contained in:
2026-03-28 20:59:50 +08:00
parent 348f4e0fe0
commit c9a569fc42
2 changed files with 27 additions and 2 deletions
+14
View File
@@ -123,4 +123,18 @@ class AiProviderConfig extends Model
->orderBy('sort_order') ->orderBy('sort_order')
->get(); ->get();
} }
/**
* 按模型名称查找已启用的 AI 配置
*
* 用于特定业务场景(如百家乐预测)指定使用某款模型。
*
* @param string $model 模型名称(完整匹配)
*/
public static function findByModel(string $model): ?self
{
return static::where('is_enabled', true)
->where('model', $model)
->first();
}
} }
+13 -2
View File
@@ -29,6 +29,14 @@ class BaccaratPredictionService
*/ */
private const REQUEST_TIMEOUT = 30; private const REQUEST_TIMEOUT = 30;
/**
* 百家乐预测优先使用的模型名称
*
* 在后台 AI 配置中留存此模型时自动选用;
* 若该模型未配置或已禁用,则回退到默认 AI 厂商。
*/
private const PREFERRED_MODEL = 'glm-5.1-free';
/** /**
* 调用 AI 接口预测百家乐下注方向 * 调用 AI 接口预测百家乐下注方向
* *
@@ -40,7 +48,9 @@ class BaccaratPredictionService
*/ */
public function predict(array $recentResults): ?string public function predict(array $recentResults): ?string
{ {
$provider = AiProviderConfig::getDefault(); // 优先使用指定模型,找不到则回退默认配置
$provider = AiProviderConfig::findByModel(self::PREFERRED_MODEL)
?? AiProviderConfig::getDefault();
if (! $provider) { if (! $provider) {
Log::warning('百家乐 AI 预测:无可用 AI 厂商配置,跳过 AI 预测'); Log::warning('百家乐 AI 预测:无可用 AI 厂商配置,跳过 AI 预测');
@@ -55,6 +65,7 @@ class BaccaratPredictionService
} catch (\Exception $e) { } catch (\Exception $e) {
Log::warning('百家乐 AI 预测调用失败,将使用本地决策兜底', [ Log::warning('百家乐 AI 预测调用失败,将使用本地决策兜底', [
'provider' => $provider->name, 'provider' => $provider->name,
'model' => $provider->model,
'error' => $e->getMessage(), 'error' => $e->getMessage(),
]); ]);
@@ -126,7 +137,7 @@ PROMPT;
->post($endpoint, [ ->post($endpoint, [
'model' => $config->model, 'model' => $config->model,
'temperature' => 0.3, // 预测任务偏确定性,使用较低温度 'temperature' => 0.3, // 预测任务偏确定性,使用较低温度
'max_tokens' => 1000, // 推理模型需要大量 token 完成思考后才输出 content 'max_tokens' => 50, // 推理模型只需输出单词,50 足够;推理模型请调高此值
'messages' => [ 'messages' => [
[ [
'role' => 'system', 'role' => 'system',