Git Product home page Git Product logo

laravel-synth's Introduction

Synth for Laravel

(Not a 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
  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) ๐Ÿ”„
  • 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(): arraya
    {
        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);

laravel-synth's People

Contributors

dependabot[bot] avatar lennardv2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.