承接 dejury/gptfaker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dejury/gptfaker

Composer 安装命令:

composer require dejury/gptfaker

包简介

An package that integrates with FakerPHP and generates AI based texts

README 文档

README

This package adds the possibility to use GPT to generate fake text. It completely integrates with Laravel and their factories.

Installation

Install the package using composer:

composer require dejury/gptfaker --dev

Add this to your .env file:

FAKERGPT_OPENAI_API_KEY=<your-api-key>

Config

The config file can be published with the following command:

php artisan vendor:publish --provider="Motivo\GptFaker\GptFakerServiceProvider"

Usage

Use it in your Laravel Factory:

<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Page;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\Factory;

class PageFactory extends Factory
{

    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Page::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition(): array
    {
        return [
            'name'    => $this->faker->unique()->gpt('Create an title for the page'),
            'slug'    => $this->faker->slug,
            'content' => $this->faker->gpt('Create a short paragraph for the page'),
            'visible' => true,
        ];
    }
}

Fallback

A fallback can be supplied in case ChatGPT is unable to create a response, the api key is not set or if FakerGPT should not be executed for the given environment. By default this value is set to null so it is highly recommended to provide a valid fallback.

$this->faker->gpt(
    'Create a short paragraph for the page', 
    $this->faker->paragraph
),

Multi-language

Prompts are accepted in every language ChatGPT understands. The results will be translated to your configured faker locale.

Multiple prompts

It is possible to give an array with prompts:

$choices = $this->faker->unique()->gpt(
    prompt: [
        "Maak een functietitel binnen de zorg aan",
        "Maak een korte titel over het werken in de zorg",
        "Maak een korte quote over het werken in de zorg",
        "Maak een korte alinea over het werken in de zorg",
    ],
    returnArray: true
);

return [
    'overview_pretitle' => Str::of($choices[0]?->text)->trim(),
];

Environments

You can configure for which environments FakerGPT should be executed. By default this is only for local environment. This can be changed by publishing the config file as described above and overwriting the environment config.

Trimming quotes

ChatGPT has a tendency to start end and sentences with quotes, especially when requesting titles, this is often undesirable. These quotes can be trimmed as follows:

$this->faker->unique()->gpt(
    prompt: "Maak een functietitel binnen de zorg aan",
    trimQuotes: true
);

Performance mode

Performance mode can be enabled to drastically improve the speed of your factories/seeders. This executes the same prompt several times at once instead of making multiple requests and caches the results. Each result will only be used once. When the cache runs empty a new batch will be fetched. This is an opt-in feature, as it may expend tokens to cache results that might never be used, and as a result it becomes more expensive to use.

This feature can be enabled by adding the following line to your .env

FAKERGPT_PERFORMANCE_MODE=true

Persistent Cache

Often it is enough to generate fake data once rather than for every time the seeders are being executed, both for monetary and execution speed reasons. For these situations persistent cache can be enabled. This will cache the prompts and their results in .fakergpt_cache.php.

FAKERGPT_PERSISTENT_CACHE=true

Persistent cache will have the side effect (and potential benefit) that generated content is predictable.

Unlike most cache files it's highly recommended to commit the .fakergpt_cache.php when this feature is enabled.

dejury/gptfaker 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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