{"id":15287223,"url":"https://github.com/php-llm/llm-chain-bundle","last_synced_at":"2025-04-13T05:08:16.890Z","repository":{"id":245746325,"uuid":"819118696","full_name":"php-llm/llm-chain-bundle","owner":"php-llm","description":"Symfony integration bundle for php-llm/llm-chain library.","archived":false,"fork":false,"pushed_at":"2025-04-12T20:29:15.000Z","size":450,"stargazers_count":18,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T05:08:05.985Z","etag":null,"topics":["llm","php","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-llm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-23T20:38:39.000Z","updated_at":"2025-04-03T12:17:14.000Z","dependencies_parsed_at":"2024-11-23T10:24:23.829Z","dependency_job_id":"07133d5c-a34f-4503-a372-261db7164efd","html_url":"https://github.com/php-llm/llm-chain-bundle","commit_stats":null,"previous_names":["php-llm/llm-chain-bundle"],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-llm%2Fllm-chain-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-llm%2Fllm-chain-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-llm%2Fllm-chain-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-llm%2Fllm-chain-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-llm","download_url":"https://codeload.github.com/php-llm/llm-chain-bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llm","php","symfony"],"created_at":"2024-09-30T15:26:47.457Z","updated_at":"2025-04-13T05:08:16.884Z","avatar_url":"https://github.com/php-llm.png","language":"PHP","funding_links":[],"categories":["PHP","Natural Language Processing"],"sub_categories":["Symfony Integrations"],"readme":"# LLM Chain Bundle\n\nSymfony integration bundle for [php-llm/llm-chain](https://github.com/php-llm/llm-chain) library.\n\n## Installation\n\n```bash\ncomposer require php-llm/llm-chain-bundle\n```\n\n## Configuration\n\n### Simple Example with OpenAI\n\n```yaml\n# config/packages/llm_chain.yaml\nllm_chain:\n    platform:\n        openai:\n            api_key: '%env(OPENAI_API_KEY)%'\n    chain:\n        default:\n            model:\n                name: 'GPT'\n```\n\n### Advanced Example with Anthropic, Azure, Google and multiple chains\n```yaml\n# config/packages/llm_chain.yaml\nllm_chain:\n    platform:\n        anthropic:\n            api_key: '%env(ANTHROPIC_API_KEY)%'\n        azure:\n            # multiple deployments possible\n            gpt_deployment:\n                base_url: '%env(AZURE_OPENAI_BASEURL)%'\n                deployment: '%env(AZURE_OPENAI_GPT)%'\n                api_key: '%env(AZURE_OPENAI_KEY)%'\n                api_version: '%env(AZURE_GPT_VERSION)%'\n        google:\n            api_key: '%env(GOOGLE_API_KEY)%'\n    chain:\n        rag:\n            platform: 'llm_chain.platform.azure.gpt_deployment'\n            structured_output: false # Disables support for \"output_structure\" option, default is true\n            model:\n                name: 'GPT'\n                version: 'gpt-4o-mini'\n            system_prompt: 'You are a helpful assistant that can answer questions.' # The default system prompt of the chain\n            include_tools: true # Include tool definitions at the end of the system prompt \n            tools:\n                # Referencing a service with #[AsTool] attribute\n                - 'PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\SimilaritySearch'\n                \n                # Referencing a service without #[AsTool] attribute\n                - service: 'App\\Chain\\Tool\\CompanyName'\n                  name: 'company_name'\n                  description: 'Provides the name of your company'\n                  method: 'foo' # Optional with default value '__invoke'\n                \n                # Referencing a chain =\u003e chain in chain 🤯\n                - service: 'llm_chain.chain.research'\n                  name: 'wikipedia_research'\n                  description: 'Can research on Wikipedia'\n                  is_chain: true\n        research:\n            platform: 'llm_chain.platform.anthropic'\n            model:\n                name: 'Claude'\n            tools: # If undefined, all tools are injected into the chain, use \"tools: false\" to disable tools.\n                - 'PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\Wikipedia'\n            fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true\n    store:\n        # also azure_search, mongodb and pinecone are supported as store type\n        chroma_db:\n            # multiple collections possible per type\n            default:\n                collection: 'my_collection'\n    embedder:\n        default:\n            # platform: 'llm_chain.platform.anthropic'\n            # store: 'llm_chain.store.chroma_db.default'\n            model:\n                name: 'Embeddings'\n                version: 'text-embedding-ada-002'\n```\n\n## Usage\n\n### Chain Service\n\nUse the `Chain` service to leverage GPT:\n```php\nuse PhpLlm\\LlmChain\\ChainInterface;\nuse PhpLlm\\LlmChain\\Model\\Message\\Message;\nuse PhpLlm\\LlmChain\\Model\\Message\\MessageBag;\n\nfinal readonly class MyService\n{\n    public function __construct(\n        private ChainInterface $chain,\n    ) {\n    }\n    \n    public function submit(string $message): string\n    {\n        $messages = new MessageBag(\n            Message::forSystem('Speak like a pirate.'),\n            Message::ofUser($message),\n        );\n\n        return $this-\u003echain-\u003ecall($messages);\n    }\n}\n```\n\n### Register Tools\n\nTo use existing tools, you can register them as a service:\n```yaml\nservices:\n    _defaults:\n        autowire: true\n        autoconfigure: true\n\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\Clock: ~\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\OpenMeteo: ~\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\SerpApi:\n        $apiKey: '%env(SERP_API_KEY)%'\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\SimilaritySearch: ~\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\Tavily:\n      $apiKey: '%env(TAVILY_API_KEY)%'\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\Wikipedia: ~\n    PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\YouTubeTranscriber: ~\n```\n\nCustom tools can be registered by using the `#[AsTool]` attribute:\n\n```php\nuse PhpLlm\\LlmChain\\Chain\\Toolbox\\Attribute\\AsTool;\n\n#[AsTool('company_name', 'Provides the name of your company')]\nfinal class CompanyName\n{\n    public function __invoke(): string\n    {\n        return 'ACME Corp.'\n    }\n}\n```\n\nThe chain configuration by default will inject all known tools into the chain.\n\nTo disable this behavior, set the `tools` option to `false`:\n```yaml\nllm_chain:\n    chain:\n        my_chain:\n            tools: false\n```\n\nTo inject only specific tools, list them in the configuration:\n```yaml\nllm_chain:\n    chain:\n        my_chain:\n            tools:\n                - 'PhpLlm\\LlmChain\\Chain\\Toolbox\\Tool\\SimilaritySearch'\n```\n\n### Profiler\n\nThe profiler panel provides insights into the chain's execution:\n\n![Profiler](./profiler.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-llm%2Fllm-chain-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-llm%2Fllm-chain-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-llm%2Fllm-chain-bundle/lists"}