sonichaos360/lugpt
Composer 安装命令:
composer create-project sonichaos360/lugpt
包简介
A PHP library for interacting with OpenAI's Completions and ChatCompletions API.
关键字:
README 文档
README
A PHP library for interacting with OpenAI's Completions and ChatCompletions API.
Table of Contents
Installation
Install the library using Composer:
composer require sonichaos360/lugpt
Usage
Initialization
Initialize the LuGPT class with your OpenAI API key:
require_once 'vendor/autoload.php'; use Sonichaos360\LuGPT\Completions; $apiKey = 'your_openai_api_key'; $model = 'gpt-3.5-turbo'; $maxTokens = '1500'; $temp = '1'; $conversationsPath = '../conversations'; //Optional, necessary only if you will manage conversation history using createConversation() $luGPT = new Completions($apiKey, $model, $maxTokens, $temp, $conversationsPath);
In this example, we are using the gpt-3.5-turbo model, which is optimized for chat. The chat-optimized models can be used with the chat() method. If you want to use the completion() method, you will need to use text-davinci-003 or another non-chat-optimized model. A list of all available OpenAI models can be found here.
Chat
Send a message using Chat Completions API:
$systemMessage = 'You are an assistant that translates English to French.'; $userMessage = 'Translate the following sentence: "Hello, how are you?"'; $response = $luGPT->Chat($systemMessage, $userMessage); echo $response['choices'][0]['message']['content'];
Conversations
Create and manage conversations:
// Create a new conversation $conversationId = $luGPT->createConversation(); // Send messages within the conversation $systemMessage = 'You are an assistant that translates between any languages.'; $userMessage1 = 'Translate the following sentence from English to French: "Hello, how are you?"'; $response1 = $luGPT->Chat($systemMessage, $userMessage1, $conversationId); echo $response1['choices'][0]['message']['content']." | "; $userMessage2 = 'Now, please translate this: "I am fine, thank you."'; $response2 = $luGPT->Chat($systemMessage, $userMessage2, $conversationId); echo $response2['choices'][0]['message']['content']." | ";
This example uses a conversationId, which allows the API to remember the context of previous messages and responses. The conversations will be created as separate JSON files stored in the $conversationsPath directory.
Completion
Send a prompt to the text-davinci-003 or other non chat completions optimized model:
$prompt = 'Translate the following English sentence to French: "Hello, how are you?"'; $response = $luGPT->Completion($prompt); echo $response["choices"][0]["text"];
TODO
Here are some upcoming features and improvements we have planned for the LuGPT library. We encourage contributors to take on these tasks or suggest new ones by creating issues on GitHub:
- Refactor the
saveTokens()function, which was deactivated due to strange behavior with non-English language characters. - Improve error handling and provide more informative error messages.
- Implement unit tests for the library to ensure code quality and functionality.
Please consider contributing to the development of these features or suggesting new ones by creating an issue or submitting a pull request. Your input and collaboration are greatly appreciated.
Issues
If you encounter any problems or have suggestions for improvements, we welcome you to create an issue on GitHub. To do so, please follow these steps:
- Navigate to the Issues section of the LuGPT repository.
- Click on the "New issue" button.
- Provide a clear and descriptive title for the issue.
- In the description, include as much detail as possible, such as:
- A summary of the problem or suggestion.
- Steps to reproduce the issue, if applicable.
- The expected behavior and the actual behavior.
- Any error messages or logs, if available.
- The PHP version and operating system you are using.
- Attach any relevant screenshots or code snippets, if necessary.
When creating an issue, please keep the following recommendations in mind:
- Make sure to search the existing issues before submitting a new one, to avoid duplicates.
- Be respectful and courteous to other users and maintain a constructive discussion.
- Stay on topic and keep the conversation relevant to the issue at hand.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes.
- Submit a pull request.
License
This library is released under the MIT License.
sonichaos360/lugpt 适用场景与选型建议
sonichaos360/lugpt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ai」 「chatbot」 「openai」 「gpt」 「gpt-3.5-turbo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sonichaos360/lugpt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sonichaos360/lugpt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sonichaos360/lugpt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP 8.0+ OpenAI API client with fully typed/documented requests+responses models, guzzle and symfony/http-client support and async/parallel requests.
AI-powered helper for PHP errors, warnings and exceptions: practical, context-aware explanations and suggestions via local or API LLMs.
Magento MCP AI Assistant - A powerful AI assistant for Magento 2 that helps with store data queries and management
Estimate AI API costs before making expensive calls
A powerful package that seamlessly integrates OpenAI's advanced AI capabilities into your Laravel applications. This package offers quick setup and intuitive configuration to leverage AI models for chat, embeddings, and more.
AI discussion summaries for Flarum with real-time streaming.
统计信息
- 总下载量: 56
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-07