Skip to content

Add custom Contract service injection support for Platform configurations #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 26, 2025

This PR implements support for injecting custom Contract services into Platform instances via bundle configuration, enabling platform-specific customization of request/response handling, authentication, and other contract logic.

Changes

Core Implementation

  • Added ContractInterface - New interface that custom contract services must implement for type safety
  • Enhanced Configuration - Added optional contract key to all platform configurations (anthropic, azure, google, openai, mistral, openrouter)
  • Updated Extension Logic - Modified platform creation to inject contract service references when provided
  • Autoconfiguration Support - Registered ContractInterface for automatic service discovery

Configuration Example

llm_chain:
  platforms:
    openai:
      api_key: '%env(OPENAI_API_KEY)%'
      contract: '@my_custom_openai_contract_service'
    azure_openai:
      api_key: '%env(AZURE_OPENAI_API_KEY)%'
      contract: '@my_custom_azure_contract_service'

Key Features

  • Optional and Backward Compatible - Contract injection defaults to null, existing configurations work unchanged
  • Type Safe - Custom contracts must implement ContractInterface
  • All Platform Types Supported - Works with OpenAI, Azure, Google, Anthropic, Mistral, and OpenRouter
  • Symfony Service Integration - Uses standard service reference patterns (@service_name)
  • Minimal Changes - Only additions, no modifications to existing functionality

Usage

  1. Create a custom contract service implementing ContractInterface
  2. Register it in Symfony (autoconfigured with llm_chain.platform.contract tag)
  3. Reference it in platform configuration using contract: '@your_service_name'

Testing

  • Comprehensive unit tests for configuration and extension logic
  • Integration tests validating end-to-end workflow
  • Backward compatibility tests ensuring existing configs continue working
  • Example implementation demonstrating real-world usage

Documentation

  • Updated README with configuration examples
  • Added complete section on creating and using custom contract services
  • Included integration examples for different platforms

Fixes #95.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/OskarStark/enum-helper/zipball/adccc8c099db61cb26497a1e1987fc95ebda02a9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/eea219a577085bd13ff0cb644a422c20798316c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/QkJ5qa /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/php-llm/llm-chain/zipball/dbd6ff8e728a2736cd2b4f49b3e272ec82225824
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/92dde6a5919e34835c506ac8c523ef095a95ed62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9b30d6fd026b2c132b3985ce6b23bec09ab3aa68
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/a5c75038693ad2e8d4b6c15ba2403532647830c4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/3473f61172093b2da7de1fb5782e1f24cc036dc3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/694d156164372abbd149a4b85ccda2e4670c0e16
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/a8a7e30534b0eb0c77cd9d07e82de1a114389f5e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/clock/zipball/b81435fbd6648ea425d1ee96a2d8e68f4ceacd24
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/QkJ5qa /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/http-client-contracts/zipball/75d7043853a42837e68111812f4d964b01e5101c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/http-client/zipball/57e4fb86314015a695a750ace358d07a7e37b8a9
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-php83/zipball/2fb86d65e2d424369ad2905e83b236a8805ba491
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/polyfill-uuid/zipball/21533be36c24be3f4b1669c4725c7d1d2bab4ae2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/QkJ5qa /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/property-access/zipball/3bcf43665d6aff90547b005348e1e351f4e2174b
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/property-info/zipball/200d230d8553610ada73ac557501dc4609aad31f
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/serializer/zipball/2d86f81b1c506d7e1578789f93280dab4b8411bb
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/type-info/zipball/bc9af22e25796d98078f69c0749ab3a9d3454786
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/symfony/uid/zipball/7beeb2b885cd584cd01e126c5777206ae4c3c6a3
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/QkJ5qa /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/QkJ5qa /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/keoyLK /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Allow custom Contract service injection in Platform class via bundle config Add custom Contract service injection support for Platform configurations Jun 26, 2025
@Copilot Copilot AI requested a review from chr-hertel June 26, 2025 17:10
Copilot finished work on behalf of chr-hertel June 26, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom Contract service injection in Platform class via bundle config
2 participants