Skip to content
Merged
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: 1 addition & 3 deletions src/platform/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
"symfony/property-info": "^6.4 || ^7.1",
"symfony/serializer": "^6.4 || ^7.1",
"symfony/type-info": "^7.2.3",
"symfony/uid": "^6.4 || ^7.1",
"webmozart/assert": "^1.11"
"symfony/uid": "^6.4 || ^7.1"
},
"require-dev": {
"async-aws/bedrock-runtime": "^0.1.0",
"codewithkyrian/transformers": "^0.5.3",
"phpstan/phpstan": "^2.1.17",
"phpstan/phpstan-symfony": "^2.0.6",
"phpstan/phpstan-webmozart-assert": "^2.0.0",
"phpunit/phpunit": "^11.5",
"symfony/console": "^6.4 || ^7.1",
"symfony/dotenv": "^6.4 || ^7.1",
Expand Down
12 changes: 6 additions & 6 deletions src/platform/src/Bridge/Azure/OpenAI/EmbeddingsModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace Symfony\AI\Platform\Bridge\Azure\OpenAI;

use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -34,11 +34,11 @@ public function __construct(
#[\SensitiveParameter] private string $apiKey,
) {
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
}

public function supports(Model $model): bool
Expand Down
12 changes: 6 additions & 6 deletions src/platform/src/Bridge/Azure/OpenAI/GPTModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace Symfony\AI\Platform\Bridge\Azure\OpenAI;

use Symfony\AI\Platform\Bridge\OpenAI\GPT;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -34,11 +34,11 @@ public function __construct(
#[\SensitiveParameter] private string $apiKey,
) {
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
}

public function supports(Model $model): bool
Expand Down
12 changes: 6 additions & 6 deletions src/platform/src/Bridge/Azure/OpenAI/WhisperModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

use Symfony\AI\Platform\Bridge\OpenAI\Whisper;
use Symfony\AI\Platform\Bridge\OpenAI\Whisper\Task;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -35,11 +35,11 @@ public function __construct(
#[\SensitiveParameter] private string $apiKey,
) {
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
}

public function supports(Model $model): bool
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/OpenAI/DallE/Base64Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;

use Webmozart\Assert\Assert;
use Symfony\AI\Platform\Exception\InvalidArgumentException;

/**
* @author Denis Zunke <denis.zunke@gmail.com>
Expand All @@ -21,6 +21,6 @@
public function __construct(
public string $encodedImage,
) {
Assert::stringNotEmpty($encodedImage, 'The base64 encoded image generated must be given.');
'' !== $encodedImage || throw new InvalidArgumentException('The base64 encoded image generated must be given.');
}
}
6 changes: 3 additions & 3 deletions src/platform/src/Bridge/OpenAI/DallE/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;

use Symfony\AI\Platform\Bridge\OpenAI\DallE;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
use Symfony\AI\Platform\Response\ResponseInterface as LlmResponse;
use Symfony\AI\Platform\ResponseConverterInterface as PlatformResponseConverter;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface as HttpResponse;
use Webmozart\Assert\Assert;

/**
* @see https://platform.openai.com/docs/api-reference/images/create
Expand All @@ -33,8 +33,8 @@ public function __construct(
#[\SensitiveParameter]
private string $apiKey,
) {
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
}

public function supports(Model $model): bool
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/OpenAI/DallE/UrlImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;

use Webmozart\Assert\Assert;
use Symfony\AI\Platform\Exception\InvalidArgumentException;

/**
* @author Denis Zunke <denis.zunke@gmail.com>
Expand All @@ -21,6 +21,6 @@
public function __construct(
public string $url,
) {
Assert::stringNotEmpty($url, 'The image url must be given.');
'' !== $url || throw new InvalidArgumentException('The image url must be given.');
}
}
6 changes: 3 additions & 3 deletions src/platform/src/Bridge/OpenAI/Embeddings/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
namespace Symfony\AI\Platform\Bridge\OpenAI\Embeddings;

use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -28,8 +28,8 @@ public function __construct(
#[\SensitiveParameter]
private string $apiKey,
) {
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
}

public function supports(Model $model): bool
Expand Down
6 changes: 3 additions & 3 deletions src/platform/src/Bridge/OpenAI/GPT/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace Symfony\AI\Platform\Bridge\OpenAI\GPT;

use Symfony\AI\Platform\Bridge\OpenAI\GPT;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -32,8 +32,8 @@ public function __construct(
private string $apiKey,
) {
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
}

public function supports(Model $model): bool
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/OpenAI/Whisper/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
namespace Symfony\AI\Platform\Bridge\OpenAI\Whisper;

use Symfony\AI\Platform\Bridge\OpenAI\Whisper;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface as BaseModelClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -28,7 +28,7 @@ public function __construct(
#[\SensitiveParameter]
private string $apiKey,
) {
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
}

public function supports(Model $model): bool
Expand Down
6 changes: 3 additions & 3 deletions src/platform/src/Bridge/OpenRouter/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\AI\Platform\Bridge\OpenRouter;

use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
Expand All @@ -20,7 +21,6 @@
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author rglozman
Expand All @@ -34,8 +34,8 @@ public function __construct(
#[\SensitiveParameter] private string $apiKey,
) {
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
}

public function supports(Model $model): bool
Expand Down
4 changes: 2 additions & 2 deletions src/platform/src/Bridge/Replicate/LlamaModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
namespace Symfony\AI\Platform\Bridge\Replicate;

use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Exception\InvalidArgumentException;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Webmozart\Assert\Assert;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand All @@ -34,7 +34,7 @@ public function supports(Model $model): bool

public function request(Model $model, array|string $payload, array $options = []): ResponseInterface
{
Assert::isInstanceOf($model, Llama::class);
$model instanceof Llama || throw new InvalidArgumentException(\sprintf('The model must be an instance of "%s".', Llama::class));

return $this->client->request(\sprintf('meta/meta-%s', $model->getName()), 'predictions', $payload);
}
Expand Down
Loading