Files
lgp-admin-plus-api/app/Service/common/ai/AiAgentFactory.php

42 lines
1.3 KiB
PHP
Raw Normal View History

2026-08-10 15:51:00 +08:00
<?php
namespace App\Service\common\ai;
use App\BaseApp\BaseService;
/**
* AI Agent 工厂按系统配置nl_system_config + 平台表)选择供应商
* 未配置时回落 envconfig/ai.php目前支持讯飞星火 / DeepSeek
*/
class AiAgentFactory extends BaseService
{
public const PROVIDER_SPARK = 'spark';
public const PROVIDER_DEEPSEEK = 'deepseek';
public function __construct()
{
// 工厂解析不强制登录(内部调用)
$this->isAuth = false;
parent::__construct();
}
/**
* 获取 Agent 实例
*
* @param string|null $provider 为空则用系统配置 ai_active_provider / env 默认
*/
public function make(?string $provider = null): AiAgentInterface
{
$resolved = AiRuntimeConfigService::getInstance()->resolve($provider);
$name = strtolower(trim((string) ($resolved['provider'] ?? self::PROVIDER_DEEPSEEK)));
if ($name === self::PROVIDER_DEEPSEEK) {
return DeepSeekAiAgent::getInstance();
}
if ($name === self::PROVIDER_SPARK) {
return SparkAiAgent::getInstance();
}
$this->utils->errorThrow('不支持的 AI 供应商:' . $name);
return SparkAiAgent::getInstance();
}
}