AI代码生成工具
This commit is contained in:
41
app/Service/common/ai/AiAgentFactory.php
Normal file
41
app/Service/common/ai/AiAgentFactory.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user