在laravel框架中用ChatGPT生成代码的扩展包推荐:laravel-synth
Laravel  /  管理员 发布于 2个月前   177
Laravel的Synth软件包可以帮助你在Laravel应用程序中生成代码并执行各种任务。
它利用OpenAI的GPT语言模型的力量来提供一个互动和智能的开发体验。
git:
https://github.com/blinq-dev/laravel-synth
这个包的工作原理是启动artisan synth命令,然后让你与ChatGPT互动工作,并运行任务。
根据readme,Synth的主要功能包括以下内容:
需要时自动从小模型切换到大模型(gpt-3.5-turbo vs gpt-3.5-turbo-16k)
使用OpenAI的函数API
用Ctrl+C取消生成
附件: 用GPT将文件附在对话中。
架构师: 集思广益,生成一个新的应用架构。
聊天: 与GPT聊天以获得回应和执行行动。
制作:强迫GPT为所问问题生成文件。
迁移: 为你的应用程序生成迁移。
模型: 为你的应用程序生成模型。
文件: 向文件系统中写入文件。
你还可以使用包中提供的接口创建自定义模块来扩展Synth。
编写你自己的模块
Synth允许你通过编写自己的模块来扩展其功能。
一个模块是一个实现必要方法的类,用来注册和处理特定的动作。
要创建一个新的模块,请遵循以下步骤:
创建一个新的PHP类,并扩展模块类。
实现name方法来定义你的模块的名称。
实现register方法来定义你的模块所提供的动作。
实现onSelect方法来处理选定的动作。
安装
使用Composer安装Synth软件包:
composer require blinq/synth
发布 Synth 配置文件:
php artisan vendor:publish --tag=synth-config
在.env文件中设置你的OpenAI API密钥:
openai_key=your_api_key
下面是一个实现自定义模块的例子:
use Blinq\Synth\Modules\Module;
/**
* Class MyModule
*
* @propery \Blinq\Synth\Commands\SynthCommand $cmd
*/
class MyModule extends Module
{
public function name(): string
{
return 'MyModule';
}
public function register(): arraya
{
return [
'action1' => 'Perform Action 1',
'action2' => 'Perform Action 2',
];
}
public function onSelect(?string $key = null)
{
$this->cmd->info("You selected: {$key}");
$synth = $this->cmd->synth;
if ($key === 'action1') {
// Handle Action 1
while (true) {
$input = $this->cmd->ask("You");
// Send the input to GPT
$synth->chat($input, [
// ... The OpenAI Chat options
// If you want a function to be called by GPT
'function_call' => ['name' => 'some_function'], // Forces the function call
'functions' => [
[
'name' => 'some_function',
'description' => 'Description of the function',
'parameters' => [
// ..schema
]
]
]
]);
Functions::register('some_function', function (SynthCommand $cmd, $args, $asSpecified, $inSchema) { // etc..
// Do something with the call
});
// This will parse the json result and call the function if needed
$synth->handleFunctionsForLastMessage();
// Just retrieve the last message
$lastMessage = $synth->getLastMessage();
// Echo it's contents
echo $lastMessage->content;
// Or it's raw function_call
dump($lastMessage->function_call);
if (!$input || $input == 'exit') {
break;
}
}
}
if ($key === 'action2') {
// Handle Action 2
}
}
}
然后你可以在Synth包内的Modules类中注册你的自定义模块,并在CLI界面中使用它:
use Blinq\Synth\Modules;
Modules::register(MyModule::class);
了解更多关于synth包的知识,请自行上github查看源码及说明文档
路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..博主 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 @ mashrdn 多切换几个节点测试,免费ssr是没那么稳..mashrdn 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 V2rayn免费节点添加上去了,youtobe无法打开网页,是怎么回事..张伟 在
科学上网翻墙之v2rayN-Core客户端免费公益节点使用教程中评论 3q!有用,不过免费节点隔天就要去git上复制新的导进去..博主 在
科学上网翻墙访问Google , 上外网神器佛跳墙VPN(永久免费)使用流程步骤中评论 该篇教程已不能用了,告知大家,免的老有老铁问我!..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号