定制 dmsemenov/openai-attribute 二次开发

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

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

dmsemenov/openai-attribute

最新稳定版本:v1.2.3

Composer 安装命令:

composer require dmsemenov/openai-attribute

包简介

Allow to fill model attribute from OpenAi response.

README 文档

README

GitHub license Latest Version on Packagist Total Downloads

Laravel package that allows to define ChatGPT generated attributes for Laravel model like description or other "text" attribute.

Installation

  • Install package
 composer require dmsemenov/openai-attribute

Configuration

Publish config if needed:

 php artisan vendor:publish --provider="Dmsemenov\OpenaiAttribute\OpenaiAttributeServiceProvider"

It is possible to specify request options in published config or in the model generatedAttributes() method.
Available request options see at OpenApi documentation page.

    // OpenAI api key
    'api_key' => env('OPENAI_API_KEY'),

    // Queue name for generate attributes jobs
    'queue_name' => env('OPENAI_QUEUE_NMAE', 'openai_generate'),

    // Default options for api chat completions requests.
    'default_options' => [
        'model' => env('OPENAI_API_MODEL', 'gpt-3.5-turbo'),
        'temperature' => 0.3,
        'max_tokens' => 100,
        'top_p' => 1.0,
        'frequency_penalty' => 0.0,
        'presence_penalty' => 0.0
    ],

Usage

Trait HasGeneratedAttributes should be added to model. it contains list of model attributes with prompt and options (if needed, see default_options):

public function generatedAttributes(): array
{
    return [
        'description' => [
            'prompt' => 'Tell info about [model:name]". Wrap each paragraph to tag <p>',
            'max_tokens' => 1000
        ],

        'slug' => [
            'prompt' => 'Generate slug from [model:name]',
            'max_tokens' => 10
        ],
    ];
}

Models that fits condition in [MyModel]->NeedsGenerateAttributes() will be selected for attributes generation. Default: all.

Artisan commands to generate attributes:

php artisan openai:generate App\\Models\\[MyModel] --queued

or generate instantly without queue option:

php artisan openai:generate App\\Models\\[MyModel]

or specify model ids list:

php artisan openai:generate App\\Models\\[MyModel] --ids=1 --ids=2

Other useful commands:

Display queue size:
php artisan queue:monitor openai_generate

Remove jobs from queue:
php artisan queue:clear --queue=openai_generate

Run workers:
php artisan queue:work --queue=openai_generate

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email dimitr.semenov@gmail.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-18