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
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
-
Clone the repository:
git clone https://github.com/yourusername/OpenAIPromptDataGenerator.git -
Install dependencies:
composer install -
Set up your API key:
- For OpenAI: Set the
OPENAI_API_KEYenvironment variable - For Anthropic: Set the
ANTHROPIC_API_KEYenvironment variable
- For OpenAI: Set the
Usage
- Create a configuration array with your desired settings.
- Instantiate the
Configclass with your configuration. - Create an instance of
OpenAIPromptDataGeneratorusing the config. - 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 generationinput_function: An array describing the input function and its parametersnumber_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 outputfixed_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
OpenAIPromptDataGenerator: The main class that orchestrates the example generation process.Config: Handles configuration settings for the generator.APIClient: Manages API interactions with OpenAI or Anthropic, including error handling and retries.DataProcessor: Prepares messages for API requests and processes the output.Utilities: Provides utility functions for saving data to files.Example: Represents a single generated example.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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-01