Skip to content

Commit 14a9f1a

Browse files
authored
feat: introduce Version value object (#12)
* Introduce `Model` value object
1 parent dccc6dd commit 14a9f1a

File tree

15 files changed

+135
-48
lines changed

15 files changed

+135
-48
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"symfony/property-info": "^6.4 || ^7.1",
2020
"symfony/serializer": "^6.4 || ^7.1",
2121
"symfony/type-info": "^6.4 || ^7.1",
22-
"symfony/uid": "^6.4 || ^7.1"
22+
"symfony/uid": "^6.4 || ^7.1",
23+
"webmozart/assert": "^1.11"
2324
},
2425
"require-dev": {
2526
"codewithkyrian/chromadb-php": "^0.2.1",

examples/chat-gpt-azure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
getenv('AZURE_OPENAI_VERSION'),
1717
getenv('AZURE_OPENAI_KEY')
1818
);
19-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
19+
$llm = new Gpt($runtime, Version::gpt4oMini());
2020

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

examples/chat-gpt-openai.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require_once dirname(__DIR__).'/vendor/autoload.php';
1212

1313
$runtime = new OpenAI(HttpClient::create(), getenv('OPENAI_API_KEY'));
14-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
14+
$llm = new Gpt($runtime, Version::gpt4oMini());
1515

1616
$chain = new Chain($llm);
1717
$messages = new MessageBag(

examples/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
require_once dirname(__DIR__).'/vendor/autoload.php';
1818

1919
$runtime = new OpenAI(HttpClient::create(), getenv('OPENAI_API_KEY'));
20-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
20+
$llm = new Gpt($runtime, Version::gpt4oMini());
2121
$responseFormatFactory = new ResponseFormatFactory(SchemaFactory::create());
2222
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
2323

examples/toolbox-clock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require_once dirname(__DIR__).'/vendor/autoload.php';
1616

1717
$runtime = new OpenAI(HttpClient::create(), getenv('OPENAI_API_KEY'));
18-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
18+
$llm = new Gpt($runtime, Version::gpt4oMini());
1919

2020
$clock = new Clock(new SymfonyClock());
2121
$toolBox = new ToolBox(new ToolAnalyzer(), [$clock]);

examples/toolbox-serpapi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$httpClient = HttpClient::create();
1717
$runtime = new OpenAI($httpClient, getenv('OPENAI_API_KEY'));
18-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
18+
$llm = new Gpt($runtime, Version::gpt4oMini());
1919

2020
$serpApi = new SerpApi($httpClient, getenv('SERP_API_KEY'));
2121
$toolBox = new ToolBox(new ToolAnalyzer(), [$serpApi]);

examples/toolbox-weather.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$httpClient = HttpClient::create();
1717
$runtime = new OpenAI($httpClient, getenv('OPENAI_API_KEY'));
18-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
18+
$llm = new Gpt($runtime, Version::gpt4oMini());
1919

2020
$wikipedia = new OpenMeteo($httpClient);
2121
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);

examples/toolbox-wikipedia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$httpClient = HttpClient::create();
1717
$runtime = new OpenAI($httpClient, getenv('OPENAI_API_KEY'));
18-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
18+
$llm = new Gpt($runtime, Version::gpt4oMini());
1919

2020
$wikipedia = new Wikipedia($httpClient);
2121
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);

examples/toolbox-youtube.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$httpClient = HttpClient::create();
1717
$runtime = new OpenAI($httpClient, getenv('OPENAI_API_KEY'));
18-
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
18+
$llm = new Gpt($runtime, Version::gpt4oMini());
1919

2020
$transcriber = new YouTubeTranscriber($httpClient);
2121
$toolBox = new ToolBox(new ToolAnalyzer(), [$transcriber]);

src/Anthropic/Model/Claude.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111
use PhpLlm\LlmChain\Response\Choice;
1212
use PhpLlm\LlmChain\Response\Response;
1313

14-
final readonly class Claude implements LanguageModel
14+
final class Claude implements LanguageModel
1515
{
1616
public function __construct(
17-
private ClaudeRuntime $runtime,
18-
private Version $version = Version::SONNET_35,
19-
private float $temperature = 1.0,
20-
private int $maxTokens = 1000,
17+
private readonly ClaudeRuntime $runtime,
18+
private ?Version $version = null,
19+
private readonly float $temperature = 1.0,
20+
private readonly int $maxTokens = 1000,
2121
) {
22+
$this->version ??= Version::sonnet35();
2223
}
2324

2425
public function call(MessageBag $messages, array $options = []): Response
2526
{
2627
$system = $messages->getSystemMessage();
2728
$body = [
28-
'model' => $this->version->value,
29+
'model' => $this->version->name,
2930
'temperature' => $this->temperature,
3031
'max_tokens' => $this->maxTokens,
3132
'system' => $system->content,

0 commit comments

Comments
 (0)