diff --git a/src/Platform/Bridge/Anthropic/Contract/AnthropicSet.php b/src/Platform/Bridge/Anthropic/Contract/AnthropicSet.php new file mode 100644 index 00000000..39ecc935 --- /dev/null +++ b/src/Platform/Bridge/Anthropic/Contract/AnthropicSet.php @@ -0,0 +1,28 @@ + + */ +final readonly class AnthropicSet +{ + /** @return array */ + public static function get(): array + { + return [ + new AssistantMessageNormalizer(), + new DocumentNormalizer(), + new DocumentUrlNormalizer(), + new ImageNormalizer(), + new ImageUrlNormalizer(), + new MessageBagNormalizer(), + new ToolCallMessageNormalizer(), + new ToolNormalizer(), + ]; + } +} diff --git a/src/Platform/Bridge/Anthropic/PlatformFactory.php b/src/Platform/Bridge/Anthropic/PlatformFactory.php index 87abe1f5..0bdce54f 100644 --- a/src/Platform/Bridge/Anthropic/PlatformFactory.php +++ b/src/Platform/Bridge/Anthropic/PlatformFactory.php @@ -4,15 +4,9 @@ namespace PhpLlm\LlmChain\Platform\Bridge\Anthropic; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\AssistantMessageNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\DocumentNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\DocumentUrlNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\ImageNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\ImageUrlNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\MessageBagNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\ToolCallMessageNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\ToolNormalizer; +use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Contract\AnthropicSet; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -27,22 +21,14 @@ public static function create( string $apiKey, string $version = '2023-06-01', ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); return new Platform( [new ModelClient($httpClient, $apiKey, $version)], [new ResponseConverter()], - Contract::create( - new AssistantMessageNormalizer(), - new DocumentNormalizer(), - new DocumentUrlNormalizer(), - new ImageNormalizer(), - new ImageUrlNormalizer(), - new MessageBagNormalizer(), - new ToolCallMessageNormalizer(), - new ToolNormalizer(), - ) + $contract ?? Contract::create(...AnthropicSet::get()), ); } } diff --git a/src/Platform/Bridge/Azure/Meta/PlatformFactory.php b/src/Platform/Bridge/Azure/Meta/PlatformFactory.php index 51e4c3d5..8b2a8ab6 100644 --- a/src/Platform/Bridge/Azure/Meta/PlatformFactory.php +++ b/src/Platform/Bridge/Azure/Meta/PlatformFactory.php @@ -4,6 +4,7 @@ namespace PhpLlm\LlmChain\Platform\Bridge\Azure\Meta; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -18,9 +19,10 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $modelClient = new LlamaHandler($httpClient ?? HttpClient::create(), $baseUrl, $apiKey); - return new Platform([$modelClient], [$modelClient]); + return new Platform([$modelClient], [$modelClient], $contract); } } diff --git a/src/Platform/Bridge/Azure/OpenAI/PlatformFactory.php b/src/Platform/Bridge/Azure/OpenAI/PlatformFactory.php index 6e4e1288..dc5daab4 100644 --- a/src/Platform/Bridge/Azure/OpenAI/PlatformFactory.php +++ b/src/Platform/Bridge/Azure/OpenAI/PlatformFactory.php @@ -8,6 +8,7 @@ use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT\ResponseConverter; use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\AudioNormalizer; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -24,6 +25,7 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); $embeddingsResponseFactory = new EmbeddingsModelClient($httpClient, $baseUrl, $deployment, $apiVersion, $apiKey); @@ -33,7 +35,7 @@ public static function create( return new Platform( [$GPTResponseFactory, $embeddingsResponseFactory, $whisperResponseFactory], [new ResponseConverter(), new Embeddings\ResponseConverter(), new \PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\ResponseConverter()], - Contract::create(new AudioNormalizer()), + $contract ?? Contract::create(new AudioNormalizer()), ); } } diff --git a/src/Platform/Bridge/Bedrock/Platform.php b/src/Platform/Bridge/Bedrock/Platform.php index 9dd887f0..b0804810 100644 --- a/src/Platform/Bridge/Bedrock/Platform.php +++ b/src/Platform/Bridge/Bedrock/Platform.php @@ -6,6 +6,7 @@ use PhpLlm\LlmChain\Platform\Bridge\Bedrock\Nova\Contract as NovaContract; use PhpLlm\LlmChain\Platform\Bridge\Meta\Contract as LlamaContract; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Exception\RuntimeException; use PhpLlm\LlmChain\Platform\Model; use PhpLlm\LlmChain\Platform\PlatformInterface; @@ -26,7 +27,7 @@ class Platform implements PlatformInterface */ public function __construct( iterable $modelClients, - private ?Contract $contract = null, + private ?ContractInterface $contract = null, ) { $this->contract = $contract ?? Contract::create( new AnthropicContract\AssistantMessageNormalizer(), diff --git a/src/Platform/Bridge/Bedrock/PlatformFactory.php b/src/Platform/Bridge/Bedrock/PlatformFactory.php index e2315682..7528e96f 100644 --- a/src/Platform/Bridge/Bedrock/PlatformFactory.php +++ b/src/Platform/Bridge/Bedrock/PlatformFactory.php @@ -8,6 +8,7 @@ use PhpLlm\LlmChain\Platform\Bridge\Bedrock\Anthropic\ClaudeHandler; use PhpLlm\LlmChain\Platform\Bridge\Bedrock\Meta\LlamaModelClient; use PhpLlm\LlmChain\Platform\Bridge\Bedrock\Nova\NovaHandler; +use PhpLlm\LlmChain\Platform\ContractInterface; /** * @author Björn Altmann @@ -16,11 +17,12 @@ { public static function create( BedrockRuntimeClient $bedrockRuntimeClient = new BedrockRuntimeClient(), + ?ContractInterface $contract = null, ): Platform { $modelClient[] = new ClaudeHandler($bedrockRuntimeClient); $modelClient[] = new NovaHandler($bedrockRuntimeClient); $modelClient[] = new LlamaModelClient($bedrockRuntimeClient); - return new Platform($modelClient); + return new Platform($modelClient, $contract); } } diff --git a/src/Platform/Bridge/Google/Contract/GoogleSet.php b/src/Platform/Bridge/Google/Contract/GoogleSet.php new file mode 100644 index 00000000..d4e0661c --- /dev/null +++ b/src/Platform/Bridge/Google/Contract/GoogleSet.php @@ -0,0 +1,25 @@ + + */ +final readonly class GoogleSet +{ + /** @return array */ + public static function get(): array + { + return [ + new AssistantMessageNormalizer(), + new MessageBagNormalizer(), + new ToolNormalizer(), + new ToolCallMessageNormalizer(), + new UserMessageNormalizer(), + ]; + } +} diff --git a/src/Platform/Bridge/Google/PlatformFactory.php b/src/Platform/Bridge/Google/PlatformFactory.php index da224f29..5a08a420 100644 --- a/src/Platform/Bridge/Google/PlatformFactory.php +++ b/src/Platform/Bridge/Google/PlatformFactory.php @@ -4,13 +4,10 @@ namespace PhpLlm\LlmChain\Platform\Bridge\Google; -use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\AssistantMessageNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\MessageBagNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\ToolCallMessageNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\ToolNormalizer; -use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\UserMessageNormalizer; +use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\GoogleSet; use PhpLlm\LlmChain\Platform\Bridge\Google\Embeddings\ModelClient; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -24,17 +21,16 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); $responseHandler = new ModelHandler($httpClient, $apiKey); $embeddings = new ModelClient($httpClient, $apiKey); - return new Platform([$responseHandler, $embeddings], [$responseHandler, $embeddings], Contract::create( - new AssistantMessageNormalizer(), - new MessageBagNormalizer(), - new ToolNormalizer(), - new ToolCallMessageNormalizer(), - new UserMessageNormalizer(), - )); + return new Platform( + [$responseHandler, $embeddings], + [$responseHandler, $embeddings], + $contract ?? Contract::create(...GoogleSet::get()), + ); } } diff --git a/src/Platform/Bridge/HuggingFace/PlatformFactory.php b/src/Platform/Bridge/HuggingFace/PlatformFactory.php index e46ae69a..c488bbc5 100644 --- a/src/Platform/Bridge/HuggingFace/PlatformFactory.php +++ b/src/Platform/Bridge/HuggingFace/PlatformFactory.php @@ -7,6 +7,7 @@ use PhpLlm\LlmChain\Platform\Bridge\HuggingFace\Contract\FileNormalizer; use PhpLlm\LlmChain\Platform\Bridge\HuggingFace\Contract\MessageBagNormalizer; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -21,13 +22,14 @@ public static function create( string $apiKey, string $provider = Provider::HF_INFERENCE, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); return new Platform( [new ModelClient($httpClient, $provider, $apiKey)], [new ResponseConverter()], - Contract::create( + $contract ?? Contract::create( new FileNormalizer(), new MessageBagNormalizer(), ), diff --git a/src/Platform/Bridge/Mistral/PlatformFactory.php b/src/Platform/Bridge/Mistral/PlatformFactory.php index 47ab83a0..66554fcf 100644 --- a/src/Platform/Bridge/Mistral/PlatformFactory.php +++ b/src/Platform/Bridge/Mistral/PlatformFactory.php @@ -10,6 +10,7 @@ use PhpLlm\LlmChain\Platform\Bridge\Mistral\Llm\ModelClient as MistralModelClient; use PhpLlm\LlmChain\Platform\Bridge\Mistral\Llm\ResponseConverter as MistralResponseConverter; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -23,13 +24,14 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); return new Platform( [new EmbeddingsModelClient($httpClient, $apiKey), new MistralModelClient($httpClient, $apiKey)], [new EmbeddingsResponseConverter(), new MistralResponseConverter()], - Contract::create(new ToolNormalizer()), + $contract ?? Contract::create(new ToolNormalizer()), ); } } diff --git a/src/Platform/Bridge/Ollama/PlatformFactory.php b/src/Platform/Bridge/Ollama/PlatformFactory.php index c07e9699..b0134b71 100644 --- a/src/Platform/Bridge/Ollama/PlatformFactory.php +++ b/src/Platform/Bridge/Ollama/PlatformFactory.php @@ -4,6 +4,7 @@ namespace PhpLlm\LlmChain\Platform\Bridge\Ollama; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -16,10 +17,11 @@ final class PlatformFactory public static function create( string $hostUrl = 'http://localhost:11434', ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); $handler = new LlamaModelHandler($httpClient, $hostUrl); - return new Platform([$handler], [$handler]); + return new Platform([$handler], [$handler], $contract); } } diff --git a/src/Platform/Bridge/OpenAI/PlatformFactory.php b/src/Platform/Bridge/OpenAI/PlatformFactory.php index f27c76b7..b98a7bc6 100644 --- a/src/Platform/Bridge/OpenAI/PlatformFactory.php +++ b/src/Platform/Bridge/OpenAI/PlatformFactory.php @@ -13,6 +13,7 @@ use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\ModelClient as WhisperModelClient; use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\ResponseConverter as WhisperResponseConverter; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -26,6 +27,7 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); @@ -44,7 +46,7 @@ public static function create( $dallEModelClient, new WhisperResponseConverter(), ], - Contract::create(new AudioNormalizer()), + $contract ?? Contract::create(new AudioNormalizer()), ); } } diff --git a/src/Platform/Bridge/OpenRouter/PlatformFactory.php b/src/Platform/Bridge/OpenRouter/PlatformFactory.php index bd0cb684..6bac24fc 100644 --- a/src/Platform/Bridge/OpenRouter/PlatformFactory.php +++ b/src/Platform/Bridge/OpenRouter/PlatformFactory.php @@ -8,6 +8,7 @@ use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\MessageBagNormalizer; use PhpLlm\LlmChain\Platform\Bridge\Google\Contract\UserMessageNormalizer; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -21,14 +22,19 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); $handler = new Client($httpClient, $apiKey); - return new Platform([$handler], [$handler], Contract::create( - new AssistantMessageNormalizer(), - new MessageBagNormalizer(), - new UserMessageNormalizer(), - )); + return new Platform( + [$handler], + [$handler], + $contract ?? Contract::create( + new AssistantMessageNormalizer(), + new MessageBagNormalizer(), + new UserMessageNormalizer(), + ), + ); } } diff --git a/src/Platform/Bridge/Replicate/PlatformFactory.php b/src/Platform/Bridge/Replicate/PlatformFactory.php index f150ff0a..48cfa7a7 100644 --- a/src/Platform/Bridge/Replicate/PlatformFactory.php +++ b/src/Platform/Bridge/Replicate/PlatformFactory.php @@ -6,6 +6,7 @@ use PhpLlm\LlmChain\Platform\Bridge\Replicate\Contract\LlamaMessageBagNormalizer; use PhpLlm\LlmChain\Platform\Contract; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\Clock\Clock; use Symfony\Component\HttpClient\HttpClient; @@ -20,11 +21,12 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { return new Platform( [new LlamaModelClient(new Client($httpClient ?? HttpClient::create(), new Clock(), $apiKey))], [new LlamaResponseConverter()], - Contract::create(new LlamaMessageBagNormalizer()), + $contract ?? Contract::create(new LlamaMessageBagNormalizer()), ); } } diff --git a/src/Platform/Bridge/Voyage/PlatformFactory.php b/src/Platform/Bridge/Voyage/PlatformFactory.php index f4bb9ec6..cf507bb4 100644 --- a/src/Platform/Bridge/Voyage/PlatformFactory.php +++ b/src/Platform/Bridge/Voyage/PlatformFactory.php @@ -4,6 +4,7 @@ namespace PhpLlm\LlmChain\Platform\Bridge\Voyage; +use PhpLlm\LlmChain\Platform\ContractInterface; use PhpLlm\LlmChain\Platform\Platform; use Symfony\Component\HttpClient\EventSourceHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -17,10 +18,11 @@ public static function create( #[\SensitiveParameter] string $apiKey, ?HttpClientInterface $httpClient = null, + ?ContractInterface $contract = null, ): Platform { $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); $handler = new ModelHandler($httpClient, $apiKey); - return new Platform([$handler], [$handler]); + return new Platform([$handler], [$handler], $contract); } } diff --git a/src/Platform/Contract.php b/src/Platform/Contract.php index dff53424..e85b53f3 100644 --- a/src/Platform/Contract.php +++ b/src/Platform/Contract.php @@ -4,17 +4,7 @@ namespace PhpLlm\LlmChain\Platform; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\AssistantMessageNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\Content\AudioNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\Content\ImageNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\Content\ImageUrlNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\Content\TextNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\MessageBagNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\SystemMessageNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\ToolCallMessageNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Message\UserMessageNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\Response\ToolCallNormalizer; -use PhpLlm\LlmChain\Platform\Contract\Normalizer\ToolNormalizer; +use PhpLlm\LlmChain\Platform\Contract\PlatformSet; use PhpLlm\LlmChain\Platform\Tool\Tool; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -23,7 +13,7 @@ /** * @author Christopher Hertel */ -final readonly class Contract +final readonly class Contract implements ContractInterface { public const CONTEXT_MODEL = 'model'; @@ -34,27 +24,8 @@ public function __construct( public static function create(NormalizerInterface ...$normalizer): self { - // Messages - $normalizer[] = new MessageBagNormalizer(); - $normalizer[] = new AssistantMessageNormalizer(); - $normalizer[] = new SystemMessageNormalizer(); - $normalizer[] = new ToolCallMessageNormalizer(); - $normalizer[] = new UserMessageNormalizer(); - - // Message Content - $normalizer[] = new AudioNormalizer(); - $normalizer[] = new ImageNormalizer(); - $normalizer[] = new ImageUrlNormalizer(); - $normalizer[] = new TextNormalizer(); - - // Options - $normalizer[] = new ToolNormalizer(); - - // Response - $normalizer[] = new ToolCallNormalizer(); - return new self( - new Serializer($normalizer), + new Serializer(array_merge($normalizer, PlatformSet::get())), ); } diff --git a/src/Platform/Contract/PlatformSet.php b/src/Platform/Contract/PlatformSet.php new file mode 100644 index 00000000..4bf6bfe4 --- /dev/null +++ b/src/Platform/Contract/PlatformSet.php @@ -0,0 +1,49 @@ + + */ +final readonly class PlatformSet +{ + /** @return array */ + public static function get(): array + { + return [ + // Messages + new MessageBagNormalizer(), + new AssistantMessageNormalizer(), + new SystemMessageNormalizer(), + new ToolCallMessageNormalizer(), + new UserMessageNormalizer(), + + // Message Content + new AudioNormalizer(), + new ImageNormalizer(), + new ImageUrlNormalizer(), + new TextNormalizer(), + + // Options + new ToolNormalizer(), + + // Response + new ToolCallNormalizer(), + ]; + } +} diff --git a/src/Platform/ContractInterface.php b/src/Platform/ContractInterface.php new file mode 100644 index 00000000..a961aa6d --- /dev/null +++ b/src/Platform/ContractInterface.php @@ -0,0 +1,27 @@ + + */ +interface ContractInterface +{ + /** + * @param object|array|string $input + * + * @return array|string + */ + public function createRequestPayload(Model $model, object|array|string $input): string|array; + + /** + * @param Tool[] $tools + * + * @return array + */ + public function createToolOption(array $tools, Model $model): array; +} diff --git a/src/Platform/Platform.php b/src/Platform/Platform.php index 369eb228..f525fbb5 100644 --- a/src/Platform/Platform.php +++ b/src/Platform/Platform.php @@ -31,7 +31,7 @@ final class Platform implements PlatformInterface public function __construct( iterable $modelClients, iterable $responseConverter, - private ?Contract $contract = null, + private ?ContractInterface $contract = null, ) { $this->contract = $contract ?? Contract::create(); $this->modelClients = $modelClients instanceof \Traversable ? iterator_to_array($modelClients) : $modelClients;