Skip to content

Commit 349f4af

Browse files
authored
refactor: rename Model::version to Model::name (#278)
I'm currently working on an integration for Hugging Face and I think `$version` is misleading since this could also use quite different Models of one family. Looking more into the direction of `GenericModel` what we saw already with #203 https://github.com/php-llm/llm-chain/blob/main/src/Bridge/OpenRouter/GenericModel.php WDYT @OskarStark @DZunke
1 parent aa73b0c commit 349f4af

28 files changed

+78
-78
lines changed

examples/chat-claude-anthropic.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
19-
$llm = new Claude(Claude::VERSION_37_SONNET);
19+
$llm = new Claude(Claude::SONNET_37);
2020

2121
$chain = new Chain($platform, $llm);
2222
$messages = new MessageBag(

examples/chat-llama-azure.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

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

2121
$chain = new Chain($platform, $llm);
2222
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));

examples/image-generator-dall-e-3.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
1818

1919
$response = $platform->request(
20-
model: new DallE(version: DallE::DALL_E_3),
20+
model: new DallE(name: DallE::DALL_E_3),
2121
input: 'A cartoon-style elephant with a long trunk and large ears.',
2222
options: [
2323
'response_format' => 'url', // Generate response as URL

src/Bridge/Anthropic/Claude.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88

99
final readonly class Claude implements LanguageModel
1010
{
11-
public const VERSION_3_HAIKU = 'claude-3-haiku-20240307';
12-
public const VERSION_35_HAIKU = 'claude-3-5-haiku-20241022';
13-
public const VERSION_3_SONNET = 'claude-3-sonnet-20240229';
14-
public const VERSION_35_SONNET = 'claude-3-5-sonnet-20240620';
15-
public const VERSION_35_SONNET_V2 = 'claude-3-5-sonnet-20241022';
16-
public const VERSION_37_SONNET = 'claude-3-7-sonnet-20250219';
17-
public const VERSION_3_OPUS = 'claude-3-opus-20240229';
11+
public const HAIKU_3 = 'claude-3-haiku-20240307';
12+
public const HAIKU_35 = 'claude-3-5-haiku-20241022';
13+
public const SONNET_3 = 'claude-3-sonnet-20240229';
14+
public const SONNET_35 = 'claude-3-5-sonnet-20240620';
15+
public const SONNET_35_V2 = 'claude-3-5-sonnet-20241022';
16+
public const SONNET_37 = 'claude-3-7-sonnet-20250219';
17+
public const OPUS_3 = 'claude-3-opus-20240229';
1818

1919
/**
2020
* @param array<string, mixed> $options The default options for the model usage
2121
*/
2222
public function __construct(
23-
private string $version = self::VERSION_35_SONNET,
23+
private string $name = self::SONNET_37,
2424
private array $options = ['temperature' => 1.0, 'max_tokens' => 1000],
2525
) {
2626
}
2727

28-
public function getVersion(): string
28+
public function getName(): string
2929
{
30-
return $this->version;
30+
return $this->name;
3131
}
3232

3333
public function getOptions(): array

src/Bridge/Anthropic/ModelHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function request(Model $model, object|array|string $input, array $options
6262
}
6363

6464
$body = [
65-
'model' => $model->getVersion(),
65+
'model' => $model->getName(),
6666
'messages' => $input->withoutSystemMessage()->jsonSerialize(),
6767
];
6868

src/Bridge/Azure/Meta/LlamaHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function request(Model $model, object|array|string $input, array $options
4141
'Authorization' => $this->apiKey,
4242
],
4343
'json' => array_merge($options, [
44-
'model' => $model->getVersion(),
44+
'model' => $model->getName(),
4545
'messages' => $input,
4646
]),
4747
]);

src/Bridge/Azure/OpenAI/EmbeddingsModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function request(Model $model, object|array|string $input, array $options
4646
],
4747
'query' => ['api-version' => $this->apiVersion],
4848
'json' => array_merge($options, [
49-
'model' => $model->getVersion(),
49+
'model' => $model->getName(),
5050
'input' => $input,
5151
]),
5252
]);

src/Bridge/Azure/OpenAI/GPTModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function request(Model $model, object|array|string $input, array $options
4646
],
4747
'query' => ['api-version' => $this->apiVersion],
4848
'json' => array_merge($options, [
49-
'model' => $model->getVersion(),
49+
'model' => $model->getName(),
5050
'messages' => $input,
5151
]),
5252
]);

src/Bridge/Azure/OpenAI/WhisperModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function request(Model $model, object|array|string $input, array $options
5050
],
5151
'query' => ['api-version' => $this->apiVersion],
5252
'body' => array_merge($options, $model->getOptions(), [
53-
'model' => $model->getVersion(),
53+
'model' => $model->getName(),
5454
'file' => fopen($input->path, 'r'),
5555
]),
5656
]);

src/Bridge/Google/Gemini.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
* @param array<string, mixed> $options The default options for the model usage
1919
*/
2020
public function __construct(
21-
private string $version = self::GEMINI_2_PRO,
21+
private string $name = self::GEMINI_2_PRO,
2222
private array $options = ['temperature' => 1.0],
2323
) {
2424
}
2525

26-
public function getVersion(): string
26+
public function getName(): string
2727
{
28-
return $this->version;
28+
return $this->name;
2929
}
3030

3131
public function getOptions(): array

src/Bridge/Google/ModelHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function request(Model $model, object|array|string $input, array $options
4848

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

src/Bridge/Meta/Llama.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88

99
final readonly class Llama implements LanguageModel
1010
{
11-
public const LLAMA_3_3_70B_INSTRUCT = 'llama-3.3-70B-Instruct';
12-
public const LLAMA_3_2_90B_VISION_INSTRUCT = 'llama-3.2-90b-vision-instruct';
13-
public const LLAMA_3_2_11B_VISION_INSTRUCT = 'llama-3.2-11b-vision-instruct';
14-
public const LLAMA_3_2_3B = 'llama-3.2-3b';
15-
public const LLAMA_3_2_3B_INSTRUCT = 'llama-3.2-3b-instruct';
16-
public const LLAMA_3_2_1B = 'llama-3.2-1b';
17-
public const LLAMA_3_2_1B_INSTRUCT = 'llama-3.2-1b-instruct';
18-
public const LLAMA_3_1_405B_INSTRUCT = 'llama-3.1-405b-instruct';
19-
public const LLAMA_3_1_70B = 'llama-3.1-70b';
20-
public const LLAMA_3_1_70B_INSTRUCT = 'llama-3-70b-instruct';
21-
public const LLAMA_3_1_8B = 'llama-3.1-8b';
22-
public const LLAMA_3_1_8B_INSTRUCT = 'llama-3.1-8b-instruct';
23-
public const LLAMA_3_70B = 'llama-3-70b';
24-
public const LLAMA_3_8B_INSTRUCT = 'llama-3-8b-instruct';
25-
public const LLAMA_3_8B = 'llama-3-8b';
11+
public const V3_3_70B_INSTRUCT = 'llama-3.3-70B-Instruct';
12+
public const V3_2_90B_VISION_INSTRUCT = 'llama-3.2-90b-vision-instruct';
13+
public const V3_2_11B_VISION_INSTRUCT = 'llama-3.2-11b-vision-instruct';
14+
public const V3_2_3B = 'llama-3.2-3b';
15+
public const V3_2_3B_INSTRUCT = 'llama-3.2-3b-instruct';
16+
public const V3_2_1B = 'llama-3.2-1b';
17+
public const V3_2_1B_INSTRUCT = 'llama-3.2-1b-instruct';
18+
public const V3_1_405B_INSTRUCT = 'llama-3.1-405b-instruct';
19+
public const V3_1_70B = 'llama-3.1-70b';
20+
public const V3_1_70B_INSTRUCT = 'llama-3-70b-instruct';
21+
public const V3_1_8B = 'llama-3.1-8b';
22+
public const V3_1_8B_INSTRUCT = 'llama-3.1-8b-instruct';
23+
public const V3_70B = 'llama-3-70b';
24+
public const V3_8B_INSTRUCT = 'llama-3-8b-instruct';
25+
public const V3_8B = 'llama-3-8b';
2626

2727
/**
2828
* @param array<string, mixed> $options
2929
*/
3030
public function __construct(
31-
private string $version = self::LLAMA_3_1_405B_INSTRUCT,
31+
private string $name = self::V3_1_405B_INSTRUCT,
3232
private array $options = [],
3333
) {
3434
}
3535

36-
public function getVersion(): string
36+
public function getName(): string
3737
{
38-
return $this->version;
38+
return $this->name;
3939
}
4040

4141
public function getOptions(): array

src/Bridge/Ollama/LlamaModelHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function request(Model $model, object|array|string $input, array $options
3333
return $this->httpClient->request('POST', sprintf('%s/api/chat', $this->hostUrl), [
3434
'headers' => ['Content-Type' => 'application/json'],
3535
'json' => [
36-
'model' => $model->getVersion(),
36+
'model' => $model->getName(),
3737
'messages' => $input,
3838
'stream' => false,
3939
],

src/Bridge/OpenAI/DallE.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
/** @param array<string, mixed> $options The default options for the model usage */
1515
public function __construct(
16-
private string $version = self::DALL_E_2,
16+
private string $name = self::DALL_E_2,
1717
private array $options = [],
1818
) {
1919
}
2020

21-
public function getVersion(): string
21+
public function getName(): string
2222
{
23-
return $this->version;
23+
return $this->name;
2424
}
2525

2626
/** @return array<string, mixed> */

src/Bridge/OpenAI/DallE/ModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function request(Model $model, object|array|string $input, array $options
3737
return $this->httpClient->request('POST', 'https://api.openai.com/v1/images/generations', [
3838
'auth_bearer' => $this->apiKey,
3939
'json' => \array_merge($options, [
40-
'model' => $model->getVersion(),
40+
'model' => $model->getName(),
4141
'prompt' => $input,
4242
]),
4343
]);

src/Bridge/OpenAI/Embeddings.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* @param array<string, mixed> $options
1717
*/
1818
public function __construct(
19-
private string $version = self::TEXT_3_SMALL,
19+
private string $name = self::TEXT_3_SMALL,
2020
private array $options = [],
2121
) {
2222
}
2323

24-
public function getVersion(): string
24+
public function getName(): string
2525
{
26-
return $this->version;
26+
return $this->name;
2727
}
2828

2929
public function getOptions(): array

src/Bridge/OpenAI/Embeddings/ModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function request(Model $model, object|array|string $input, array $options
3232
return $this->httpClient->request('POST', 'https://api.openai.com/v1/embeddings', [
3333
'auth_bearer' => $this->apiKey,
3434
'json' => array_merge($model->getOptions(), $options, [
35-
'model' => $model->getVersion(),
35+
'model' => $model->getName(),
3636
'input' => $input,
3737
]),
3838
]);

src/Bridge/OpenAI/GPT.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ final class GPT implements LanguageModel
2525
* @param array<mixed> $options The default options for the model usage
2626
*/
2727
public function __construct(
28-
private readonly string $version = self::GPT_4O,
28+
private readonly string $name = self::GPT_4O,
2929
private readonly array $options = ['temperature' => 1.0],
3030
private bool $supportsAudioInput = false,
3131
private bool $supportsImageInput = false,
3232
private bool $supportsStructuredOutput = false,
3333
) {
3434
if (false === $this->supportsAudioInput) {
35-
$this->supportsAudioInput = self::GPT_4O_AUDIO === $this->version;
35+
$this->supportsAudioInput = self::GPT_4O_AUDIO === $this->name;
3636
}
3737

3838
if (false === $this->supportsImageInput) {
39-
$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);
39+
$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);
4040
}
4141

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

47-
public function getVersion(): string
47+
public function getName(): string
4848
{
49-
return $this->version;
49+
return $this->name;
5050
}
5151

5252
public function getOptions(): array

src/Bridge/OpenAI/GPT/ModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function request(Model $model, object|array|string $input, array $options
3535
return $this->httpClient->request('POST', 'https://api.openai.com/v1/chat/completions', [
3636
'auth_bearer' => $this->apiKey,
3737
'json' => array_merge($options, [
38-
'model' => $model->getVersion(),
38+
'model' => $model->getName(),
3939
'messages' => $input,
4040
]),
4141
]);

src/Bridge/OpenAI/Whisper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* @param array<string, mixed> $options
1515
*/
1616
public function __construct(
17-
private string $version = self::WHISPER_1,
17+
private string $name = self::WHISPER_1,
1818
private array $options = [],
1919
) {
2020
}
2121

22-
public function getVersion(): string
22+
public function getName(): string
2323
{
24-
return $this->version;
24+
return $this->name;
2525
}
2626

2727
public function getOptions(): array

src/Bridge/OpenAI/Whisper/ModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function request(Model $model, object|array|string $input, array $options
3434
'auth_bearer' => $this->apiKey,
3535
'headers' => ['Content-Type' => 'multipart/form-data'],
3636
'body' => array_merge($options, $model->getOptions(), [
37-
'model' => $model->getVersion(),
37+
'model' => $model->getName(),
3838
'file' => fopen($input->path, 'r'),
3939
]),
4040
]);

src/Bridge/OpenRouter/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function request(Model $model, object|array|string $input, array $options
3939
return $this->httpClient->request('POST', 'https://openrouter.ai/api/v1/chat/completions', [
4040
'auth_bearer' => $this->apiKey,
4141
'json' => array_merge($options, [
42-
'model' => $model->getVersion(),
42+
'model' => $model->getName(),
4343
'messages' => $input,
4444
]),
4545
]);

src/Bridge/OpenRouter/GenericModel.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* @param array<string, mixed> $options
1414
*/
1515
public function __construct(
16-
private string $version = Llama::LLAMA_3_2_90B_VISION_INSTRUCT,
16+
private string $name = Llama::V3_2_90B_VISION_INSTRUCT,
1717
private array $options = [],
1818
) {
1919
}
2020

21-
public function getVersion(): string
21+
public function getName(): string
2222
{
23-
return $this->version;
23+
return $this->name;
2424
}
2525

2626
public function getOptions(): array

src/Bridge/Replicate/LlamaModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function request(Model $model, object|array|string $input, array $options
3131
Assert::isInstanceOf($model, Llama::class);
3232
Assert::isInstanceOf($input, MessageBagInterface::class);
3333

34-
return $this->client->request(sprintf('meta/meta-%s', $model->getVersion()), 'predictions', [
34+
return $this->client->request(sprintf('meta/meta-%s', $model->getName()), 'predictions', [
3535
'system' => $this->promptConverter->convertMessage($input->getSystemMessage() ?? new SystemMessage('')),
3636
'prompt' => $this->promptConverter->convertToPrompt($input->withoutSystemMessage()),
3737
]);

src/Bridge/Voyage/ModelHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function request(Model $model, object|string|array $input, array $options
3232
return $this->httpClient->request('POST', 'https://api.voyageai.com/v1/embeddings', [
3333
'auth_bearer' => $this->apiKey,
3434
'json' => [
35-
'model' => $model->getVersion(),
35+
'model' => $model->getName(),
3636
'input' => $input,
3737
],
3838
]);

0 commit comments

Comments
 (0)