Skip to content

Commit ba62c9b

Browse files
committed
minor #113 refactor: replace composer suggests with runtime checks (OskarStark)
This PR was merged into the main branch. Discussion ---------- refactor: replace composer suggests with runtime checks | Q | A | ------------- | --- | Bug fix? | no | New feature? |no | Docs? | no | Issues | Fix #76 | License | MIT Cherry picking php-llm/llm-chain#385 > Remove the `suggest` section from composer.json and add explicit runtime checks that throw exceptions with helpful composer require commands when optional dependencies are missing. > > This provides better developer experience by: > - Giving clear error messages when optional dependencies are needed > - Providing the exact composer command to install missing packages > - Following Symfony's pattern for handling optional dependencies > > Optional dependencies now throw exceptions instead of silently failing when the required packages are not installed. Commits ------- 95cd020 refactor: replace composer suggests with runtime checks (#385)
2 parents 1200cce + 95cd020 commit ba62c9b

File tree

13 files changed

+29
-22
lines changed

13 files changed

+29
-22
lines changed

src/agent/composer.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@
4343
"symfony/event-dispatcher": "^6.4 || ^7.1",
4444
"symfony/http-foundation": "^6.4 || ^7.1"
4545
},
46-
"suggest": {
47-
"mrmysql/youtube-transcript": "For using the YouTube transcription tool.",
48-
"symfony/ai-store": "For using Similarity Search with a vector store.",
49-
"symfony/css-selector": "For using the YouTube transcription tool.",
50-
"symfony/dom-crawler": "For using the Crawler tool.",
51-
"symfony/http-foundation": "For using the SessionStore as message store.",
52-
"psr/cache": "For using the CacheStore as message store."
53-
},
5446
"config": {
5547
"sort-packages": true
5648
},

src/agent/src/Chat/MessageStore/CacheStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public function __construct(
2323
private string $cacheKey,
2424
private int $ttl = 86400,
2525
) {
26+
if (!interface_exists(CacheItemPoolInterface::class)) {
27+
throw new \RuntimeException('For using the CacheStore as message store, a PSR-6 cache implementation is required. Try running "composer require symfony/cache" or another PSR-6 compatible cache.');
28+
}
2629
}
2730

2831
public function save(MessageBagInterface $messages): void

src/agent/src/Chat/MessageStore/SessionStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function __construct(
2525
RequestStack $requestStack,
2626
private string $sessionKey = 'messages',
2727
) {
28+
if (!class_exists(RequestStack::class)) {
29+
throw new \RuntimeException('For using the SessionStore as message store, the symfony/http-foundation package is required. Try running "composer require symfony/http-foundation".');
30+
}
2831
$this->session = $requestStack->getSession();
2932
}
3033

src/agent/src/Toolbox/Tool/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
private HttpClientInterface $httpClient,
2727
) {
2828
if (!class_exists(DomCrawler::class)) {
29-
throw new RuntimeException('The DomCrawler component is not installed. Please install it using "composer require symfony/dom-crawler".');
29+
throw new RuntimeException('For using the Crawler tool, the symfony/dom-crawler package is required. Try running "composer require symfony/dom-crawler".');
3030
}
3131
}
3232

src/agent/src/Toolbox/Tool/YouTubeTranscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
private HttpClientInterface $client,
2828
) {
2929
if (!class_exists(TranscriptListFetcher::class)) {
30-
throw new LogicException('The package `mrmysql/youtube-transcript` is required to use this tool. Try running "composer require mrmysql/youtube-transcript".');
30+
throw new LogicException('For using the YouTube transcription tool, the mrmysql/youtube-transcript package is required. Try running "composer require mrmysql/youtube-transcript".');
3131
}
3232
}
3333

src/platform/composer.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@
5050
"symfony/process": "^6.4 || ^7.1",
5151
"symfony/var-dumper": "^6.4 || ^7.1"
5252
},
53-
"suggest": {
54-
"async-aws/bedrock-runtime": "For using the Bedrock platform.",
55-
"codewithkyrian/transformers": "For using the TransformersPHP with FFI to run models in PHP."
56-
},
5753
"config": {
5854
"allow-plugins": {
5955
"codewithkyrian/transformers-libsloader": true

src/platform/src/Bridge/Bedrock/PlatformFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public static function create(
2626
BedrockRuntimeClient $bedrockRuntimeClient = new BedrockRuntimeClient(),
2727
?Contract $contract = null,
2828
): Platform {
29+
if (!class_exists(BedrockRuntimeClient::class)) {
30+
throw new \RuntimeException('For using the Bedrock platform, the async-aws/bedrock-runtime package is required. Try running "composer require async-aws/bedrock-runtime".');
31+
}
32+
2933
$modelClient[] = new ClaudeHandler($bedrockRuntimeClient);
3034
$modelClient[] = new NovaHandler($bedrockRuntimeClient);
3135
$modelClient[] = new LlamaModelClient($bedrockRuntimeClient);

src/platform/src/Bridge/TransformersPHP/PlatformFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public static function create(): Platform
2323
{
2424
if (!class_exists(Transformers::class)) {
25-
throw new RuntimeException('TransformersPHP is not installed. Please install it using "composer require codewithkyrian/transformers".');
25+
throw new RuntimeException('For using the TransformersPHP with FFI to run models in PHP, the codewithkyrian/transformers package is required. Try running "composer require codewithkyrian/transformers".');
2626
}
2727

2828
return new Platform();

src/store/composer.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
"phpunit/phpunit": "^11.5",
4040
"probots-io/pinecone-php": "^1.0"
4141
},
42-
"suggest": {
43-
"ext-pdo": "For using MariaDB as retrieval vector store.",
44-
"codewithkyrian/chromadb-php": "For using the ChromaDB as retrieval vector store.",
45-
"doctrine/dbal": "For using MariaDB via Doctrine as retrieval vector store",
46-
"mongodb/mongodb": "For using MongoDB Atlas as retrieval vector store.",
47-
"probots-io/pinecone-php": "For using the Pinecone as retrieval vector store."
48-
},
4942
"config": {
5043
"sort-packages": true
5144
},

src/store/src/Bridge/ChromaDB/Store.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function __construct(
2727
private Client $client,
2828
private string $collectionName,
2929
) {
30+
if (!class_exists(Client::class)) {
31+
throw new \RuntimeException('For using the ChromaDB as retrieval vector store, the codewithkyrian/chromadb-php package is required. Try running "composer require codewithkyrian/chromadb-php".');
32+
}
3033
}
3134

3235
public function add(VectorDocument ...$documents): void

0 commit comments

Comments
 (0)