ToolsController.php
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 控制层: 智能门锁消息通知 控制类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Http\Api\V1\Controllers
* @package App\Http\Api\V1\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2021年1月30日09:20:18
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Http\Api\V1\Controllers;
use Tectalic\OpenAi\Authentication;
use Tectalic\OpenAi\Manager;
/**
* Class NoticeLocksController.
*
* @category App\Http\Api\V1\Controllers
* @package App\Http\Api\V1\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2021年1月30日09:20:18
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class ToolsController extends BaseController
{
public function test1()
{
$text = request()->input('text');
$open_api_key = config('openai.api_key') ;// '你的Open Ai key';
$openaiClient = Manager::build(
new \GuzzleHttp\Client([
// 'proxy' => 'http://127.0.0.1:10809',
'verify' =>false
]),
new Authentication($open_api_key)
);
// dd($openaiClient);
// $response = $openaiClient->models()->list();
// dd($response->toArray());
// https://open2.aiproxy.xyz/
/** @var \Tectalic\OpenAi\Models\Completions\CreateResponse $response */
$response = $openaiClient->completions()->create(
new \Tectalic\OpenAi\Models\Completions\CreateRequest([
'model' => 'text-davinci-003',
// 'model' => 'gpt-4',
'prompt' => $text, // 设置问题
'max_tokens' => 2000, // 设置答案长度 不设置只显示部分字符
])
)->toModel();
// dump(json_encode($response));
// $response = $openaiClient->completions()->create(
// new \Tectalic\OpenAi\Models\Completions\CreateRequest([
// 'model' => 'gpt-4',
// 'messages' => [
// [
// 'role' => 'user',
// 'content' => $text,
// ],
// ],
// ])
// )->toModel();
print_r($response->choices[0]->text);die;
}
public function express()
{
$model= Express::find(request('id'));
$this->syncExpress($model);
dd(1);
}
}