llm-html-extractor/symfony-bundle
Composer 安装命令:
composer require llm-html-extractor/symfony-bundle
包简介
Symfony bundle for extracting structured data from HTML using LLM providers
关键字:
README 文档
README
A powerful Symfony bundle for extracting structured data from HTML using LLM (Large Language Model) providers with a plugin architecture.
Features
- LLM-Based Extraction: Uses LLM providers (starting with Jina Reader) to extract structured data from HTML
- Type-Safe DTOs: Define extraction schemas using PHP attributes on your DTOs
- Hybrid Extraction: Easily combine LLM extraction with code-based extraction - use AI for complex fields and DomCrawler/XPath for simple structured data
- Extensible: Plugin architecture allows custom extractors for specific use cases
- Cacheable: Built-in caching support for LLM responses
- Logging: Optional logging for LLM requests/responses and cache operations
- Configurable: Flexible configuration for different LLM providers and caching strategies
Installation
composer require llm-html-extractor/symfony-bundle
Configuration
Create or update config/packages/llm_html_extractor.yaml:
llm_html_extractor: llm_client: client: jina_reader # or any service ID for custom client jina_reader: model: 'jinaai/readerlm-v2' # or 'jinaai/readerlm-v1.5' default_temperature: 0.0 # Default temperature for LLM requests (0.0 = deterministic) default_max_tokens: 64000 # Default max tokens for LLM responses http_client: base_uri: 'https://r.jina.ai' api_key: '%env(JINA_API_KEY)%' timeout: 600 headers: X-Custom-Header: 'value' cache: enabled: true ttl: 36000 # 10 hours pool: 'cache.app' logs: enabled: true # default: false logger: 'logger' # service ID of the logger to use
Alternatively, you can use an existing HTTP client service:
llm_html_extractor: llm_client: client: jina_reader jina_reader: model: 'jinaai/readerlm-v2' http_client: 'my_custom_http_client_service' # Service ID implementing HttpClientInterface
Using a Custom LLM Client
To use your own LLM client implementation, just set the client parameter to your service ID:
llm_html_extractor: llm_client: client: 'app.my_custom_llm_client' # Your service ID cache: enabled: true # Will automatically wrap your client with caching
Your custom client must implement LlmHtmlExtractor\SymfonyBundle\Client\LlmClientInterface. The bundle will validate this during container compilation and throw a clear error if the interface is not implemented.
Logging
The bundle provides comprehensive logging for debugging and monitoring:
- Request/Response Logging: When
logs.enabled: true, all LLM requests and responses are logged at info level - Cache Operations: Cache hits and misses are logged when both caching and logging are enabled
- Error Logging: Failed LLM requests are logged at error level with exception details
The decorators are applied in this order:
- Base LLM Client (e.g., JinaReaderLlmClient)
- LoggingLlmClient (if logs enabled) - logs requests/responses
- CacheableLlmClient (if cache enabled) - logs cache hits/misses
This means logged requests show the actual LLM calls (cache misses), not cached responses.
Usage
1. Define Your Extraction DTO
use LlmHtmlExtractor\SymfonyBundle\Attribute\AsLlmExtractableProperty; class ArticleExtractionResult { public function __construct( #[AsLlmExtractableProperty('Extract the article title')] public string $title, #[AsLlmExtractableProperty('Extract the author name')] public string $author, #[AsLlmExtractableProperty('Extract publication date in YYYY-MM-DD format')] public string $publishedAt, #[AsLlmExtractableProperty('Extract the main article content')] public string $content, ) {} }
2. Use the Extraction Handler
use LlmHtmlExtractor\SymfonyBundle\Extractor\ExtractionHandler; class ArticleScraper { public function __construct( private ExtractionHandler $extractionHandler, ) {} public function scrape(string $html): ArticleExtractionResult { return $this->extractionHandler->handle( ArticleExtractionResult::class, $html ); } }
3. Create Custom Extractors (Optional)
For specific extraction needs, implement the FromHtmlExtractorInterface:
use LlmHtmlExtractor\SymfonyBundle\Extractor\FromHtmlExtractorInterface; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; #[AutoconfigureTag('llm_extractor.extractor', ['priority' => 50])] class CustomPdfUrlExtractor implements FromHtmlExtractorInterface { public function extract(string $html, array $context = []): mixed { $crawler = new Crawler($html); return $crawler->filterXPath('//a[contains(@href, ".pdf")]') ->each(fn($node) => $node->attr('href')); } public function supports(string $className, string $propertyName): bool { return $className === ArticleExtractionResult::class && $propertyName === 'pdfUrls'; } }
Supported LLM Providers
Currently supported:
- Jina Reader (jinaai/readerlm-v2, jinaai/readerlm-v1.5)
- Uses vLLM OpenAI API standard endpoint (
/openai/v1/chat/completions) - Tested with Runpod serverless deployments
- Compatible with any vLLM deployment following the OpenAI API standard
- Uses vLLM OpenAI API standard endpoint (
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
llm-html-extractor/symfony-bundle 适用场景与选型建议
llm-html-extractor/symfony-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「parser」 「bundle」 「html」 「extraction」 「extractor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 llm-html-extractor/symfony-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 llm-html-extractor/symfony-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 llm-html-extractor/symfony-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
An MT940 bank statement parser for PHP
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-19