42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
||
|
||
namespace App\Service\common\ai;
|
||
|
||
use App\BaseApp\BaseService;
|
||
|
||
/**
|
||
* AI Agent 工厂:按系统配置(nl_system_config + 平台表)选择供应商
|
||
* 未配置时回落 env(config/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();
|
||
}
|
||
}
|