Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ llm_chain:
model:
name: 'GPT'
version: 'gpt-4o-mini'
system_prompt: 'You are a helpful assistant that can answer questions.' # The default system prompt of the chain
tools:
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
research:
Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->booleanNode('structured_output')->defaultTrue()->end()
->scalarNode('system_prompt')
->validate()
->ifTrue(fn ($v) => null !== $v && '' === trim($v))
->thenInvalid('The default system prompt must not be an empty string')
->end()
->defaultNull()
->info('The default system prompt of the chain')
->end()
->arrayNode('tools')
->addDefaultsIfNotSet()
->treatFalseLike(['enabled' => false])
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/LlmChainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PhpLlm\LlmChain\Bridge\Voyage\Voyage;
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Chain\InputProcessor;
use PhpLlm\LlmChain\Chain\InputProcessor\SystemPromptInputProcessor;
use PhpLlm\LlmChain\Chain\OutputProcessor;
use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
Expand Down Expand Up @@ -259,6 +260,17 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
$inputProcessors[] = new Reference(StructureOutputProcessor::class);
$outputProcessors[] = new Reference(StructureOutputProcessor::class);
}

// SYSTEM PROMPT
if (is_string($config['system_prompt'])) {
$systemPromptInputProcessorDefinition = new Definition(SystemPromptInputProcessor::class);
$systemPromptInputProcessorDefinition
->setAutowired(true)
->setArgument('$systemPrompt', $config['system_prompt']);

$inputProcessor[] = $systemPromptInputProcessorDefinition;
}

$chainDefinition
->setArgument('$inputProcessors', $inputProcessors)
->setArgument('$outputProcessors', $outputProcessors);
Expand Down
Loading