定制 ogrre/laravel-chatgpt 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ogrre/laravel-chatgpt

Composer 安装命令:

composer require ogrre/laravel-chatgpt

包简介

Library to add chat management for openai client

README 文档

README

Packagist Version GitHub License Packagist Downloads

Documentation

This libray need openai php client, so don't forget to add in your .env this variables:

# .env

OPENAI_API_KEY=
OPENAI_API_ORGANIZATION=
OPENAI_MODEL=gpt-4

Installation:

To install the Laravel Chat for ChatGPT library, run the following command:

composer require ogrre/laravel-chatgpt

After the installation, publish the vendor files by executing the command:

php artisan vendor:publish --provider="Ogrre\ChatGPT\ChatServiceProvider"

By default, the service provider will be automatically registered in the app.php file. However, if needed, you can manually add the service provider in the config/app.php file:

# config/app.php

'providers' => [
    // ...
    Ogrre\ChatGPT\ChatServiceProvider,
];

Finally, run the migration command to create the necessary database tables:

php artisan migrate

Usage instructions

To associate a chat with a model, the model must use the hasChat trait. For example, in the User model:

class User extends Authenticatable
{
    use HasFactory, HasChat;
    // ...
}

Once the model is set up with the hasChat trait, you can create a new chat using the following command:

$optional_title = "Translate this word";
$optional_role = "You're a helpful assistant";

$user_chat = $user->newChat($optional_title, $optional_role);

After creating a new chat or retrieving an existing one, you have two options to interact with it:

Using the chat object directly:

$chat->gpt("say hello in French");

Using the model directly (in this example, the User model):

$user->chatgpt("say hello in French", $chat);

The Chat model is a standard Laravel Model, so you can use all the usual functions, including delete and others.

Additionally, the library provides a ChatResource for displaying chats in an API, allowing for easy integration with API endpoints.

Contributing

Contributions are welcome and will be fully credited. I accept contributions via Pull Requests on Github.

Support me

Buy Me A Coffee

ogrre/laravel-chatgpt 适用场景与选型建议

ogrre/laravel-chatgpt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ogrre/laravel-chatgpt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ogrre/laravel-chatgpt 我们能提供哪些服务?
定制开发 / 二次开发

基于 ogrre/laravel-chatgpt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 123
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-26