php-llm / llm-chain-bundle
Symfony integration bundle for php-llm/llm-chain
Installs: 5 352
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=8.2
- php-llm/llm-chain: ^0.7
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/framework-bundle: ^6.4 || ^7.0
Requires (Dev)
- php-cs-fixer/shim: ^3.64
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.3
README
Symfony integration bundle for php-llm/llm-chain library.
Installation
composer require php-llm/llm-chain-bundle
Configuration
# config/packages/llm_chain.yaml llm_chain: platforms: azure_gpt: type: 'azure' base_url: '%env(AZURE_OPENAI_BASEURL)%' deployment: '%env(AZURE_OPENAI_GPT)%' api_key: '%env(AZURE_OPENAI_KEY)%' version: '%env(AZURE_OPENAI_VERSION)%' azure_embeddings: type: 'azure' base_url: '%env(AZURE_OPENAI_BASEURL)%' deployment: '%env(AZURE_OPENAI_EMBEDDINGS)%' api_key: '%env(AZURE_OPENAI_KEY)%' version: '%env(AZURE_OPENAI_VERSION)%' openai: type: 'openai' api_key: '%env(OPENAI_API_KEY)%' llms: azure_gpt: platform: 'azure_gpt' original_gpt: platform: 'openai' embeddings: azure_embeddings: platform: 'azure_embeddings' original_embeddings: platform: 'openai' stores: azure_search: engine: 'azure-search' api_key: '%env(AZURE_SEARCH_KEY)%' endpoint: '%env(AZURE_SEARCH_ENDPOINT)%' index_name: '%env(AZURE_SEARCH_INDEX)%' api_version: '2024-07-01' chroma_db: engine: 'chroma-db' collection_name: '%env(CHROMA_COLLECTION)%' mongodb: engine: 'mongodb' database_name: '%env(MONGODB_DATABASE)%' collection_name: '%env(MONGODB_COLLECTION)%' index_name: '%env(MONGODB_INDEX)%' vector_field_name: 'vector' bulk_write: false pinecone: engine: 'pinecone' namespace: 'partition' filter: { 'key' : 'value' } top_k: 5
Usage
Chain Service
Use the Chain
service to leverage GPT:
use PhpLlm\LlmChain\Chat; final readonly class MyService { public function __construct( private Chain $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\ToolBox\Tool\Clock: ~ PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo: ~ PhpLlm\LlmChain\ToolBox\Tool\SerpApi: $apiKey: '%env(SERP_API_KEY)%' PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch: ~ PhpLlm\LlmChain\ToolBox\Tool\Wikipedia: ~ PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber: ~
Custom tools can be registered by using the #[AsTool]
attribute:
use PhpLlm\LlmChain\ToolBox\AsTool; #[AsTool('company_name', 'Provides the name of your company')] final class CompanyName { public function __invoke(): string { return 'ACME Corp.' } }
Profiler
The profiler panel provides insights into the chain's execution: