Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

refactor: rename Model::version to Model::name #278

Merged
merged 1 commit into from
Apr 14, 2025
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
2 changes: 1 addition & 1 deletion examples/chat-claude-anthropic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
$llm = new Claude(Claude::VERSION_37_SONNET);
$llm = new Claude(Claude::SONNET_37);

$chain = new Chain($platform, $llm);
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/chat-llama-azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

$platform = PlatformFactory::create($_ENV['AZURE_LLAMA_BASEURL'], $_ENV['AZURE_LLAMA_KEY']);
$llm = new Llama(Llama::LLAMA_3_3_70B_INSTRUCT);
$llm = new Llama(Llama::V3_3_70B_INSTRUCT);

$chain = new Chain($platform, $llm);
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
Expand Down
2 changes: 1 addition & 1 deletion examples/image-generator-dall-e-3.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);

$response = $platform->request(
model: new DallE(version: DallE::DALL_E_3),
model: new DallE(name: DallE::DALL_E_3),
input: 'A cartoon-style elephant with a long trunk and large ears.',
options: [
'response_format' => 'url', // Generate response as URL
Expand Down
20 changes: 10 additions & 10 deletions src/Bridge/Anthropic/Claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

final readonly class Claude implements LanguageModel
{
public const VERSION_3_HAIKU = 'claude-3-haiku-20240307';
public const VERSION_35_HAIKU = 'claude-3-5-haiku-20241022';
public const VERSION_3_SONNET = 'claude-3-sonnet-20240229';
public const VERSION_35_SONNET = 'claude-3-5-sonnet-20240620';
public const VERSION_35_SONNET_V2 = 'claude-3-5-sonnet-20241022';
public const VERSION_37_SONNET = 'claude-3-7-sonnet-20250219';
public const VERSION_3_OPUS = 'claude-3-opus-20240229';
public const HAIKU_3 = 'claude-3-haiku-20240307';
public const HAIKU_35 = 'claude-3-5-haiku-20241022';
public const SONNET_3 = 'claude-3-sonnet-20240229';
public const SONNET_35 = 'claude-3-5-sonnet-20240620';
public const SONNET_35_V2 = 'claude-3-5-sonnet-20241022';
public const SONNET_37 = 'claude-3-7-sonnet-20250219';
public const OPUS_3 = 'claude-3-opus-20240229';

/**
* @param array<string, mixed> $options The default options for the model usage
*/
public function __construct(
private string $version = self::VERSION_35_SONNET,
private string $name = self::SONNET_37,
private array $options = ['temperature' => 1.0, 'max_tokens' => 1000],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Anthropic/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function request(Model $model, object|array|string $input, array $options
}

$body = [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input->withoutSystemMessage()->jsonSerialize(),
];

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Azure/Meta/LlamaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function request(Model $model, object|array|string $input, array $options
'Authorization' => $this->apiKey,
],
'json' => array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input,
]),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Azure/OpenAI/EmbeddingsModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function request(Model $model, object|array|string $input, array $options
],
'query' => ['api-version' => $this->apiVersion],
'json' => array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'input' => $input,
]),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Azure/OpenAI/GPTModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function request(Model $model, object|array|string $input, array $options
],
'query' => ['api-version' => $this->apiVersion],
'json' => array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input,
]),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Azure/OpenAI/WhisperModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function request(Model $model, object|array|string $input, array $options
],
'query' => ['api-version' => $this->apiVersion],
'body' => array_merge($options, $model->getOptions(), [
'model' => $model->getVersion(),
'model' => $model->getName(),
'file' => fopen($input->path, 'r'),
]),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Google/Gemini.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
* @param array<string, mixed> $options The default options for the model usage
*/
public function __construct(
private string $version = self::GEMINI_2_PRO,
private string $name = self::GEMINI_2_PRO,
private array $options = ['temperature' => 1.0],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Google/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function request(Model $model, object|array|string $input, array $options

$url = sprintf(
'https://generativelanguage.googleapis.com/v1beta/models/%s:%s',
$model->getVersion(),
$model->getName(),
$options['stream'] ?? false ? 'streamGenerateContent' : 'generateContent',
);

Expand Down
36 changes: 18 additions & 18 deletions src/Bridge/Meta/Llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@

final readonly class Llama implements LanguageModel
{
public const LLAMA_3_3_70B_INSTRUCT = 'llama-3.3-70B-Instruct';
public const LLAMA_3_2_90B_VISION_INSTRUCT = 'llama-3.2-90b-vision-instruct';
public const LLAMA_3_2_11B_VISION_INSTRUCT = 'llama-3.2-11b-vision-instruct';
public const LLAMA_3_2_3B = 'llama-3.2-3b';
public const LLAMA_3_2_3B_INSTRUCT = 'llama-3.2-3b-instruct';
public const LLAMA_3_2_1B = 'llama-3.2-1b';
public const LLAMA_3_2_1B_INSTRUCT = 'llama-3.2-1b-instruct';
public const LLAMA_3_1_405B_INSTRUCT = 'llama-3.1-405b-instruct';
public const LLAMA_3_1_70B = 'llama-3.1-70b';
public const LLAMA_3_1_70B_INSTRUCT = 'llama-3-70b-instruct';
public const LLAMA_3_1_8B = 'llama-3.1-8b';
public const LLAMA_3_1_8B_INSTRUCT = 'llama-3.1-8b-instruct';
public const LLAMA_3_70B = 'llama-3-70b';
public const LLAMA_3_8B_INSTRUCT = 'llama-3-8b-instruct';
public const LLAMA_3_8B = 'llama-3-8b';
public const V3_3_70B_INSTRUCT = 'llama-3.3-70B-Instruct';
public const V3_2_90B_VISION_INSTRUCT = 'llama-3.2-90b-vision-instruct';
public const V3_2_11B_VISION_INSTRUCT = 'llama-3.2-11b-vision-instruct';
public const V3_2_3B = 'llama-3.2-3b';
public const V3_2_3B_INSTRUCT = 'llama-3.2-3b-instruct';
public const V3_2_1B = 'llama-3.2-1b';
public const V3_2_1B_INSTRUCT = 'llama-3.2-1b-instruct';
public const V3_1_405B_INSTRUCT = 'llama-3.1-405b-instruct';
public const V3_1_70B = 'llama-3.1-70b';
public const V3_1_70B_INSTRUCT = 'llama-3-70b-instruct';
public const V3_1_8B = 'llama-3.1-8b';
public const V3_1_8B_INSTRUCT = 'llama-3.1-8b-instruct';
public const V3_70B = 'llama-3-70b';
public const V3_8B_INSTRUCT = 'llama-3-8b-instruct';
public const V3_8B = 'llama-3-8b';

/**
* @param array<string, mixed> $options
*/
public function __construct(
private string $version = self::LLAMA_3_1_405B_INSTRUCT,
private string $name = self::V3_1_405B_INSTRUCT,
private array $options = [],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Ollama/LlamaModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function request(Model $model, object|array|string $input, array $options
return $this->httpClient->request('POST', sprintf('%s/api/chat', $this->hostUrl), [
'headers' => ['Content-Type' => 'application/json'],
'json' => [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input,
'stream' => false,
],
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/OpenAI/DallE.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

/** @param array<string, mixed> $options The default options for the model usage */
public function __construct(
private string $version = self::DALL_E_2,
private string $name = self::DALL_E_2,
private array $options = [],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

/** @return array<string, mixed> */
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/OpenAI/DallE/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function request(Model $model, object|array|string $input, array $options
return $this->httpClient->request('POST', 'https://api.openai.com/v1/images/generations', [
'auth_bearer' => $this->apiKey,
'json' => \array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'prompt' => $input,
]),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/OpenAI/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* @param array<string, mixed> $options
*/
public function __construct(
private string $version = self::TEXT_3_SMALL,
private string $name = self::TEXT_3_SMALL,
private array $options = [],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/OpenAI/Embeddings/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function request(Model $model, object|array|string $input, array $options
return $this->httpClient->request('POST', 'https://api.openai.com/v1/embeddings', [
'auth_bearer' => $this->apiKey,
'json' => array_merge($model->getOptions(), $options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'input' => $input,
]),
]);
Expand Down
12 changes: 6 additions & 6 deletions src/Bridge/OpenAI/GPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ final class GPT implements LanguageModel
* @param array<mixed> $options The default options for the model usage
*/
public function __construct(
private readonly string $version = self::GPT_4O,
private readonly string $name = self::GPT_4O,
private readonly array $options = ['temperature' => 1.0],
private bool $supportsAudioInput = false,
private bool $supportsImageInput = false,
private bool $supportsStructuredOutput = false,
) {
if (false === $this->supportsAudioInput) {
$this->supportsAudioInput = self::GPT_4O_AUDIO === $this->version;
$this->supportsAudioInput = self::GPT_4O_AUDIO === $this->name;
}

if (false === $this->supportsImageInput) {
$this->supportsImageInput = in_array($this->version, [self::GPT_4_TURBO, self::GPT_4O, self::GPT_4O_MINI, self::O1_MINI, self::O1_PREVIEW, self::O3_MINI, self::GPT_45_PREVIEW], true);
$this->supportsImageInput = in_array($this->name, [self::GPT_4_TURBO, self::GPT_4O, self::GPT_4O_MINI, self::O1_MINI, self::O1_PREVIEW, self::O3_MINI, self::GPT_45_PREVIEW], true);
}

if (false === $this->supportsStructuredOutput) {
$this->supportsStructuredOutput = in_array($this->version, [self::GPT_4O, self::GPT_4O_MINI, self::O3_MINI, self::GPT_45_PREVIEW], true);
$this->supportsStructuredOutput = in_array($this->name, [self::GPT_4O, self::GPT_4O_MINI, self::O3_MINI, self::GPT_45_PREVIEW], true);
}
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/OpenAI/GPT/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function request(Model $model, object|array|string $input, array $options
return $this->httpClient->request('POST', 'https://api.openai.com/v1/chat/completions', [
'auth_bearer' => $this->apiKey,
'json' => array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input,
]),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/OpenAI/Whisper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* @param array<string, mixed> $options
*/
public function __construct(
private string $version = self::WHISPER_1,
private string $name = self::WHISPER_1,
private array $options = [],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/OpenAI/Whisper/ModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function request(Model $model, object|array|string $input, array $options
'auth_bearer' => $this->apiKey,
'headers' => ['Content-Type' => 'multipart/form-data'],
'body' => array_merge($options, $model->getOptions(), [
'model' => $model->getVersion(),
'model' => $model->getName(),
'file' => fopen($input->path, 'r'),
]),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/OpenRouter/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function request(Model $model, object|array|string $input, array $options
return $this->httpClient->request('POST', 'https://openrouter.ai/api/v1/chat/completions', [
'auth_bearer' => $this->apiKey,
'json' => array_merge($options, [
'model' => $model->getVersion(),
'model' => $model->getName(),
'messages' => $input,
]),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/OpenRouter/GenericModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* @param array<string, mixed> $options
*/
public function __construct(
private string $version = Llama::LLAMA_3_2_90B_VISION_INSTRUCT,
private string $name = Llama::V3_2_90B_VISION_INSTRUCT,
private array $options = [],
) {
}

public function getVersion(): string
public function getName(): string
{
return $this->version;
return $this->name;
}

public function getOptions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Replicate/LlamaModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function request(Model $model, object|array|string $input, array $options
Assert::isInstanceOf($model, Llama::class);
Assert::isInstanceOf($input, MessageBagInterface::class);

return $this->client->request(sprintf('meta/meta-%s', $model->getVersion()), 'predictions', [
return $this->client->request(sprintf('meta/meta-%s', $model->getName()), 'predictions', [
'system' => $this->promptConverter->convertMessage($input->getSystemMessage() ?? new SystemMessage('')),
'prompt' => $this->promptConverter->convertToPrompt($input->withoutSystemMessage()),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Voyage/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function request(Model $model, object|string|array $input, array $options
return $this->httpClient->request('POST', 'https://api.voyageai.com/v1/embeddings', [
'auth_bearer' => $this->apiKey,
'json' => [
'model' => $model->getVersion(),
'model' => $model->getName(),
'input' => $input,
],
]);
Expand Down
Loading