Skip to content

feat: open contract for more flexible normalizer configuration #69

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

Merged
merged 1 commit into from
Jul 6, 2025

Conversation

chr-hertel
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Docs? no
Issues
License MIT

Cherry picking php-llm/llm-chain#372

Could fix part of #371 - the question for flexibility.

Why? Messages are given on platform calls and are given with the
`MessageInterface`. So it is very flexible what could be given on call.
Normalizers are only configured once, internally. So one side is highly
flexible, the other side not.

Giving the contract an interface allows creating own contracts with
whatever backed technology one wants. So more flexible. Additionally it
allows to add a contract that has an amount of normalizers one wants.
For making it easier i thought about having model contract sets. I did
it for anthropic, google and the platform itself.

So a custom contract could look like

```php

use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory;
use PhpLlm\LlmChain\Platform\Contract;

$platform = PlatformFactory::create(
    'my-api-key',
    contract: Contract::create(new MyOwnMessageBagNormalizer(), new MyOwnMessageThingyNormalizer()),
);
```

or, totally flexible:

```php
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory;

$platform = PlatformFactory::create(
    'my-api-key',
    contract: new MyVeryOwnContractUtilizingJsonStreamer(),
);
```

Maybe this could be a way for more flexibility with the combination of
non configurable normalizer and "unknown" message input?
@chr-hertel chr-hertel requested a review from Nyholm as a code owner July 6, 2025 20:48
@chr-hertel chr-hertel added the Platform Issues & PRs about the AI Platform component label Jul 6, 2025
@chr-hertel chr-hertel merged commit fac418b into main Jul 6, 2025
24 checks passed
@chr-hertel chr-hertel deleted the extendable-contract branch July 6, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Issues & PRs about the AI Platform component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants