Skip to content

Commit d299212

Browse files
authored
Merge pull request #1 from llm-agents-php/feature/laravel-support
Adds laravel support
2 parents 5787b95 + 4521a12 commit d299212

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ composer require llm-agents/json-schema-mapper
4848
### Setting it up in Spiral
4949

5050
If you're using the Spiral framework (and why wouldn't you be? It's awesome!), you'll need to register the bootloader.
51-
Here's how:
51+
52+
**Here's how:**
5253

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

5657
```php
5758
class Kernel extends \Spiral\Framework\Kernel
@@ -62,13 +63,23 @@ class Kernel extends \Spiral\Framework\Kernel
6263
{
6364
return [
6465
// ... other bootloaders ...
65-
\LLM\Agents\JsonSchema\Mapper\Bootloader\SchemaMapperBootloader::class,
66+
\LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader::class,
6667
];
6768
}
6869
}
6970
```
7071

71-
And that's it! The bootloader will take care of registering the SchemaMapper for you.
72+
And that's it! The bootloader will take care of registering all the necessary components for you.
73+
74+
### Setting it up in Laravel
75+
76+
If you're using the Laravel framework, you'll need to register the Service provider.
77+
78+
**Here's how:**
79+
80+
Just register the `LLM\Agents\JsonSchema\Mapper\Integration\Laravel\SchemaMapperServiceProvider`
81+
82+
And that's it! The service provider will take care of registering all the necessary components for you.
7283

7384
## How to Use It
7485

composer.json

Lines changed: 11 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": {
@@ -25,6 +26,13 @@
2526
"config": {
2627
"sort-packages": true
2728
},
29+
"extra": {
30+
"laravel": {
31+
"providers": [
32+
"LLM\\Agents\\JsonSchema\\Mapper\\Integration\\Laravel\\SchemaMapperServiceProvider"
33+
]
34+
}
35+
},
2836
"minimum-stability": "dev",
2937
"prefer-stable": true
3038
}
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+
Application $app,
28+
) => $app->make(MapperBuilder::class)->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)