Skip to content

Commit ce89797

Browse files
authored
refactor: rename Runtime to Platform (#34)
1 parent a9d5831 commit ce89797

19 files changed

+60
-60
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ composer require php-llm/llm-chain
2121

2222
When using Symfony Framework, check out the integration bundle [php-llm/llm-chain-bundle](https://github.com/php-llm/llm-chain-bundle).
2323

24-
Supported Models & Runtimes
25-
---------------------------
24+
Supported Models & Platforms
25+
----------------------------
2626

27-
Currently supported models and runtimes:
27+
Currently supported models and platforms:
2828

29-
| Vendor | Model | Runtime |
30-
|----------------|------------------------|----------------------------------|
31-
| **OpenAI** | - GPT<br/>- Embeddings | - OpenAI<br/>- Azure |
32-
| **Anthropic** | - Claude | - Anthropic |
29+
| Vendor | Model | Platform |
30+
|----------------|------------------------|----------------------|
31+
| **OpenAI** | - GPT<br/>- Embeddings | - OpenAI<br/>- Azure |
32+
| **Anthropic** | - Claude | - Anthropic |
3333

34-
Planned Models & Runtimes (not implemented yet):
34+
Planned Models & Platforms (not implemented yet):
3535

36-
| Vendor | Model | Runtime |
36+
| Vendor | Model | Platform |
3737
|----------------|------------------------|----------------------------------|
3838
| **Anthropic** | - Voyage | - GPC<br/>- AWS |
3939
| **Google** | - Gemini<br/>- Gemma | - GPC |

examples/chat-claude-anthropic.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22

33
use PhpLlm\LlmChain\Anthropic\Model\Claude;
4-
use PhpLlm\LlmChain\Anthropic\Runtime\Anthropic;
4+
use PhpLlm\LlmChain\Anthropic\Platform\Anthropic;
55
use PhpLlm\LlmChain\Chain;
66
use PhpLlm\LlmChain\Message\Message;
77
use PhpLlm\LlmChain\Message\MessageBag;
88
use Symfony\Component\HttpClient\HttpClient;
99

1010
require_once dirname(__DIR__).'/vendor/autoload.php';
1111

12-
$runtime = new Anthropic(HttpClient::create(), getenv('ANTHROPIC_API_KEY'));
13-
$llm = new Claude($runtime);
12+
$platform = new Anthropic(HttpClient::create(), getenv('ANTHROPIC_API_KEY'));
13+
$llm = new Claude($platform);
1414

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

examples/chat-gpt-azure.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\Azure;
8+
use PhpLlm\LlmChain\OpenAI\Platform\Azure;
99
use Symfony\Component\HttpClient\HttpClient;
1010

1111
require_once dirname(__DIR__).'/vendor/autoload.php';
1212

13-
$runtime = new Azure(HttpClient::create(),
13+
$platform = new Azure(HttpClient::create(),
1414
getenv('AZURE_OPENAI_BASEURL'),
1515
getenv('AZURE_OPENAI_DEPLOYMENT'),
1616
getenv('AZURE_OPENAI_VERSION'),
1717
getenv('AZURE_OPENAI_KEY')
1818
);
19-
$llm = new Gpt($runtime, Version::gpt4oMini());
19+
$llm = new Gpt($platform, Version::gpt4oMini());
2020

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

examples/chat-gpt-openai.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use Symfony\Component\HttpClient\HttpClient;
1010

1111
require_once dirname(__DIR__).'/vendor/autoload.php';
1212

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

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

examples/structured-output-math.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\StructuredOutput\ResponseFormatFactory;
1010
use PhpLlm\LlmChain\StructuredOutput\SchemaFactory;
1111
use PhpLlm\LlmChain\Tests\StructuredOutput\Data\MathReasoning;
@@ -16,8 +16,8 @@
1616

1717
require_once dirname(__DIR__).'/vendor/autoload.php';
1818

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

examples/toolbox-clock.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\Tool\Clock;
1010
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1111
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -14,8 +14,8 @@
1414

1515
require_once dirname(__DIR__).'/vendor/autoload.php';
1616

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

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

examples/toolbox-serpapi.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\Tool\SerpApi;
1010
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1111
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -14,8 +14,8 @@
1414
require_once dirname(__DIR__).'/vendor/autoload.php';
1515

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

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

examples/toolbox-weather.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo;
1010
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1111
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -14,8 +14,8 @@
1414
require_once dirname(__DIR__).'/vendor/autoload.php';
1515

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

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

examples/toolbox-wikipedia.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\Tool\Wikipedia;
1010
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1111
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -14,8 +14,8 @@
1414
require_once dirname(__DIR__).'/vendor/autoload.php';
1515

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

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

examples/toolbox-youtube.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpLlm\LlmChain\Message\MessageBag;
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
8+
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber;
1010
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1111
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -14,8 +14,8 @@
1414
require_once dirname(__DIR__).'/vendor/autoload.php';
1515

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

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

src/Anthropic/ClaudeRuntime.php renamed to src/Anthropic/ClaudePlatform.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpLlm\LlmChain\Anthropic;
66

7-
interface ClaudeRuntime
7+
interface ClaudePlatform
88
{
99
/**
1010
* @param array<string, mixed> $body

src/Anthropic/Model/Claude.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpLlm\LlmChain\Anthropic\Model;
66

7-
use PhpLlm\LlmChain\Anthropic\ClaudeRuntime;
7+
use PhpLlm\LlmChain\Anthropic\ClaudePlatform;
88
use PhpLlm\LlmChain\Anthropic\Model\Claude\Version;
99
use PhpLlm\LlmChain\LanguageModel;
1010
use PhpLlm\LlmChain\Message\MessageBag;
@@ -14,7 +14,7 @@
1414
final class Claude implements LanguageModel
1515
{
1616
public function __construct(
17-
private readonly ClaudeRuntime $runtime,
17+
private readonly ClaudePlatform $platform,
1818
private ?Version $version = null,
1919
private readonly float $temperature = 1.0,
2020
private readonly int $maxTokens = 1000,
@@ -33,7 +33,7 @@ public function call(MessageBag $messages, array $options = []): Response
3333
'messages' => $messages->withoutSystemMessage(),
3434
];
3535

36-
$response = $this->runtime->request(array_merge($body, $options));
36+
$response = $this->platform->request(array_merge($body, $options));
3737

3838
return new Response(new Choice($response['content'][0]['text']));
3939
}

src/Anthropic/Runtime/Anthropic.php renamed to src/Anthropic/Platform/Anthropic.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\Anthropic\Runtime;
5+
namespace PhpLlm\LlmChain\Anthropic\Platform;
66

7-
use PhpLlm\LlmChain\Anthropic\ClaudeRuntime;
7+
use PhpLlm\LlmChain\Anthropic\ClaudePlatform;
88
use Symfony\Contracts\HttpClient\HttpClientInterface;
99

10-
final readonly class Anthropic implements ClaudeRuntime
10+
final readonly class Anthropic implements ClaudePlatform
1111
{
1212
public function __construct(
1313
private HttpClientInterface $httpClient,

src/OpenAI/Model/Embeddings.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
use PhpLlm\LlmChain\Document\Vector;
88
use PhpLlm\LlmChain\EmbeddingModel;
99
use PhpLlm\LlmChain\OpenAI\Model\Embeddings\Version;
10-
use PhpLlm\LlmChain\OpenAI\Runtime;
10+
use PhpLlm\LlmChain\OpenAI\Platform;
1111

1212
final class Embeddings implements EmbeddingModel
1313
{
1414
public function __construct(
15-
private readonly Runtime $runtime,
15+
private readonly Platform $platform,
1616
private ?Version $version = null,
1717
) {
1818
$this->version ??= Version::textEmbedding3Small();
1919
}
2020

2121
public function create(string $text): Vector
2222
{
23-
$response = $this->runtime->request('embeddings', $this->createBody($text));
23+
$response = $this->platform->request('embeddings', $this->createBody($text));
2424

2525
return $this->extractVector($response);
2626
}
@@ -30,7 +30,7 @@ public function multiCreate(array $texts): array
3030
$bodies = array_map([$this, 'createBody'], $texts);
3131

3232
$vectors = [];
33-
foreach ($this->runtime->multiRequest('embeddings', $bodies) as $response) {
33+
foreach ($this->platform->multiRequest('embeddings', $bodies) as $response) {
3434
$vectors[] = $this->extractVector($response);
3535
}
3636

src/OpenAI/Model/Gpt.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
use PhpLlm\LlmChain\LanguageModel;
88
use PhpLlm\LlmChain\Message\MessageBag;
99
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
10-
use PhpLlm\LlmChain\OpenAI\Runtime;
10+
use PhpLlm\LlmChain\OpenAI\Platform;
1111
use PhpLlm\LlmChain\Response\Choice;
1212
use PhpLlm\LlmChain\Response\Response;
1313
use PhpLlm\LlmChain\Response\ToolCall;
1414

1515
final class Gpt implements LanguageModel
1616
{
1717
public function __construct(
18-
private readonly Runtime $runtime,
18+
private readonly Platform $platform,
1919
private ?Version $version = null,
2020
private readonly float $temperature = 1.0,
2121
) {
@@ -30,7 +30,7 @@ public function call(MessageBag $messages, array $options = []): Response
3030
'messages' => $messages,
3131
];
3232

33-
$response = $this->runtime->request('chat/completions', array_merge($body, $options));
33+
$response = $this->platform->request('chat/completions', array_merge($body, $options));
3434

3535
return new Response(...array_map([$this, 'convertChoice'], $response['choices']));
3636
}

src/OpenAI/Runtime.php renamed to src/OpenAI/Platform.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpLlm\LlmChain\OpenAI;
66

7-
interface Runtime
7+
interface Platform
88
{
99
/**
1010
* @param array<string, mixed> $body

src/OpenAI/Runtime/AbstractRuntime.php renamed to src/OpenAI/Platform/AbstractPlatform.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\OpenAI\Runtime;
5+
namespace PhpLlm\LlmChain\OpenAI\Platform;
66

7-
use PhpLlm\LlmChain\OpenAI\Runtime;
7+
use PhpLlm\LlmChain\OpenAI\Platform;
88
use Symfony\Component\HttpClient\Exception\ClientException;
99
use Symfony\Contracts\HttpClient\ResponseInterface;
1010

11-
abstract class AbstractRuntime implements Runtime
11+
abstract class AbstractPlatform implements Platform
1212
{
1313
public function request(string $endpoint, array $body): array
1414
{

src/OpenAI/Runtime/Azure.php renamed to src/OpenAI/Platform/Azure.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\OpenAI\Runtime;
5+
namespace PhpLlm\LlmChain\OpenAI\Platform;
66

7-
use PhpLlm\LlmChain\OpenAI\Runtime;
7+
use PhpLlm\LlmChain\OpenAI\Platform;
88
use Symfony\Contracts\HttpClient\HttpClientInterface;
99
use Symfony\Contracts\HttpClient\ResponseInterface;
1010

11-
final class Azure extends AbstractRuntime implements Runtime
11+
final class Azure extends AbstractPlatform implements Platform
1212
{
1313
public function __construct(
1414
private readonly HttpClientInterface $httpClient,

src/OpenAI/Runtime/OpenAI.php renamed to src/OpenAI/Platform/OpenAI.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpLlm\LlmChain\OpenAI\Runtime;
5+
namespace PhpLlm\LlmChain\OpenAI\Platform;
66

7-
use PhpLlm\LlmChain\OpenAI\Runtime;
7+
use PhpLlm\LlmChain\OpenAI\Platform;
88
use Symfony\Contracts\HttpClient\HttpClientInterface;
99
use Symfony\Contracts\HttpClient\ResponseInterface;
1010

11-
final class OpenAI extends AbstractRuntime implements Runtime
11+
final class OpenAI extends AbstractPlatform implements Platform
1212
{
1313
public function __construct(
1414
private readonly HttpClientInterface $httpClient,

0 commit comments

Comments
 (0)