Skip to content

Use capabilities instead of instanceof checks #299

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/Albert/EmbeddingsModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Albert;

use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand All @@ -35,7 +35,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Embeddings;
return $model->supports(Capability::INPUT_MULTIPLE);
}

public function request(Model $model, array|string $payload, array $options = []): RawResultInterface
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/Albert/GptModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Albert;

use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Gpt;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, array|string $payload, array $options = []): RawResultInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\AssistantMessage;
use Symfony\AI\Platform\Model;
Expand All @@ -33,7 +33,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::TOOL_CALLING);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\Content\Document;
use Symfony\AI\Platform\Model;
Expand All @@ -28,7 +28,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_PDF);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\Content\DocumentUrl;
use Symfony\AI\Platform\Model;
Expand All @@ -28,7 +28,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_MESSAGES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\Content\Image;
use Symfony\AI\Platform\Model;
Expand All @@ -30,7 +30,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_IMAGE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\Content\Image;
use Symfony\AI\Platform\Message\Content\ImageUrl;
use Symfony\AI\Platform\Model;

Expand All @@ -29,7 +28,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_IMAGE) || $model->supports(Capability::INPUT_MESSAGES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\MessageBagInterface;
Expand All @@ -33,7 +33,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_MESSAGES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\ToolCallMessage;
use Symfony\AI\Platform\Model;
Expand All @@ -32,7 +32,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::TOOL_CALLING);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic\Contract;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\JsonSchema\Factory;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Model;
Expand All @@ -31,7 +31,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::TOOL_CALLING);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/Anthropic/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic;

use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\AI\Platform\Result\RawHttpResult;
Expand All @@ -34,7 +35,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, array|string $payload, array $options = []): RawHttpResult
Expand Down
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/Anthropic/ResultConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Anthropic;

use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\RawHttpResult;
Expand All @@ -33,7 +34,7 @@ class ResultConverter implements ResultConverterInterface
{
public function supports(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::OUTPUT_TEXT) || $model->supports(Capability::TOOL_CALLING);
}

public function convert(RawHttpResult|RawResultInterface $result, array $options = []): ResultInterface
Expand Down
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/Azure/Meta/LlamaModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\AI\Platform\Bridge\Azure\Meta;

use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\AI\Platform\Result\RawHttpResult;
Expand All @@ -31,7 +32,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Llama;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, array|string $payload, array $options = []): RawHttpResult
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/Azure/Meta/LlamaResultConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Azure\Meta;

use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\RawResultInterface;
Expand All @@ -25,7 +25,7 @@
{
public function supports(Model $model): bool
{
return $model instanceof Llama;
return $model->supports(Capability::OUTPUT_TEXT);
}

public function convert(RawResultInterface $result, array $options = []): TextResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Azure\OpenAi;

use Symfony\AI\Platform\Bridge\OpenAi\Embeddings;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Embeddings;
return $model->supports(Capability::INPUT_MULTIPLE);
}

public function request(Model $model, array|string $payload, array $options = []): RawHttpResult
Expand Down
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/Azure/OpenAi/GptModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\AI\Platform\Bridge\Azure\OpenAi;

use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Gpt;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, object|array|string $payload, array $options = []): RawHttpResult
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/Azure/OpenAi/WhisperModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\AI\Platform\Bridge\Azure\OpenAi;

use Symfony\AI\Platform\Bridge\OpenAi\Whisper;
use Symfony\AI\Platform\Bridge\OpenAi\Whisper\Task;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Whisper;
return $model->supports(Capability::INPUT_AUDIO);
}

public function request(Model $model, array|string $payload, array $options = []): RawHttpResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use AsyncAws\BedrockRuntime\Result\InvokeModelResponse;
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand All @@ -36,7 +37,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, array|string $payload, array $options = []): RawBedrockResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\AI\Platform\Bridge\Bedrock\Anthropic;

use Symfony\AI\Platform\Bridge\Anthropic\Claude;
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\RawResultInterface;
Expand All @@ -28,7 +28,7 @@
{
public function supports(Model $model): bool
{
return $model instanceof Claude;
return $model->supports(Capability::OUTPUT_TEXT) || $model->supports(Capability::TOOL_CALLING);
}

public function convert(RawResultInterface|RawBedrockResult $result, array $options = []): ToolCallResult|TextResult
Expand Down
3 changes: 2 additions & 1 deletion src/platform/src/Bridge/Bedrock/Meta/LlamaModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use AsyncAws\BedrockRuntime\Input\InvokeModelRequest;
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;

Expand All @@ -30,7 +31,7 @@ public function __construct(

public function supports(Model $model): bool
{
return $model instanceof Llama;
return $model->supports(Capability::INPUT_MESSAGES);
}

public function request(Model $model, array|string $payload, array $options = []): RawBedrockResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\RawResultInterface;
Expand All @@ -26,7 +27,7 @@ class LlamaResultConverter implements ResultConverterInterface
{
public function supports(Model $model): bool
{
return $model instanceof Llama;
return $model->supports(Capability::OUTPUT_TEXT);
}

public function convert(RawResultInterface|RawBedrockResult $result, array $options = []): TextResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Bedrock\Nova\Contract;

use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer;
use Symfony\AI\Platform\Message\AssistantMessage;
use Symfony\AI\Platform\Model;
Expand All @@ -29,7 +29,7 @@ protected function supportedDataClass(): string

protected function supportsModel(Model $model): bool
{
return $model instanceof Nova;
return $model->supports(Capability::TOOL_CALLING);
}

/**
Expand Down
Loading
Loading