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

Commit 8a55022

Browse files
authored
refactor: from vendor to structural namespaces for models and platforms (#68)
1 parent 67b108b commit 8a55022

35 files changed

+134
-331
lines changed

examples/chat-claude-anthropic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Anthropic\Model\Claude;
4-
use PhpLlm\LlmChain\Anthropic\Platform\Anthropic;
53
use PhpLlm\LlmChain\Chain;
64
use PhpLlm\LlmChain\Message\Message;
75
use PhpLlm\LlmChain\Message\MessageBag;
6+
use PhpLlm\LlmChain\Model\Language\Claude;
7+
use PhpLlm\LlmChain\Platform\Anthropic;
88
use Symfony\Component\Dotenv\Dotenv;
99
use Symfony\Component\HttpClient\HttpClient;
1010

examples/chat-gpt-azure.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use PhpLlm\LlmChain\Chain;
44
use PhpLlm\LlmChain\Message\Message;
55
use PhpLlm\LlmChain\Message\MessageBag;
6-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
7-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Platform\Azure;
6+
use PhpLlm\LlmChain\Model\Language\Gpt;
7+
use PhpLlm\LlmChain\Platform\OpenAI\Azure;
98
use Symfony\Component\Dotenv\Dotenv;
109
use Symfony\Component\HttpClient\HttpClient;
1110

@@ -24,7 +23,7 @@
2423
$_ENV['AZURE_OPENAI_VERSION'],
2524
$_ENV['AZURE_OPENAI_KEY'],
2625
);
27-
$llm = new Gpt($platform, Version::gpt4oMini());
26+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
2827

2928
$chain = new Chain($llm);
3029
$messages = new MessageBag(

examples/chat-gpt-openai.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use PhpLlm\LlmChain\Chain;
44
use PhpLlm\LlmChain\Message\Message;
55
use PhpLlm\LlmChain\Message\MessageBag;
6-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
7-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
6+
use PhpLlm\LlmChain\Model\Language\Gpt;
7+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
98
use Symfony\Component\Dotenv\Dotenv;
109
use Symfony\Component\HttpClient\HttpClient;
1110

@@ -18,7 +17,7 @@
1817
}
1918

2019
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
21-
$llm = new Gpt($platform, Version::gpt4oMini(), [
20+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI, [
2221
'temperature' => 0.5, // default options for the model
2322
]);
2423

examples/chat-o1-openai.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use PhpLlm\LlmChain\Chain;
44
use PhpLlm\LlmChain\Message\Message;
55
use PhpLlm\LlmChain\Message\MessageBag;
6-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
7-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
8-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
6+
use PhpLlm\LlmChain\Model\Language\Gpt;
7+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
98
use Symfony\Component\Dotenv\Dotenv;
109
use Symfony\Component\HttpClient\HttpClient;
1110

@@ -23,7 +22,7 @@
2322
}
2423

2524
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
26-
$llm = new Gpt($platform, Version::o1Preview());
25+
$llm = new Gpt($platform, Gpt::O1_PREVIEW);
2726

2827
$prompt = <<<PROMPT
2928
I want to build a Symfony app in PHP 8.2 that takes user questions and looks them

examples/embeddings-openai.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

3-
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
4-
use PhpLlm\LlmChain\OpenAI\Model\Embeddings\Version;
5-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
3+
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
4+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
65
use Symfony\Component\Dotenv\Dotenv;
76
use Symfony\Component\HttpClient\HttpClient;
87

@@ -14,8 +13,8 @@
1413
exit(1);
1514
}
1615

17-
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
18-
$embeddings = new Embeddings($platform, Version::textEmbedding3Small());
16+
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
17+
$embeddings = new Embeddings($platform);
1918

2019
$vector = $embeddings->create(<<<TEXT
2120
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.

examples/embeddings-voyage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Voyage\Model\Voyage;
4-
use PhpLlm\LlmChain\Voyage\Platform\Voyage as VoyagePlatform;
3+
use PhpLlm\LlmChain\Model\Embeddings\Voyage;
4+
use PhpLlm\LlmChain\Platform\Voyage as Platform;
55
use Symfony\Component\Dotenv\Dotenv;
66
use Symfony\Component\HttpClient\HttpClient;
77

@@ -13,7 +13,7 @@
1313
exit(1);
1414
}
1515

16-
$platform = new VoyagePlatform(HttpClient::create(), $_ENV['VOYAGE_API_KEY']);
16+
$platform = new Platform(HttpClient::create(), $_ENV['VOYAGE_API_KEY']);
1717
$embeddings = new Voyage($platform);
1818

1919
$vector = $embeddings->create(<<<TEXT

examples/image-describer-binary.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
use PhpLlm\LlmChain\Message\Content\Image;
55
use PhpLlm\LlmChain\Message\Message;
66
use PhpLlm\LlmChain\Message\MessageBag;
7-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
8-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
9-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
7+
use PhpLlm\LlmChain\Model\Language\Gpt;
8+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
109
use Symfony\Component\Dotenv\Dotenv;
1110
use Symfony\Component\HttpClient\HttpClient;
1211

@@ -19,7 +18,7 @@
1918
}
2019

2120
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
22-
$llm = new Gpt($platform, Version::gpt4oMini());
21+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
2322

2423
$chain = new Chain($llm);
2524
$messages = new MessageBag(

examples/image-describer-url.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
use PhpLlm\LlmChain\Message\Content\Image;
55
use PhpLlm\LlmChain\Message\Message;
66
use PhpLlm\LlmChain\Message\MessageBag;
7-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
8-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
9-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
7+
use PhpLlm\LlmChain\Model\Language\Gpt;
8+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
109
use Symfony\Component\Dotenv\Dotenv;
1110
use Symfony\Component\HttpClient\HttpClient;
1211

@@ -19,7 +18,7 @@
1918
}
2019

2120
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
22-
$llm = new Gpt($platform, Version::gpt4oMini());
21+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
2322

2423
$chain = new Chain($llm);
2524
$messages = new MessageBag(

examples/store-mongodb-similarity-search.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
use PhpLlm\LlmChain\DocumentEmbedder;
88
use PhpLlm\LlmChain\Message\Message;
99
use PhpLlm\LlmChain\Message\MessageBag;
10-
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
11-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
12-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
13-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
10+
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
11+
use PhpLlm\LlmChain\Model\Language\Gpt;
12+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
1413
use PhpLlm\LlmChain\Store\MongoDB\Store;
1514
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
1615
use PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch;
@@ -54,14 +53,14 @@
5453
}
5554

5655
// create embeddings for documents
57-
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
56+
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
5857
$embedder = new DocumentEmbedder($embeddings = new Embeddings($platform), $store);
5958
$embedder->embed($documents);
6059

6160
// initialize the index
6261
$store->initialize();
6362

64-
$llm = new Gpt($platform, Version::gpt4oMini());
63+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
6564

6665
$similaritySearch = new SimilaritySearch($embeddings, $store);
6766
$toolBox = new ToolBox(new ToolAnalyzer(), [$similaritySearch]);

examples/store-pinecone-similarity-search.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
use PhpLlm\LlmChain\DocumentEmbedder;
77
use PhpLlm\LlmChain\Message\Message;
88
use PhpLlm\LlmChain\Message\MessageBag;
9-
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
10-
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
11-
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
12-
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
9+
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
10+
use PhpLlm\LlmChain\Model\Language\Gpt;
11+
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
1312
use PhpLlm\LlmChain\Store\Pinecone\Store;
1413
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
1514
use PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch;
@@ -48,11 +47,11 @@
4847
}
4948

5049
// create embeddings for documents
51-
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
50+
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
5251
$embedder = new DocumentEmbedder($embeddings = new Embeddings($platform), $store);
5352
$embedder->embed($documents);
5453

55-
$llm = new Gpt($platform, Version::gpt4oMini());
54+
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
5655

5756
$similaritySearch = new SimilaritySearch($embeddings, $store);
5857
$toolBox = new ToolBox(new ToolAnalyzer(), [$similaritySearch]);

0 commit comments

Comments
 (0)