承接 4mesolutions/php-auto-prompt 相关项目开发

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

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

4mesolutions/php-auto-prompt

Composer 安装命令:

composer require 4mesolutions/php-auto-prompt

包简介

PHPAutoPrompt is a PHP class for generating prompts using OpenAI API or Anthropic API.

README 文档

README

The OpenAIPromptDataGenerator is a PHP library designed to generate data examples using AI language models (OpenAI GPT or Anthropic Claude) based on provided configurations and prompts. This tool is useful for creating datasets, testing prompts, and generating diverse examples for various natural language processing tasks.

Table of Contents

  1. Features
  2. Requirements
  3. Installation
  4. Usage
  5. Configuration
  6. Classes Overview
  7. Example

Features

  • Generate examples using OpenAI GPT or Anthropic Claude models
  • Configurable number of examples, model, and output formats
  • Support for single-shot and multi-shot generation
  • Option to diversify generated examples
  • Automatic retrying with exponential backoff for API requests
  • Progress bar to track generation process
  • Output as serialized PHP array or CSV file

Requirements

  • PHP 7.4 or higher
  • Composer (for managing dependencies)
  • OpenAI API key or Anthropic API key

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/OpenAIPromptDataGenerator.git
    
  2. Install dependencies:

    composer install
    
  3. Set up your API key:

    • For OpenAI: Set the OPENAI_API_KEY environment variable
    • For Anthropic: Set the ANTHROPIC_API_KEY environment variable

Usage

  1. Create a configuration array with your desired settings.
  2. Instantiate the Config class with your configuration.
  3. Create an instance of OpenAIPromptDataGenerator using the config.
  4. Call the generateExamples() method to generate your data.

Configuration

The Config class accepts an associative array with the following options:

  • api_key: Your API key (optional if set as an environment variable)
  • prompt: The prompt to use for generation
  • input_function: An array describing the input function and its parameters
  • number_of_examples: Number of examples to generate (default: 5)
  • model_name: The name of the AI model to use (default: 'gpt-3.5-turbo')
  • output_path: Path to save the serialized output (optional)
  • output_csv_path: Path to save the CSV output (optional)
  • single_shot: Whether to use single-shot generation (default: false)
  • diversify: Whether to diversify the generated examples (default: false)
  • expected_param_name: The name of the parameter expected in the output
  • fixed_input: Fixed input to be added to all generated examples (optional)
  • api_type: The type of API to use ('openai' or 'anthropic', default: 'openai')

Classes Overview

  1. OpenAIPromptDataGenerator: The main class that orchestrates the example generation process.
  2. Config: Handles configuration settings for the generator.
  3. APIClient: Manages API interactions with OpenAI or Anthropic, including error handling and retries.
  4. DataProcessor: Prepares messages for API requests and processes the output.
  5. Utilities: Provides utility functions for saving data to files.
  6. Example: Represents a single generated example.
  7. ProgressBar: Displays a progress bar during the generation process.

Example

<?php

require_once 'vendor/autoload.php';

$config = new Config([
    'prompt' => 'Generate a random person's name and age.',
    'input_function' => [
        'name' => 'generate_person',
        'parameters' => [
            'min_age' => 'int',
            'max_age' => 'int',
        ],
    ],
    'number_of_examples' => 10,
    'model_name' => 'gpt-3.5-turbo',
    'output_csv_path' => 'output.csv',
    'expected_param_name' => 'person',
    'api_type' => 'openai',
]);

$generator = new OpenAIPromptDataGenerator($config);
$examples = $generator->generateExamples();

print_r($examples);

This example will generate 10 random person names and ages using the OpenAI GPT-3.5-turbo model and save the results to output.csv.

4mesolutions/php-auto-prompt 适用场景与选型建议

4mesolutions/php-auto-prompt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 4mesolutions/php-auto-prompt 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-01