Skip to content

Commit

Permalink
Merge pull request #1 from llm-agents-php/feature/laravel-support
Browse files Browse the repository at this point in the history
Adds laravel support
  • Loading branch information
butschster authored Sep 1, 2024
2 parents 5787b95 + 4521a12 commit d299212
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ composer require llm-agents/json-schema-mapper
### Setting it up in Spiral

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

**Here's how:**

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

```php
class Kernel extends \Spiral\Framework\Kernel
Expand All @@ -62,13 +63,23 @@ class Kernel extends \Spiral\Framework\Kernel
{
return [
// ... other bootloaders ...
\LLM\Agents\JsonSchema\Mapper\Bootloader\SchemaMapperBootloader::class,
\LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader::class,
];
}
}
```

And that's it! The bootloader will take care of registering the SchemaMapper for you.
And that's it! The bootloader will take care of registering all the necessary components for you.

### Setting it up in Laravel

If you're using the Laravel framework, you'll need to register the Service provider.

**Here's how:**

Just register the `LLM\Agents\JsonSchema\Mapper\Integration\Laravel\SchemaMapperServiceProvider`

And that's it! The service provider will take care of registering all the necessary components for you.

## How to Use It

Expand Down
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"php": "^8.3",
"spiral/json-schema-generator": "^1.0",
"llm-agents/agents": "^1.0",
"cuyz/valinor": "^1.12",
"spiral/boot": "^3.13"
"cuyz/valinor": "^1.12"
},
"require-dev": {
"phpunit/phpunit": "^11.3"
"phpunit/phpunit": "^11.3",
"spiral/boot": "^3.13",
"illuminate/support": "^v11.0"
},
"autoload": {
"psr-4": {
Expand All @@ -25,6 +26,13 @@
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"LLM\\Agents\\JsonSchema\\Mapper\\Integration\\Laravel\\SchemaMapperServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
45 changes: 45 additions & 0 deletions src/Integration/Laravel/SchemaMapperServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace LLM\Agents\JsonSchema\Mapper\Integration\Laravel;

use CuyZ\Valinor\Cache\FileSystemCache;
use CuyZ\Valinor\Mapper\TreeMapper;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use LLM\Agents\JsonSchema\Mapper\MapperBuilder;
use LLM\Agents\JsonSchema\Mapper\SchemaMapper;
use LLM\Agents\Tool\SchemaMapperInterface;

final class SchemaMapperServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(
SchemaMapperInterface::class,
SchemaMapper::class,
);

$this->app->singleton(
TreeMapper::class,
static fn(
Application $app,
) => $app->make(MapperBuilder::class)->build(),
);

$this->app->singleton(
MapperBuilder::class,
static fn(
Application $app,
) => new MapperBuilder(
cache: match (true) {
$app->environment('prod') => new FileSystemCache(
cacheDir: $app->storagePath('cache/valinor'),
),
default => null,
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace LLM\Agents\JsonSchema\Mapper\Bootloader;
namespace LLM\Agents\JsonSchema\Mapper\Integration\Spiral;

use CuyZ\Valinor\Cache\FileSystemCache;
use CuyZ\Valinor\Mapper\TreeMapper;
Expand Down

0 comments on commit d299212

Please sign in to comment.