Skip to content

Commit 31a7d46

Browse files
committed
Adds laravel support
1 parent 5787b95 commit 31a7d46

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If you're using the Spiral framework (and why wouldn't you be? It's awesome!), y
5151
Here's how:
5252

5353
1. Open up your `app/src/Application/Kernel.php` file.
54-
2. Add the SchemaMapperBootloader to the `defineBootloaders()` method:
54+
2. Add the `LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader` to the `defineBootloaders()` method:
5555

5656
```php
5757
class Kernel extends \Spiral\Framework\Kernel
@@ -62,14 +62,23 @@ class Kernel extends \Spiral\Framework\Kernel
6262
{
6363
return [
6464
// ... other bootloaders ...
65-
\LLM\Agents\JsonSchema\Mapper\Bootloader\SchemaMapperBootloader::class,
65+
\LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader::class,
6666
];
6767
}
6868
}
6969
```
7070

7171
And that's it! The bootloader will take care of registering the SchemaMapper for you.
7272

73+
### Setting it up in Laravel
74+
75+
If you're using the Spiral framework (and why wouldn't you be? It's awesome!), you'll need to register the bootloader.
76+
Here's how:
77+
78+
Just register the `LLM\Agents\JsonSchema\Mapper\Integration\Laravel\SchemaMapperServiceProvider`
79+
80+
And that's it! The service provider will take care of registering the SchemaMapper for you.
81+
7382
## How to Use It
7483

7584
### Converting a PHP Class to JSON Schema

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"php": "^8.3",
77
"spiral/json-schema-generator": "^1.0",
88
"llm-agents/agents": "^1.0",
9-
"cuyz/valinor": "^1.12",
10-
"spiral/boot": "^3.13"
9+
"cuyz/valinor": "^1.12"
1110
},
1211
"require-dev": {
13-
"phpunit/phpunit": "^11.3"
12+
"phpunit/phpunit": "^11.3",
13+
"spiral/boot": "^3.13",
14+
"illuminate/support": "^v11.0"
1415
},
1516
"autoload": {
1617
"psr-4": {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LLM\Agents\JsonSchema\Mapper\Integration\Laravel;
6+
7+
use CuyZ\Valinor\Cache\FileSystemCache;
8+
use CuyZ\Valinor\Mapper\TreeMapper;
9+
use Illuminate\Contracts\Foundation\Application;
10+
use Illuminate\Support\ServiceProvider;
11+
use LLM\Agents\JsonSchema\Mapper\MapperBuilder;
12+
use LLM\Agents\JsonSchema\Mapper\SchemaMapper;
13+
use LLM\Agents\Tool\SchemaMapperInterface;
14+
15+
final class SchemaMapperServiceProvider extends ServiceProvider
16+
{
17+
public function register(): void
18+
{
19+
$this->app->singleton(
20+
SchemaMapperInterface::class,
21+
SchemaMapper::class,
22+
);
23+
24+
$this->app->singleton(
25+
TreeMapper::class,
26+
static fn(
27+
MapperBuilder $builder,
28+
) => $builder->build(),
29+
);
30+
31+
$this->app->singleton(
32+
MapperBuilder::class,
33+
static fn(
34+
Application $app,
35+
) => new MapperBuilder(
36+
cache: match (true) {
37+
$app->environment('prod') => new FileSystemCache(
38+
cacheDir: $app->storagePath('cache/valinor'),
39+
),
40+
default => null,
41+
},
42+
),
43+
);
44+
}
45+
}

src/Bootloader/SchemaMapperBootloader.php renamed to src/Integration/Spiral/SchemaMapperBootloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace LLM\Agents\JsonSchema\Mapper\Bootloader;
5+
namespace LLM\Agents\JsonSchema\Mapper\Integration\Spiral;
66

77
use CuyZ\Valinor\Cache\FileSystemCache;
88
use CuyZ\Valinor\Mapper\TreeMapper;

0 commit comments

Comments
 (0)