|
@@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log; |
|
@@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log; |
|
14
|
*/
|
14
|
*/
|
|
15
|
class Gpt
|
15
|
class Gpt
|
|
16
|
{
|
16
|
{
|
|
17
|
- public $api = 'http://openai.waimaoq.com/';
|
17
|
+ /**
|
|
|
|
18
|
+ * 头
|
|
|
|
19
|
+ * @var string[]
|
|
|
|
20
|
+ */
|
|
|
|
21
|
+ public $header = [
|
|
|
|
22
|
+ 'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
|
|
|
|
23
|
+ 'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
|
|
|
|
24
|
+ ];
|
|
18
|
|
25
|
|
|
19
|
- public $header = [];
|
26
|
+ /**
|
|
|
|
27
|
+ * 请求域名
|
|
|
|
28
|
+ * @var string
|
|
|
|
29
|
+ */
|
|
|
|
30
|
+ public $api = 'https://api.cmer.com';
|
|
20
|
|
31
|
|
|
21
|
private static $instance;
|
32
|
private static $instance;
|
|
22
|
|
33
|
|
|
@@ -35,7 +46,7 @@ class Gpt |
|
@@ -35,7 +46,7 @@ class Gpt |
|
35
|
*/
|
46
|
*/
|
|
36
|
public function openai_chat_qqs($content, $system_content = '')
|
47
|
public function openai_chat_qqs($content, $system_content = '')
|
|
37
|
{
|
48
|
{
|
|
38
|
- $url = $this->api . 'v2/openai_chat_qqs';
|
49
|
+ $url = $this->api . '/v1/openai_chat';
|
|
39
|
|
50
|
|
|
40
|
$data = [
|
51
|
$data = [
|
|
41
|
'messages' => [],
|
52
|
'messages' => [],
|
|
@@ -57,9 +68,10 @@ class Gpt |
|
@@ -57,9 +68,10 @@ class Gpt |
|
57
|
->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
|
68
|
->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
|
|
58
|
->post($url);
|
69
|
->post($url);
|
|
59
|
$json = $result->json();
|
70
|
$json = $result->json();
|
|
60
|
- if (!isset($json['text'])) {
|
71
|
+ if (!isset($json['text']) || $json['code'] !==200) {
|
|
61
|
Log::error('openai_chat_qqs data:', $data);
|
72
|
Log::error('openai_chat_qqs data:', $data);
|
|
62
|
Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
|
73
|
Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
|
|
|
|
74
|
+ $json = [];
|
|
63
|
}
|
75
|
}
|
|
64
|
} catch (\Throwable $e) {
|
76
|
} catch (\Throwable $e) {
|
|
65
|
Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
|
77
|
Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
|