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
25 changes: 24 additions & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pipeline
on: pull_request

jobs:
pipeline:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -28,6 +28,29 @@ jobs:
- name: Install PHP Dependencies
run: composer install --no-scripts

- name: Tests
run: vendor/bin/phpunit

qa:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Install Composer
uses: "ramsey/composer-install@v3"

- name: Composer Validation
run: composer validate --strict

- name: Install PHP Dependencies
run: composer install --no-scripts

- name: Code Style PHP
run: vendor/bin/php-cs-fixer fix --dry-run

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor
composer.lock
.php-cs-fixer.cache
.phpunit.cache
coverage
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@ qa:
composer update --prefer-stable
vendor/bin/php-cs-fixer fix
vendor/bin/phpstan
vendor/bin/phpunit

qa-lowest:
composer update --prefer-lowest
vendor/bin/php-cs-fixer fix
vendor/bin/phpstan
vendor/bin/phpunit

qa-dev:
composer require php-llm/llm-chain:dev-main
vendor/bin/php-cs-fixer fix
vendor/bin/phpstan
vendor/bin/phpunit
# revert
git restore composer.json

coverage:
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "php-llm/llm-chain-bundle",
"type": "symfony-bundle",
"description": "Symfony integration bundle for php-llm/llm-chain",
"license": "MIT",
"type": "symfony-bundle",
"authors": [
{
"name": "Christopher Hertel",
Expand All @@ -18,13 +18,22 @@
},
"require-dev": {
"php-cs-fixer/shim": "^3.64",
"phpstan/phpstan": "^1.12"
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.3"
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"PhpLlm\\LlmChainBundle\\": "src/"
}
}
},
"autoload-dev": {
"psr-4": {
"PhpLlm\\LlmChainBundle\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/DependencyInjection/LlmChainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use PhpLlm\LlmChain\Store\StoreInterface;
use PhpLlm\LlmChain\Store\VectorStoreInterface;
use PhpLlm\LlmChain\ToolBox\AsTool;
use PhpLlm\LlmChainBundle\DataCollector;
use PhpLlm\LlmChainBundle\TraceableLanguageModel;
use PhpLlm\LlmChainBundle\TraceableToolBox;
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
use PhpLlm\LlmChainBundle\Profiler\TraceableLanguageModel;
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
6 changes: 3 additions & 3 deletions src/DataCollector.php → src/Profiler/DataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhpLlm\LlmChainBundle;
namespace PhpLlm\LlmChainBundle\Profiler;

use PhpLlm\LlmChain\ToolBox\Metadata;
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
Expand All @@ -17,7 +17,7 @@
final class DataCollector extends AbstractDataCollector
{
/**
* @var list<TraceableLanguageModel>
* @var TraceableLanguageModel[]
*/
private readonly array $llms;

Expand All @@ -27,7 +27,7 @@ final class DataCollector extends AbstractDataCollector
public function __construct(
#[AutowireIterator('llm_chain.traceable_llm')]
iterable $llms,
private TraceableToolBox $toolBox,
private readonly TraceableToolBox $toolBox,
) {
$this->llms = $llms instanceof \Traversable ? iterator_to_array($llms) : $llms;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhpLlm\LlmChainBundle;
namespace PhpLlm\LlmChainBundle\Profiler;

use PhpLlm\LlmChain\LanguageModel;
use PhpLlm\LlmChain\Message\MessageBag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

declare(strict_types=1);

namespace PhpLlm\LlmChainBundle;
namespace PhpLlm\LlmChainBundle\Profiler;

use PhpLlm\LlmChain\Response\ToolCall;
use PhpLlm\LlmChain\ToolBox\ToolBox;
use PhpLlm\LlmChain\ToolBox\ToolBoxInterface;

/**
Expand All @@ -22,7 +21,7 @@ final class TraceableToolBox implements ToolBoxInterface
public array $calls = [];

public function __construct(
private ToolBox $toolRegistry,
private ToolBoxInterface $toolRegistry,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
use PhpLlm\LlmChain\ToolBox\ToolBox;
use PhpLlm\LlmChain\ToolBox\ToolBoxInterface;
use PhpLlm\LlmChainBundle\DataCollector;
use PhpLlm\LlmChainBundle\TraceableToolBox;
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;

return static function (ContainerConfigurator $container) {
$container->services()
Expand Down
70 changes: 70 additions & 0 deletions tests/Profiler/TraceableToolBoxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace PhpLlm\LlmChainBundle\Tests\Profiler;

use PhpLlm\LlmChain\Response\ToolCall;
use PhpLlm\LlmChain\ToolBox\Metadata;
use PhpLlm\LlmChain\ToolBox\ToolBoxInterface;
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

#[CoversClass(TraceableToolBox::class)]
#[Small]
final class TraceableToolBoxTest extends TestCase
{
#[Test]
public function getMap(): void
{
$metadata = new Metadata('Foo\Bar', 'bar', 'description', '__invoke', null);
$toolBox = $this->createToolBox(['tool' => $metadata]);
$traceableToolBox = new TraceableToolBox($toolBox);

$map = $traceableToolBox->getMap();

self::assertSame(['tool' => $metadata], $map);
}

#[Test]
public function execute(): void
{
$metadata = new Metadata('Foo\Bar', 'bar', 'description', '__invoke', null);
$toolBox = $this->createToolBox(['tool' => $metadata]);
$traceableToolBox = new TraceableToolBox($toolBox);
$toolCall = new ToolCall('foo', '__invoke');

$result = $traceableToolBox->execute($toolCall);

self::assertSame('tool_result', $result);
self::assertCount(1, $traceableToolBox->calls);
self::assertSame($toolCall, $traceableToolBox->calls[0]['call']);
self::assertSame('tool_result', $traceableToolBox->calls[0]['result']);
}

/**
* @param Metadata[] $metadata
*/
private function createToolBox(array $metadata): ToolBoxInterface
{
return new class($metadata) implements ToolBoxInterface {
public function __construct(
private array $metadata,
) {
}

public function getMap(): array
{
return $this->metadata;
}

public function execute(ToolCall $toolCall): string
{
return 'tool_result';
}
};
}
}