llm-agents/json-schema-mapper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

llm-agents/json-schema-mapper

Composer 安装命令:

composer require llm-agents/json-schema-mapper

包简介

JSON Schema to PHP Class Mapper for LLM Agents

README 文档

README

PHP Latest Version on Packagist Total Downloads

This package is a super handy JSON Schema Mapper for the LLM Agents project.

What's it all about?

This package gives you a nifty SchemaMapper that can:

  • Convert PHP classes to JSON schemas
  • Turn JSON data into PHP objects

Class Diagram

Here's a quick look at how the main components fit together:

classDiagram
    class SchemaMapperInterface {
        <<interface>>
        +toJsonSchema(string $class): array
        +toObject(string $json, ?string $class): object
    }
    class SchemaMapper {
        -generator: JsonSchemaGenerator
        -mapper: TreeMapper
        +toJsonSchema(string $class): array
        +toObject(string $json, ?string $class): object
    }
    SchemaMapperInterface <|.. SchemaMapper
    SchemaMapper --> JsonSchemaGenerator
    SchemaMapper --> TreeMapper
Loading

Getting Started

Installation

First things first, let's get this package installed:

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:

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

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

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

Converting a PHP Class to JSON Schema

Let's say you have a User class and you want to get its JSON schema:

use LLM\Agents\JsonSchema\Mapper\SchemaMapperInterface;

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

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

Converting JSON to a PHP Object

Got some JSON data that you want to turn into a PHP object? No problem:

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);
    }
}

Contributing

We'd love your help to make this package even better! Here's how you can contribute:

  1. Fork the repository
  2. Write some awesome code
  3. Create a new Pull Request

Please make sure your code follows PSR-12 coding standards and include tests for any new features.

License

This package is open-sourced software licensed under the MIT license. Feel free to use it, modify it, and share it!

That's all, folks! If you have any questions or run into any issues, don't hesitate to open an issue on GitHub.

llm-agents/json-schema-mapper 适用场景与选型建议

llm-agents/json-schema-mapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 354 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 08 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 llm-agents/json-schema-mapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 llm-agents/json-schema-mapper 我们能提供哪些服务?
定制开发 / 二次开发

基于 llm-agents/json-schema-mapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 354
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 15
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-28