lanos/laravel-open-ai-conversations
Composer 安装命令:
composer require lanos/laravel-open-ai-conversations
包简介
Adds persistent conversation functionality to the existing Laravel OpenAI Package
README 文档
README
Laravel GPT Conversations
Intro
This package is built on top of the openai-php/laravel package to allow you to build conversation sessions where context is preserved using a database.
This package is just an extra layer on top of the amazing package developed by:
- Nuno Maduro: github.com/sponsors/nunomaduro
- Sandro Gehri: github.com/sponsors/gehrisandro
The openai-php/laravel is required and should be installed as part of this install.
Setup
Requires PHP 8.1+
Really simple. Install our package (if you don't have the openai-php/laravel installed, composer should try to install it)
composer require lanos/laravel-open-ai-conversations
Then you need to just run the migrations
php artisan migrate
If you haven't set up the OpenAI-PHP Laravel package you can publish their config like so:
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
Then add the environment variables as needed.
OPENAI_API_KEY=sk-...
You can also override some of the default config variables in the .env for my plugin, such as setting the default model for a conversation.
OPENAI_DEFAULT_MODEL=gpt-4-32k OPENAI_TOKEN_LIMIT=4096
Examples
Once you have fully configured both plugins you simply create a conversation using the eloquent interface.
The defaults are filled in for you, but you can override upon creation.
Once you have created the conversation you can ask questions. The plugin will automatically append all previous responses so that the model has consciousness of previous messages in the conversation. It also automatically ensures no token limits are hit by "forgetting" older messages as needed.
<?php
// CREATES THE CONVERSATION
$conversation = Conversation::create();
// ASK A NEW QUESTION
$capitalCity = $conversation->askQuestion('What is the capital city of England?');
// ASK A FOLLOW UP QUESTION
$population = $conversation->askQuestion('And what is the population of that city?');
// GETS ALL OF THE QUESTIONS AND ANSWERS UP UNTIL NOW
$messages = $conversation->messages()->get();
Forgotten messages
Due to token limits, when necessary the plugin will soft delete older messages, similar to how chat GPT does it. The difference is with this, it will do it less often, as the token limits are higher on the API depending on what model you use. Be wary that requests can become expensive.
You can use the withTrashed function on eloquent to get all the forgotten messages.
// GETS ALL OF THE QUESTIONS AND ANSWERS UP UNTIL NOW INCLUJDING FOROGTTEN ONES
$messages = $conversation->messages()->withTrashed()->get();
// GETS ONLY FORGOTTEN MESSAGES
$messages = $conversation->messages()->onlyTrashed()->get();
License
Please refer to the license.md in this repository.
lanos/laravel-open-ai-conversations 适用场景与选型建议
lanos/laravel-open-ai-conversations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「conversations」 「openai」 「gpt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lanos/laravel-open-ai-conversations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lanos/laravel-open-ai-conversations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lanos/laravel-open-ai-conversations 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Talk is a Laravel based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.
Talk is a Laravel 5 based realtime messaging, chatting and conversation system. It helps to develop users messaging, chatting and conversations in easy way.
PHP 8.0+ OpenAI API client with fully typed/documented requests+responses models, guzzle and symfony/http-client support and async/parallel requests.
Laravel 5 user groups package originally by musonza/groups. I fork it and made some upgrades in the code & mold it according to my project needs.
A Laravel package for storing and managing AI conversation history in your applications
Laravel 5 user groups package
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-22