承接 php-llm/llm-chain-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

php-llm/llm-chain-bundle

最新稳定版本:0.25.0

Composer 安装命令:

composer require php-llm/llm-chain-bundle

包简介

Symfony integration bundle for php-llm/llm-chain

README 文档

README

Important

PHP LLM becomes Symfony AI - this project moved to github.com/symfony/ai. Please use the new repository for all future development, issues, and contributions. Thanks for your contributions - we hope to see you at Symfony AI!

Symfony integration bundle for php-llm/llm-chain library.

Installation

composer require php-llm/llm-chain-bundle

Configuration

Basic Example with OpenAI

# config/packages/llm_chain.yaml llm_chain: platform: openai: api_key: '%env(OPENAI_API_KEY)%' chain: default: model: name: 'GPT'

Advanced Example with Anthropic, Azure, Google and multiple chains

# config/packages/llm_chain.yaml llm_chain: platform: anthropic: api_key: '%env(ANTHROPIC_API_KEY)%' azure: # multiple deployments possible gpt_deployment: base_url: '%env(AZURE_OPENAI_BASEURL)%' deployment: '%env(AZURE_OPENAI_GPT)%' api_key: '%env(AZURE_OPENAI_KEY)%' api_version: '%env(AZURE_GPT_VERSION)%' google: api_key: '%env(GOOGLE_API_KEY)%' chain: rag: platform: 'llm_chain.platform.azure.gpt_deployment' structured_output: false # Disables support for "output_structure" option, default is true model: name: 'GPT' version: 'gpt-4o-mini' system_prompt: 'You are a helpful assistant that can answer questions.' # The default system prompt of the chain include_tools: true # Include tool definitions at the end of the system prompt  tools: # Referencing a service with #[AsTool] attribute - 'PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch' # Referencing a service without #[AsTool] attribute - service: 'App\Chain\Tool\CompanyName' name: 'company_name' description: 'Provides the name of your company' method: 'foo' # Optional with default value '__invoke' # Referencing a chain => chain in chain ???? - service: 'llm_chain.chain.research' name: 'wikipedia_research' description: 'Can research on Wikipedia' is_chain: true research: platform: 'llm_chain.platform.anthropic' model: name: 'Claude' tools: # If undefined, all tools are injected into the chain, use "tools: false" to disable tools. - 'PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia' fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true store: # also azure_search, mongodb and pinecone are supported as store type chroma_db: # multiple collections possible per type default: collection: 'my_collection' embedder: default: # platform: 'llm_chain.platform.anthropic' # store: 'llm_chain.store.chroma_db.default' model: name: 'Embeddings' version: 'text-embedding-ada-002'

Usage

Chain Service

Use the Chain service to leverage GPT:

use PhpLlm\LlmChain\ChainInterface; use PhpLlm\LlmChain\Model\Message\Message; use PhpLlm\LlmChain\Model\Message\MessageBag; final readonly class MyService { public function __construct( private ChainInterface $chain, ) { } public function submit(string $message): string { $messages = new MessageBag( Message::forSystem('Speak like a pirate.'), Message::ofUser($message), ); return $this->chain->call($messages); } }

Register Tools

To use existing tools, you can register them as a service:

services: _defaults: autowire: true autoconfigure: true PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock: ~ PhpLlm\LlmChain\Chain\Toolbox\Tool\OpenMeteo: ~ PhpLlm\LlmChain\Chain\Toolbox\Tool\SerpApi: $apiKey: '%env(SERP_API_KEY)%' PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch: ~ PhpLlm\LlmChain\Chain\Toolbox\Tool\Tavily: $apiKey: '%env(TAVILY_API_KEY)%' PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia: ~ PhpLlm\LlmChain\Chain\Toolbox\Tool\YouTubeTranscriber: ~

Custom tools can be registered by using the #[AsTool] attribute:

use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool; #[AsTool('company_name', 'Provides the name of your company')] final class CompanyName { public function __invoke(): string { return 'ACME Corp.' } }

The chain configuration by default will inject all known tools into the chain.

To disable this behavior, set the tools option to false:

llm_chain: chain: my_chain: tools: false

To inject only specific tools, list them in the configuration:

llm_chain: chain: my_chain: tools: - 'PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch'

Profiler

The profiler panel provides insights into the chain's execution:

Profiler

统计信息

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

GitHub 信息

  • Stars: 37
  • Watchers: 4
  • Forks: 8
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固