Demo.php
2.2 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
88
89
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/2/7
* Time: 17:58
*/
namespace App\Console\Commands\Test;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Demo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'demo';
/**
* The console command description.
*
* @var string
*/
protected $description = 'demo';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$sql = 'CREATE DATABASE database_name;';
$results = DB::select($sql);
dd($results);
return true;
}
public function printMessage()
{
$client = new Client();
$headers = [
'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/json',
'DNT' => '1',
'Origin' => 'http://openai.waimaoq.com',
'Pragma' => 'no-cache',
'Proxy-Connection' => 'keep-alive',
'Referer' => 'http://openai.waimaoq.com/docs',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
'accept' => 'application/json',
'Access-Control-Allow-Origin' => '*'
];
$body = '{
"prompt": "Human: 我需要一篇100字的英文原创博客并包含标题,内容结合:“cnc machine”。AI:"
}';
$response = $client->post('http://openai.waimaoq.com/v1/openai_chat_stream', [
'stream' => true,
'headers' => $headers,
'body' => $body
]);
// 获取响应流对象
$stream = $response->getBody();
// 设置输出缓冲区
ob_start();
// 读取流中的数据并输出到页面
while (!$stream->eof()) {
echo $stream->read(4);
ob_flush();
flush();
}
dd(1);
}
}