halilcosdu/laravel-finetuner

Laravel Fine tuner 是一个为 Laravel 框架设计的包,用于自动化 OpenAI 模型的微调。它简化了调整模型参数以优化性能的过程,专为 Laravel 应用程序量身定制。此工具非常适合希望高效提升其项目中 AI 能力的开发者,且手动干预最小化。

v1.0.3 2024-04-23 15:19 UTC

This package is auto-updated.

Last update: 2024-09-08 13:25:50 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

它简化了调整模型参数以优化性能的过程,专为 Laravel 应用程序量身定制。此工具非常适合希望高效提升其项目中 AI 能力的开发者,且手动干预最小化。

安装

您可以通过 composer 安装此包

composer require halilcosdu/laravel-finetuner

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="finetuner-config"

这是已发布的配置文件的内容

return [
    'api_key' => env('OPENAI_API_KEY'),
    'organization' => env('OPENAI_ORGANIZATION'),
    'request_timeout' => env('OPENAI_TIMEOUT'),
    'use_storage' => env('FINE_TUNER_USE_STORAGE', false),
    'sleep_seconds' => env('OPENAI_SLEEP_SECONDS'), //Sleep seconds between requests default .1
    'storage' => [
        'disk' => env('FINE_TUNER_STORAGE', 'public'),
    ],

用法

use HalilCosdu\FineTuner\Facades\FineTuner;

FineTuner::generateExamples($prompt, $temperature = .4, $numberOfExamples = 2): array
FineTuner::upload(string $file): string
FineTuner::fineTune(string $fileId, string $model = 'gpt-3.5-turbo'): string
use HalilCosdu\FineTuner\Facades\FineTuner;

// Generate examples for fine-tuning
$trainingExamples = FineTuner::generateExamples("A versatile AI assistant designed to provide personalized support across all aspects of life, from physical health and mental wellness to emotional well-being, adapting its guidance to the user's unique situation and needs. It offers practical advice, empathetic support, and proactive reminders, all while ensuring privacy and security, and continuously evolving through feedback and research.")
{
  "training_data": [
    {
      "messages": [
        {
          "role": "system",
          "content": "Given your current situation and needs, how can I assist you today?"
        },
        {
          "role": "user",
          "content": "Hey AI, I've been feeling really stressed out lately because of work. Any advice on how I can manage this better?"
        },
        {
          "role": "assistant",
          "content": "I'm really sorry to hear that you're feeling this way, but please know that it's okay to feel stressed. Here are a few suggestions that might help:\n\n1. Mindfulness and Relaxation: Try techniques like deep breathing, meditation, or yoga. They can help you to stay calm and focused.\n\n2. Time Management: Prioritize your tasks and break them down into manageable chunks. Remember, it's okay to say no to tasks that are not a priority.\n\n3. Physical Activity: Regular exercise can help reduce stress levels. Even a short walk can make a difference.\n\n4. Connect with Others: Talk to someone you trust about your stress. It can often help to share what you're experiencing.\n\n5. Professional Help: If your stress continues or leads to feelings of despair, it might be helpful to speak with a mental health professional.\n\nRemember, everyone experiences stress differently and different techniques work for different people. It's important to find what works best for you."
        }
      ]
    }
  ],
  "file_url": null
}
// If the `FINE_TUNER_USE_STORAGE` environment variable is set to `true`, the `file_url` will be returned for the upload function. Alternatively, you can create your own training `.jsonl` file using the `training_data`.

// Upload the training data
$fileId = FineTuner::upload($trainingExamples['file_url'])

// Fine-tune the model
FineTuner::fineTune($fileId, 'gpt-3.5-turbo')

使用 php artisan laravel-finetuner 命令与 Laravel Finetuner 包交互。此命令启动一个生成示例的过程。

以下是对此命令的详细说明

  1. 打开您的终端。

  2. 导航到您的 Laravel 项目目录。

  3. 运行命令 php artisan laravel-finetuner

  4. 该命令将首先要求输入一个 提示。这是一个字符串,将被用于生成微调示例。如果您不提供提示,它将使用默认值。

  5. 接下来,它将要求输入 温度。这是一个浮点值,控制生成示例的随机性。更高的值将产生更随机的示例。如果您不提供温度,它将使用默认值 .4

  6. 然后,它将要求输入 示例数量。这是一个整数,指定要生成多少个示例。如果您不提供数字,它将使用默认值 1

  7. 在您提供这些输入后,该命令将要求您确认继续。如果您确认,它将开始生成示例,这可能需要一段时间。

  8. 一旦生成示例,它们将被上传。如果在过程中出现错误,该命令将显示错误消息。

  9. 如果一切顺利,该命令将显示一个 URL。此 URL 指向已上传生成的示例的位置。

请记住,此命令是 Laravel Finetuner 包的一部分,该包旨在自动化 Laravel 应用程序中 OpenAI 模型的微调。

php artisan laravel-finetuner

测试

composer test

更新日志

有关最近更改的更多信息,请参阅 更新日志

贡献

请参阅 贡献指南 了解详细信息。

安全漏洞

请查看 我们的安全策略 了解如何报告安全漏洞。

鸣谢

许可

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