thojou/prompt-template
Composer 安装命令:
composer require thojou/prompt-template
包简介
PHP library for creating AI interaction prompts.
README 文档
README
The PHP Prompt Template is a library designed to simplify dynamic text generation in AI projects. This library empowers you to effortlessly incorporate placeholders into your text and render them with dynamic values. Thanks to yethee/tiktoken-php, this library also provides a straightforward way to count and retrieve the tokens of a prompt.
Requirements
- PHP version >= 8.1
Installation
You can effortlessly install the PHP Prompt Template using the popular package manager composer.
composer require thojou/php-prompt-template
Usage
<?php require_once __DIR__ . '/vendor/autoload.php'; use Thojou\PromptTemplate\Prompt; use Thojou\PromptTemplate\PromptTemplate; // Create a new prompt $prompt = new Prompt('Hello World!'); // Render a prompt template $template = new PromptTemplate('Hello {{name}}!'); $renderedPrompt = $template->render(['name' => 'Alice']); echo $prompt; // Outputs: "Hello World!" echo $renderedPrompt; // Outputs: "Hello Alice!" echo $prompt->getTokenCount('gpt-3.5-turbo'); // Outputs: 3 echo join(', ', $prompt->getTokens('gpt-3.5-turbo')); // Outputs: 15496, 2159, 0
For more practical examples, please refer to the examples folder.
License
This project is licensed under the generous and permissive MIT license.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-20