-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add Fabric patterns support #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements integration with Fabric patterns from danielmiessler/fabric, providing a collection of pre-built, tested system prompts for common AI tasks. Key features: - Message::fabric() factory method for easy pattern usage - FabricInputProcessor for dynamic pattern loading via chain options - FabricRepository for pattern management with caching - Support for custom pattern locations - Comprehensive test coverage Usage: 1. Install the patterns: composer require php-llm/fabric-pattern 2. Use via factory: Message::fabric('create_summary') 3. Or via processor: $chain->call($messages, ['fabric_pattern' => 'analyze_code']) The implementation requires the separate php-llm/fabric-pattern package to be installed, keeping the main library lightweight while allowing users to opt-in to Fabric patterns functionality. Closes #31 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Remove try/catch blocks for cleaner code - Use simple directory existence check - Update composer.json to only allow fabric-pattern ^0.1
- Repository is now always initialized (either provided or created) - Simplified code by removing null coalescing in processInput
- FabricPromptInterface::getPattern() now returns non-empty-string - FabricPrompt constructor expects non-empty-string for pattern - Improves type safety and PHPStan analysis
$systemMessage = new SystemMessage($fabricPrompt->getContent()); | ||
|
||
// Prepend the system message | ||
$input->messages = $input->messages->prepend($systemMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is happening if the MessageBag already have a System Message? I think most models can handle having multiple system messages. I have read some models do not care about the role of a message and take everything the same. But are we clear about possible problems when adding a system message to a bag that is already containing a system message? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, same with the SystemInputProcessor, only one SystemMessage is supported by llm-chain
{ | ||
if (null === $patternsPath) { | ||
// Check if fabric-pattern package is installed | ||
$fabricPatternPath = \dirname(__DIR__, 4).'/fabric-pattern/patterns'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this maybe be improved by checking for the existence of the pattern class from this package? For me checking directory hierarchie feels a bit unstable. And utilizing the pattern path btw. the loader from this class the library is delivering?
https://github.com/php-llm/fabric-pattern/blob/main/src/Pattern.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say yes, also not super happy right now with this extra package, maybe it's better to get all the data and check it in into the fabric-pattern repository by mentioning the copyright etc. or having a command to download the fabrics upfront and use this path. not sure yet
Summary
This PR implements support for Fabric patterns in LLM Chain, providing access to a comprehensive collection of pre-built, tested system prompts for common AI tasks.
Implementation Details
Core Components
Message::fabric()
Factory MethodMessage::fabric('create_summary')
php-llm/fabric-pattern
packageFabricInputProcessor
$chain->call($messages, ['fabric_pattern' => 'analyze_code'])
FabricRepository
php-llm/fabric-pattern
package installationException Handling
PatternNotFoundException
for missing patternsDesign Decisions
Separate Package Requirement
php-llm/fabric-pattern
packageMultiple Usage Patterns
Immutable Design
Usage Examples
Via Factory Method
Via Input Processor
Custom Pattern Location
Documentation
examples/fabric/
Testing
final
from FabricRepository)Available Patterns
Some popular patterns include:
create_summary
- Create comprehensive summariesanalyze_claims
- Fact-check and analyze claimsextract_wisdom
- Extract key insightsimprove_writing
- Enhance writing qualityanalyze_code
- Security and quality analysisCloses #31
🤖 Generated with Claude Code