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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user