hesamrad/laravel-chatgpt
最新稳定版本:v1.0.0
Composer 安装命令:
composer require hesamrad/laravel-chatgpt
包简介
A lightweight library to integrate chatGpt into your Laravel application!
README 文档
README
Laravel ChatGPT
Bring ChatGPT to your Laravel application with a few simple steps!
How to install it?
Take these steps to install ChatGPT.
Step #1
Install the package using Composer.
composer require hesamrad/laravel-chatgpt
Step #2
Publish congifuration file.
php artisan vendor:publish --provider="HesamRad\LaravelChatGpt\LaravelChatGptServiceProvider" --tag="chatgpt-config"
Step #3
Generate an API key inside your OpenAI account, and copy it into your .env file. (Generate your own API key.)
CHATGPT_API_KEY="xx-xxxx"
And that's it! You now have ChatGPT inside your application.
How to use it?
It really is up to you! You could use the built-in routes to ask your questions, or even use the global helper function inside your controllers to do the job.
Method #1 - Using built-in routes.
The package comes with a built-in route so you can send a request from anywhere inside your client application; whether it's a separate JavaScript-powered front-end, or anything else.
Simply send a POST request to /api/chatgpt/ask with a body parameter question to get your answer.
Note that you could easily change this route to whatever you want! You could do so by editing the internal_api_route key inside chatgpt.php config file under app/config.
// This is the chatgpt.php config file. -> (app/config/chatgpt.php) 'internal_api_route' => '/api/chatgpt/ask'
Method #2 - Using global helper function.
There is a chatgpt() global helper function which takes one parameter as the question you want to ask. You could use this method anywhere you like.
If you want to use this package inside any controller you could go about it like this:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Controllers\Controller; class ImaginaryController extends Controller { /** * This method connects to ChatGPT servers * and asks the given question. * * @param \Illuminate\Http\Response $request * @return \Illuminate\Http\Response */ public function ImaginaryMethod(Request $request) { $answer = chatgpt($request->input('question')); return response($answer, Response::HTTP_OK); } }
Method #3 - Using ChatGPT Facade.
If you prefer the facade's readability, I got you covered. You could do the exact same thing you were doing in previous method with the available facade; but there is literally NO difference between the two.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Controllers\Controller; use HesamRad\LaravelChatGpt\ChatGptFacade as ChatGpt; class ImaginaryController extends Controller { /** * This method connects to ChatGPT servers * and asks the given question. * * @param \Illuminate\Http\Response $request * @return \Illuminate\Http\Response */ public function ImaginaryMethod(Request $request) { $answer = chatgpt($request->input('question')); return response($answer, Response::HTTP_OK); } }
hesamrad/laravel-chatgpt 适用场景与选型建议
hesamrad/laravel-chatgpt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.25k 次下载、GitHub Stars 达 7, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「ChatGpt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hesamrad/laravel-chatgpt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hesamrad/laravel-chatgpt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hesamrad/laravel-chatgpt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
OpenAI 应用 ChatGPT
T3AI – TYPO3 AI Integration Extension
AI-powered helper for PHP errors, warnings and exceptions: practical, context-aware explanations and suggestions via local or API LLMs.
A library for interacting with ChatGPT and Claude AI
Alfabank REST API integration
Drop-in AI chatbox widget for Laravel with RAG, streaming, Vue 3 frontend, and support for Ollama, OpenAI, Groq, and any OpenAI-compatible API.
统计信息
- 总下载量: 20.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知
