mostafax/ai-reporting-engine 问题修复 & 功能扩展

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

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

mostafax/ai-reporting-engine

Composer 安装命令:

composer require mostafax/ai-reporting-engine

包简介

AI Reporting Engine — turn natural-language prompts into report queries via a unified Regex + OpenAI pipeline, with prompt normalization, fingerprint caching, and a pluggable DSL builder.

README 文档

README

Turn natural-language prompts into report queries via a unified Regex + OpenAI pipeline, with prompt normalization, fingerprint caching, and a pluggable DSL builder.

📖 Documentation · العربية

The engine produces a DSL only — execution is delegated to mostafax/dynamic-hybrid-reporting-engine, fed by data replicated through mostafax/dual-layer-reporting-engine.

Pipeline

prompt
  → PromptNormalizer          (trim, lowercase, Arabic, punctuation) + fingerprint
  → PromptCache lookup        (hit → return stored DSL, skip parsing)
  → RegexParser               (token-free) ─┐
  → OpenAiParser              (on regex miss)┘→ IntermediateQuery (unified)
  → DslBuilder                (the only place that builds DSL)
  → PromptCache store         (intent + DSL, never rows)
  → ReportEngine.run(dsl)     (unchanged executor — dynamic-hybrid-reporting-engine)

Every parser returns the same IntermediateQuery; the rest of the system never knows whether the source was regex or AI.

Install

composer require mostafax/ai-reporting-engine
php artisan vendor:publish --tag=ai-reporting-config

Both reporting packages are hard requirements and are pulled in automatically.

Usage

use Mostafax\AiReportingEngine\ReportQueryPipeline;
use Mostafax\ReportingEngine\Core\Engine\ReportEngine;

public function search(Request $request, ReportQueryPipeline $pipeline, ReportEngine $engine)
{
    $result = $pipeline->process($request->string('question'));
    // $result: ['source'=>'regex|openai|cache', 'collection'=>..., 'query'=>..., 'dsl'=>..., 'cached'=>bool]

    $rows = $engine->run($result['dsl']);   // execute via the reporting engine
    return response()->json(['data' => $rows->data, 'source' => $result['source']]);
}

Extending (SOLID)

Every collaborator is an interface — bind your own in a service provider:

Interface Default Bind to override
PromptNormalizerInterface PromptNormalizer custom normalization
AiConfigInterface ConfigAiConfig (config) DB-backed settings
PromptCacheInterface MongoPromptCache Redis/SQL cache
MappingRepositoryInterface MongoMappingRepository your mapping store
EntityResolverInterface (none) resolve class name → id, etc.
$this->app->bind(EntityResolverInterface::class, MyClassResolver::class);

Parse method

Configure via ai-reporting.parse_method: auto (regex → OpenAI), regex (no tokens), or openai.

Cache storage

Each entry keeps: original prompt, normalized prompt, fingerprint, DSL, parser source, created_at, last_used_at, usage_count — never result rows.

License

MIT © Mostafa Elbayyar

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固