thomasgenster/laragpt

Laravel ChatGPT 包,包括模型列表和检索、完成预测、对话中的聊天完成、编辑、图像创建、图像编辑、图像变体、音频翻译和转录。

dev-master 2024-03-14 09:39 UTC

This package is not auto-updated.

Last update: 2024-09-26 12:07:52 UTC


README

使用 laragpt 获取 OpenAI 的 API 权力。

laragpt 是开发人员通过易于使用的 Laravel 接口访问 OpenAI 强大人工智能能力的理想包。使用 laragpt,您可以快速使用 OpenAI 强大的深度学习算法、自然语言处理和机器学习功能,从而开发创新和复杂的应用程序。通过利用 OpenAI API 和 Laravel 简单的接口,laragpt 使将 AI 集成到项目中变得容易。使用 laragpt 为您的应用程序赋予 OpenAI 的智能。

安装

您可以通过 composer 安装此包

composer require jumbaeric/laragpt

发布配置文件

php artisan vendor:publish

并选择发布 laragpt 包。

将 OpenAI API 密钥添加到您的环境变量中

OPENAI_API_KEY=

用法

所有方法返回数组

use Jumbaeric\Laragpt\Laragpt;

// Complete
// Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
    $args = [
        'prompt' => 'Brainstorm some ideas combining VR and fitness', //required
        'model' => 'text-davinci-003',  //  required
    ];

    Laragpt::complete($args);

// Chat
// Given a chat conversation, the model will return a chat completion response.

Laragpt::chat([
        'model' => 'gpt-3.5-turbo', // required
        'messages' => [             // required
            [
                "role" => "system",
                "content" => "You are a helpful assistant."
            ],
            [
                "role" => "user",
                "content" => "Who won the world series in 2020?"
            ],
            [
                "role" => "assistant",
                "content" => "The Los Angeles Dodgers won the World Series in 2020."
            ],
            [
                "role" => "user",
                "content" => "Where was it played?"
            ],
        ],
        'temperature' => 1.0,   //  optional
        'max_tokens' => 4000,   //  optional
        'frequency_penalty' => 0,   //  optional
        'presence_penalty' => 0,    //  optional
    ]);

// Audio
// trascribe: Transcribes audio into the input language.
// translate: Translates audio into into English.

$type = "transcript"; // string: Required : value can be transcript or translation
Laragpt::audio([
            'model' => 'whisper-1',     //  required
            'file' => "audio.mp3",      //  required
            'prompt' => "",             //  optional
            'response_format' => '',    //  optional
            'temperature' => '',        //  optional
        ], $type);

// Edits
// Given a prompt and an instruction, the model will return an edited version of the prompt.
Laragpt::edits([
        'model' => 'text-davinci-edit-001', // required
        'input' => 'What day of the wek is it?',
        'instruction' => 'Fix the spelling mistakes',   //  required
        'n' => 1,   //  optional
        'temperature' => 1,   //  optional
        'top_p' => 1,    //  optional
    ]);

// Images
    $createArr = [ // $type = create
        'prompt' => 'A cute baby sea otter',
        'size' => '1024x1024',   //  required
        'n' => 1,   //  optional
    ] ;

    $ceateEditArr = [ // $type = createEdit
        'prompt' => 'A cute baby sea otter wearing a beret',    // required
        'image' => '@otter.png',                                //required
        'mask' => '@mask.png',
        'n' => 1,
        'size' => '1024x1024',
    ];

    $createVariationArr = [ // $type = variations
        'image' => '@otter.png',
        'n' => 2,
        'size' => '1024x1024',
    ];
    
    Laragpt::images($createArr, $type = 'create');

// Models
$model_id = null; // String : Optional : Lists all models when value is null, model set returns the model details
Laragpt::models($model_id);

测试

composer test

变更日志

有关最近更改的详细信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全性

如果您发现任何与安全相关的问题,请通过电子邮件 jumbaeric@gmail.com 而不是使用问题跟踪器。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件