作者 赵彬吉

update

@@ -143,7 +143,7 @@ class UpdateSeoTdk extends Command @@ -143,7 +143,7 @@ class UpdateSeoTdk extends Command
143 $this->seo_tdk($project_id); 143 $this->seo_tdk($project_id);
144 DB::disconnect('custom_mysql'); 144 DB::disconnect('custom_mysql');
145 }catch (\Exception $e){ 145 }catch (\Exception $e){
146 - echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 146 + echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
147 } 147 }
148 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 148 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
149 } 149 }
@@ -366,6 +366,7 @@ class UpdateSeoTdk extends Command @@ -366,6 +366,7 @@ class UpdateSeoTdk extends Command
366 public function ai_send($prompt) 366 public function ai_send($prompt)
367 { 367 {
368 $text = Gpt::instance()->openai_chat_qqs($prompt); 368 $text = Gpt::instance()->openai_chat_qqs($prompt);
  369 + echo 'GPT result:' . $text . PHP_EOL;
369 $text = Common::deal_keywords($text); 370 $text = Common::deal_keywords($text);
370 return Common::deal_str($text); 371 return Common::deal_str($text);
371 } 372 }
@@ -74,7 +74,7 @@ class Common @@ -74,7 +74,7 @@ class Common
74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) { 74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
75 $lang = Translate::$tls_list[$result['texts']['sl']]['text']; 75 $lang = Translate::$tls_list[$result['texts']['sl']]['text'];
76 } else { 76 } else {
77 - $lang = 'Chinese'; 77 + $lang = 'English';
78 } 78 }
79 } 79 }
80 $str = 'Please answer in '.$lang; 80 $str = 'Please answer in '.$lang;
@@ -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());