From 1d09b98ab31ac8dec3172775e2c462cb207b2048 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Sun, 1 Jun 2025 21:46:11 +0200 Subject: [PATCH] fix: support for 0.22 --- src/DependencyInjection/LlmChainExtension.php | 20 +++++++++---------- src/Profiler/TraceablePlatform.php | 3 +-- src/Resources/config/services.php | 2 +- src/Resources/views/data_collector.html.twig | 10 +++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/DependencyInjection/LlmChainExtension.php b/src/DependencyInjection/LlmChainExtension.php index 81fbbce..0263855 100644 --- a/src/DependencyInjection/LlmChainExtension.php +++ b/src/DependencyInjection/LlmChainExtension.php @@ -213,28 +213,28 @@ private function processChainConfig(string $name, array $config, ContainerBuilde // MODEL ['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model']; - $llmClass = match (strtolower((string) $modelName)) { + $modelClass = match (strtolower((string) $modelName)) { 'gpt' => GPT::class, 'claude' => Claude::class, 'llama' => Llama::class, 'gemini' => Gemini::class, default => throw new \InvalidArgumentException(sprintf('Model "%s" is not supported.', $modelName)), }; - $llmDefinition = new Definition($llmClass); + $modelDefinition = new Definition($modelClass); if (null !== $version) { - $llmDefinition->setArgument('$name', $version); + $modelDefinition->setArgument('$name', $version); } if (0 !== count($options)) { - $llmDefinition->setArgument('$options', $options); + $modelDefinition->setArgument('$options', $options); } - $llmDefinition->addTag('llm_chain.model.language_model'); - $container->setDefinition('llm_chain.chain.'.$name.'.llm', $llmDefinition); + $modelDefinition->addTag('llm_chain.model.language_model'); + $container->setDefinition('llm_chain.chain.'.$name.'.model', $modelDefinition); // CHAIN $chainDefinition = (new Definition(Chain::class)) ->setAutowired(true) ->setArgument('$platform', new Reference($config['platform'])) - ->setArgument('$llm', new Reference('llm_chain.chain.'.$name.'.llm')); + ->setArgument('$model', new Reference('llm_chain.chain.'.$name.'.model')); $inputProcessors = []; $outputProcessors = []; @@ -266,7 +266,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde } $toolboxDefinition = (new ChildDefinition('llm_chain.toolbox.abstract')) - ->replaceArgument('$metadataFactory', new Reference('llm_chain.toolbox.'.$name.'.chain_factory')) + ->replaceArgument('$toolFactory', new Reference('llm_chain.toolbox.'.$name.'.chain_factory')) ->replaceArgument('$tools', $tools); $container->setDefinition('llm_chain.toolbox.'.$name, $toolboxDefinition); @@ -436,10 +436,10 @@ private function processEmbedderConfig(int|string $name, array $config, Containe $modelDefinition->setArgument('$options', $options); } $modelDefinition->addTag('llm_chain.model.embeddings_model'); - $container->setDefinition('llm_chain.embedder.'.$name.'.embeddings', $modelDefinition); + $container->setDefinition('llm_chain.embedder.'.$name.'.model', $modelDefinition); $definition = new Definition(Embedder::class, [ - '$embeddings' => new Reference('llm_chain.embedder.'.$name.'.embeddings'), + '$model' => new Reference('llm_chain.embedder.'.$name.'.model'), '$platform' => new Reference($config['platform']), '$store' => new Reference($config['store']), ]); diff --git a/src/Profiler/TraceablePlatform.php b/src/Profiler/TraceablePlatform.php index f10caff..482df5a 100644 --- a/src/Profiler/TraceablePlatform.php +++ b/src/Profiler/TraceablePlatform.php @@ -7,7 +7,6 @@ use PhpLlm\LlmChain\Platform\Message\Content\File; use PhpLlm\LlmChain\Platform\Model; use PhpLlm\LlmChain\Platform\PlatformInterface; -use PhpLlm\LlmChain\Platform\Response\AsyncResponse; use PhpLlm\LlmChain\Platform\Response\ResponseInterface; /** @@ -42,7 +41,7 @@ public function request(Model $model, array|string|object $input, array $options 'model' => $model, 'input' => is_object($input) ? clone $input : $input, 'options' => $options, - 'response' => $response instanceof AsyncResponse ? $response->unwrap() : $response, + 'response' => $response->getContent(), ]; return $response; diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 8581a8e..9709cc0 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -33,7 +33,7 @@ ->autowire() ->abstract() ->args([ - '$metadataFactory' => service(ToolFactoryInterface::class), + '$toolFactory' => service(ToolFactoryInterface::class), '$tools' => abstract_arg('Collection of tools'), ]) ->set(Toolbox::class) diff --git a/src/Resources/views/data_collector.html.twig b/src/Resources/views/data_collector.html.twig index f70536d..3d5772f 100644 --- a/src/Resources/views/data_collector.html.twig +++ b/src/Resources/views/data_collector.html.twig @@ -153,16 +153,16 @@ Response - {% if call.input.messages is defined and call.response.content is iterable %}{# expect array of ToolCall #} - {{ _self.tool_calls(call.response.content) }} - {% elseif call.response.content is iterable %}{# expect array of Vectors #} + {% if call.input.messages is defined and call.response is iterable %}{# expect array of ToolCall #} + {{ _self.tool_calls(call.response) }} + {% elseif call.response is iterable %}{# expect array of Vectors #}
    - {% for vector in call.response.content %} + {% for vector in call.response %}
  1. Vector with {{ vector.dimensions }} dimensions
  2. {% endfor %}
{% else %} - {{ call.response.content }} + {{ call.response }} {% endif %}