定制 blinq/synth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

blinq/synth

Composer 安装命令:

composer require blinq/synth

包简介

This is my package synth

README 文档

README

(Not an official Laravel package)

Synth for Laravel

Synth is a Laravel tool that helps you generate code and perform various tasks in your Laravel application. It leverages the power of OpenAI's GPT language model to provide an interactive and intelligent development experience.

Demo

Architect -> create a todo app 😎🏗️📝

B.mp4

Attach files and create a readme.md 📎📄✍️

B2.mp4

Installation

  1. Install the Synth package using Composer:

    composer require blinq/synth
  2. Publish the Synth configuration file:

    php artisan vendor:publish --tag=synth-config

    Here you can change the used model (gpt4 versus gpt3)

  3. Set your OpenAI API key in the .env file:

    OPENAI_KEY=YOUR_API_KEY

Usage

To use Synth, simply run the synth command:

php artisan synth

This will open the Synth CLI, where you can interact with the GPT model and perform various tasks.

Features 🌟

  • Automatically switch from small to large model when needed (gpt-3.5-turbo vs gpt-3.5-turbo-16k) 🔄
  • Include the whole database schema as an attachment
  • Uses the functions API of OpenAI 👨‍💻
  • Cancel generation with Ctrl+C 🚫⌨
  • Attachments: Attach files to the conversation with GPT. 🗂️
  • Architect: Brainstorm and generate a new application architecture. 💡🏛
  • Chat: Chat with GPT to get responses and perform actions. 💬
  • Make: Forces GPT to generate files for the question asked. 📂
  • Migrations: Generate migrations for your application. 📦
  • Models: Generate models for your application. 📈
  • Files: Write files to the filesystem. 🖊️

You can select a module from the main menu and follow the prompts to perform the desired actions.

Note: Some modules require a previous step to be completed, such as creating an architecture before generating migrations or models.

Writing Your Own Modules

Synth allows you to extend its functionality by writing your own modules. A module is a class that implements the necessary methods to register and handle specific actions.

To create a new module, follow these steps:

  1. Create a new PHP class that extends the Module class.
  2. Implement the name method to define the name of your module.
  3. Implement the register method to define the actions provided by your module.
  4. Implement the onSelect method to handle the selected action.

Here is an example of a custom module implementation:

use Blinq\Synth\Modules\Module;

/**
 * Class MyModule
 * 
 * @propery \Blinq\Synth\Commands\SynthCommand $cmd
 */
class MyModule extends Module
{
    public function name(): string
    {
        return 'MyModule';
    }

    public function register(): array
    {
        return [
            'action1' => 'Perform Action 1',
            'action2' => 'Perform Action 2',
        ];
    }

    public function onSelect(?string $key = null)
    {
        $this->cmd->info("You selected: {$key}");

        $synth = $this->cmd->synth;

        if ($key === 'action1') {
            // Handle Action 1
            while (true) {
                $input = $this->cmd->ask("You");

                // Send the input to GPT
                $synth->chat($input, [
                    // ... The OpenAI Chat options

                    // If you want a function to be called by GPT
                    'function_call' => ['name' => 'some_function'], // Forces the function call
                    'functions' => [
                        [
                            'name' => 'some_function',
                            'description' => 'Description of the function',
                            'parameters' => [
                                // ..schema
                            ]
                        ]
                    ]
                ]);

                Functions::register('some_function', function (SynthCommand $cmd, $args, $asSpecified, $inSchema) { // etc..
                    // Do something with the call
                });

                // This will parse the json result and call the function if needed
                $synth->handleFunctionsForLastMessage();

                // Just retrieve the last message
                $lastMessage = $synth->getLastMessage();

                // Echo it's contents
                echo $lastMessage->content;

                // Or it's raw function_call
                dump($lastMessage->function_call);

                if (!$input || $input == 'exit') {
                    break;
                }
            }
        }
        if ($key === 'action2') {
            // Handle Action 2
        }
    }
}

You can then register your custom module in the Modules class within the Synth package and use it in the CLI interface:

use Blinq\Synth\Modules;

Modules::register(MyModule::class);

blinq/synth 适用场景与选型建议

blinq/synth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.86k 次下载、GitHub Stars 达 279, 最近一次更新时间为 2023 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「blinq」 「synth」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 blinq/synth 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 16.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 279
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 279
  • Watchers: 4
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-19