mgamadeus/ddd-ai 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mgamadeus/ddd-ai

Composer 安装命令:

composer require mgamadeus/ddd-ai

包简介

AI model management, prompt system, and Argus AI integration traits for mgamadeus/ddd

README 文档

README

AI model management, prompt system, and Argus AI integration traits for the mgamadeus/ddd framework.

Installation

composer require mgamadeus/ddd-ai

What it does

Provides the infrastructure for AI-powered features:

  • AIModel — catalog of 60+ AI models (OpenAI GPT-4o through GPT-5.4, o3/o4 reasoning, Meta Llama, image models FLUX/Imagen, audio, embeddings) with pricing and capability metadata
  • AIPrompt — template system with {%parameter%} substitution and token estimation
  • Argus AI traits — plug into any Argus repo entity to add LLM-powered loading via OpenAI/Google Gemini APIs
  • Batch services — OpenAI and OpenRouter server-side integration (batch controllers for Argus endpoints)
  • Cost tracking — per-operation cost estimation and budget enforcement

Configuration

AI Models

Models are loaded from config/app/AI/models.php (ships with 60+ model definitions). Override by placing your own config/app/AI/models.php in your project — project config takes priority.

AI Prompts

Prompts are markdown files loaded from config/app/AI/Prompts/ using dot-notation paths:

$prompt = AIPrompt::getService()->getAIPromptByName('Common.Texts.DetectedLanguage');
// Loads: config/app/AI/Prompts/Common/Texts/DetectedLanguage.md

Override any prompt by placing a file at the same path in your project's config/app/AI/Prompts/.

Environment Variables

The AI module itself requires no environment variables. The underlying Argus module needs ARGUS_API_ENDPOINT configured (see ddd-argus).

AI batch services require the OpenRouter/OpenAI API keys to be configured in the Argus batch gateway.

Service registration

Add to your project's services.yaml:

# DDD Module: ddd-ai
DDD\Domain\AI\Services\:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-ai/src/Domain/AI/Services/*'
    public: true

DDD\Domain\Batch\Services\AI\:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-ai/src/Domain/Batch/Services/AI/*'
    public: true

Usage

Adding AI to an Argus repo entity

use DDD\Domain\AI\Entities\Models\AIModel;
use DDD\Domain\AI\Repo\Argus\Attributes\ArgusLanguageModel;
use DDD\Domain\AI\Repo\Argus\Traits\ArgusAILanguageModelTrait;
use DDD\Domain\Base\Repo\Argus\Attributes\ArgusLoad;
use DDD\Domain\Base\Repo\Argus\Traits\ArgusTrait;
use DDD\Domain\Base\Repo\Argus\Utils\ArgusCache;

#[ArgusLoad(
    loadEndpoint: 'POST:/ai/openRouter/chatCompletions',
    cacheLevel: ArgusCache::CACHELEVEL_MEMORY_AND_DB,
    cacheTtl: ArgusCache::CACHELEVEL_NONE
)]
#[ArgusLanguageModel(
    defaultAIModelName: AIModel::MODEL_OPENAI_GPT5_2,
    defaultAIPromptName: 'My.Custom.Prompt',
)]
class ArgusMyAIEntity extends MyEntity
{
    use ArgusTrait, ArgusAILanguageModelTrait;

    public function getAIPromptWithParametersApplied(): AIPrompt
    {
        $prompt = $this->getAIPrompt();
        $prompt->setParameter('locale', 'de-DE');
        return $prompt;
    }

    public function getUserContent(): string|array
    {
        return 'The text to process';
    }

    protected function applyLoadResult(string $resultText): void
    {
        $this->result = $resultText;
    }
}

Supported vendors

  • OpenAI (default) — chat completions, embeddings, audio, image
  • Google Gemini — alternative payload format, auto-detected by vendor
  • Fal.ai — image generation models (FLUX, Sana, etc.)
  • OpenRouter — multi-model gateway

Batch controllers

The module ships BatchAIController with endpoints for:

  • /ai/openRouter/chatCompletions — LLM chat completions
  • /ai/openRouter/embeddings — text embeddings

Import in your project's routes.yaml to activate:

batch_ai:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-ai/src/Presentation/Api/Batch/AI'
    type: annotation
    prefix: '/api/batch'

Or extend the controller in your app to customize behavior.

Security

Batch endpoints must be secured with ROLE_SUPER_ADMIN. Ensure your security.yaml includes:

# config/symfony/default/packages/security.yaml
security:
    access_control:
        - { path: ^/api/batch, roles: ROLE_SUPER_ADMIN }

Argus clients authenticate automatically using the account specified by:

# Must have SUPER_ADMIN role — bearer token is sent with every Argus API call
CLI_DEFAULT_ACCOUNT_ID_FOR_CLI_OPERATIONS=1

See ddd-argus for the full security configuration example.

mgamadeus/ddd-ai 适用场景与选型建议

mgamadeus/ddd-ai 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 353 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mgamadeus/ddd-ai 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mgamadeus/ddd-ai 我们能提供哪些服务?
定制开发 / 二次开发

基于 mgamadeus/ddd-ai 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 353
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 43
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-14