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

Commit 8a39981

Browse files
committed
refactor: simplify Fabric integration by using Pattern class directly
- Remove FabricRepository, FabricPrompt, FabricPromptInterface - Remove PatternNotFoundException - Remove support for custom pattern paths - Use php-llm/fabric-pattern's Pattern class directly - Update tests to match new implementation - Update README to remove custom pattern location docs
1 parent 80d4a41 commit 8a39981

File tree

11 files changed

+56
-583
lines changed

11 files changed

+56
-583
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,27 @@ $response = $chain->call([
920920
]);
921921
```
922922

923+
#### Usage with Input Processor
924+
925+
For more flexibility, you can use the `FabricInputProcessor` to dynamically load patterns:
926+
927+
```php
928+
use PhpLlm\LlmChain\Chain\Chain;
929+
use PhpLlm\LlmChain\Platform\Fabric\FabricInputProcessor;
930+
931+
// Initialize Platform and LLM
932+
933+
$processor = new FabricInputProcessor();
934+
$chain = new Chain($platform, $model, [$processor]);
935+
936+
$messages = new MessageBag(
937+
Message::ofUser('Analyze this article for potential security issues: ...')
938+
);
939+
940+
// Use any Fabric pattern via options
941+
$response = $chain->call($messages, ['fabric_pattern' => 'analyze_threat_report']);
942+
```
943+
923944
#### Available Patterns
924945

925946
Some popular patterns include:

src/Platform/Fabric/Exception/PatternNotFoundException.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Platform/Fabric/FabricInputProcessor.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpLlm\LlmChain\Platform\Fabric;
66

7+
use PhpLlm\FabricPattern\Pattern;
78
use PhpLlm\LlmChain\Chain\Input;
89
use PhpLlm\LlmChain\Chain\InputProcessorInterface;
910
use PhpLlm\LlmChain\Platform\Message\SystemMessage;
@@ -16,11 +17,6 @@
1617
*/
1718
final readonly class FabricInputProcessor implements InputProcessorInterface
1819
{
19-
public function __construct(
20-
private FabricRepository $repository = new FabricRepository(),
21-
) {
22-
}
23-
2420
public function processInput(Input $input): void
2521
{
2622
$options = $input->getOptions();
@@ -39,9 +35,14 @@ public function processInput(Input $input): void
3935
throw new \LogicException('Cannot add Fabric pattern: MessageBag already contains a system message');
4036
}
4137

38+
// Check if fabric-pattern package is installed
39+
if (!class_exists(Pattern::class)) {
40+
throw new \RuntimeException('Fabric patterns not found. Please install the "php-llm/fabric-pattern" package: composer require php-llm/fabric-pattern');
41+
}
42+
4243
// Load the pattern and prepend as system message
43-
$fabricPrompt = $this->repository->load($pattern);
44-
$systemMessage = new SystemMessage($fabricPrompt->getContent());
44+
$content = (new Pattern())->load($pattern);
45+
$systemMessage = new SystemMessage($content);
4546

4647
// Prepend the system message
4748
$input->messages = $input->messages->prepend($systemMessage);

src/Platform/Fabric/FabricPrompt.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Platform/Fabric/FabricPromptInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Platform/Fabric/FabricRepository.php

Lines changed: 0 additions & 141 deletions
This file was deleted.

src/Platform/Message/Message.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpLlm\LlmChain\Platform\Message;
66

7-
use PhpLlm\LlmChain\Platform\Fabric\FabricRepository;
7+
use PhpLlm\FabricPattern\Pattern;
88
use PhpLlm\LlmChain\Platform\Message\Content\ContentInterface;
99
use PhpLlm\LlmChain\Platform\Message\Content\Text;
1010
use PhpLlm\LlmChain\Platform\Response\ToolCall;
@@ -33,16 +33,17 @@ public static function forSystem(\Stringable|string $content): SystemMessage
3333
* Note: Only one SystemMessage is supported per MessageBag. If you need to use
3434
* a Fabric pattern with an existing SystemMessage, you'll need to combine them manually.
3535
*
36-
* @param string|null $patternsPath Optional custom patterns path
37-
*
3836
* @throws \RuntimeException if fabric-pattern package is not installed
3937
*/
40-
public static function fabric(string $pattern, ?string $patternsPath = null): SystemMessage
38+
public static function fabric(string $pattern): SystemMessage
4139
{
42-
$repository = new FabricRepository($patternsPath);
43-
$fabricPrompt = $repository->load($pattern);
40+
if (!class_exists(Pattern::class)) {
41+
throw new \RuntimeException('Fabric patterns not found. Please install the "php-llm/fabric-pattern" package: composer require php-llm/fabric-pattern');
42+
}
43+
44+
$content = (new Pattern())->load($pattern);
4445

45-
return new SystemMessage($fabricPrompt->getContent());
46+
return new SystemMessage($content);
4647
}
4748

4849
/**

0 commit comments

Comments
 (0)