PHP code example of llm-agents / json-schema-mapper

1. Go to this page and download the library: Download llm-agents/json-schema-mapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

llm-agents / json-schema-mapper example snippets


class Kernel extends \Spiral\Framework\Kernel
{
    // ...

    public function defineBootloaders(): array
    {
        return [
            // ... other bootloaders ...
            \LLM\Agents\JsonSchema\Mapper\Integration\Spiral\SchemaMapperBootloader::class,
        ];
    }
}

use LLM\Agents\JsonSchema\Mapper\SchemaMapperInterface;

class UserController
{
    public function __construct(
        private SchemaMapperInterface $schemaMapper
    ) {}

    public function getUserSchema(): array
    {
        return $this->schemaMapper->toJsonSchema(User::class);
    }
}

use LLM\Agents\JsonSchema\Mapper\SchemaMapperInterface;

class UserService
{
    public function __construct(
        private SchemaMapperInterface $schemaMapper
    ) {}

    public function createUserFromJson(string $json): User
    {
        return $this->schemaMapper->toObject($json, User::class);
    }
}