在laravel框架中用ChatGPT生成代码的扩展包推荐:laravel-synth
Laravel  /  管理员 发布于 1年前   713
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查看源码及说明文档
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号