dragnsurvey/openai
Composer 安装命令:
composer require dragnsurvey/openai
包简介
Laravel Package to interract with OpenAI API
README 文档
README
Description
Laravel OpenAI Package is a Laravel wrapper for the OpenAI API, providing easy integration and usage of OpenAI's capabilities such as GPT-3, DALL-E, and more within Laravel applications. This package simplifies the process of connecting to OpenAI's API and performing various AI-driven tasks.
Features
- Easy integration with Laravel projects.
- Supports various OpenAI API functionalities like Chat, Image Generation, etc.
- Customizable to fit specific use cases.
Requirements
- PHP >= 7.4
- Laravel >= 8.0
- Guzzle HTTP Client
Installation
Install the package via Composer:
composer require dragnsurvey/openai
After installing, publish the configuration file (if needed):
php artisan vendor:publish
--provider="Dragnsurvey\OpenAi\OpenAiServiceProvider"
Configuration
To configure the package, add your OpenAI API key to your .env file:
OPENAI_API_KEY=your_api_key_here
Set other configuration options in config/openai.php (if the
configuration file was published).
Usage
Using Chat API
To use the Chat API:
use Dragnsurvey\OpenAi\Chat\ChatRequest; $chatRequest = new ChatRequest(); $chatRequest->setModel("gpt-4"); $chatRequest->addSystemMessage("You answer questions about football using the tone of a sportscaster "); $chatRequest->addUserMessage("Hello, who won the world cup in 1998?"); $response = $chatRequest->send(); print_r($response);
Using Image Generation API
To use the Image Generation API:
use Dragnsurvey\OpenAi\Image\ImageRequest; $imageRequest = new ImageRequest(); $imageRequest->setPrompt("A two-headed dragon"); $response = $imageRequest->send(); //OR pass the prompt in the constructor $imageRequest = new ImageRequest("A two-headed dragon"); $response = $imageRequest->send(); //change model $imageRequest->setModel('dall-e-3') print_r($response);
Advanced Usage
For advanced usage, refer to OpenAI's official documentation.
Testing
Run the tests with:
vendor/bin/phpunit
Contributing
Contributions are welcome, and any help is greatly appreciated.
License
This package is open-sourced software licensed under the MIT license.
Credits
- Roman STEC (https://www.dragnsurvey.com)
dragnsurvey/openai 适用场景与选型建议
dragnsurvey/openai 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dragnsurvey/openai 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dragnsurvey/openai 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-14