更新星火认知模型分析信息

This commit is contained in:
yaooo 2023-10-14 17:31:38 +08:00
parent 76a52dc9d9
commit 1ef7446e43

View File

@ -26,6 +26,7 @@ class AiAianalyse
{ {
if ($job->attempts() > 3) { if ($job->attempts() > 3) {
//通过这个方法可以检查这个任务已经重试了几次了 //通过这个方法可以检查这个任务已经重试了几次了
$job->delete();
} }
$type_name = Db::name('category_business')->where('id', $data['category_child'])->value('name'); $type_name = Db::name('category_business')->where('id', $data['category_child'])->value('name');
$data_field = json_decode($data['data_field'], true); $data_field = json_decode($data['data_field'], true);
@ -37,7 +38,6 @@ class AiAianalyse
try { try {
$chat=new ChatClient($this->app_id,$this->api_key,$this->api_secret); $chat=new ChatClient($this->app_id,$this->api_key,$this->api_secret);
$client = new Client($chat->assembleAuthUrl('wss://spark-api.xf-yun.com/v2.1/chat')); $client = new Client($chat->assembleAuthUrl('wss://spark-api.xf-yun.com/v2.1/chat'));
// 连接到 WebSocket 服务器
if ($client) { if ($client) {
$header = [ $header = [
"app_id" => $this->app_id, "app_id" => $this->app_id,
@ -69,14 +69,13 @@ class AiAianalyse
$response = $client->receive(); $response = $client->receive();
$resp = json_decode($response, true); $resp = json_decode($response, true);
$code = $resp["header"]["code"] ?? 0; $code = $resp["header"]["code"] ?? 0;
if($code == 0){ if($code > 0){
$status = $resp["header"]["status"]; break;
$content = $resp['payload']['choices']['text'][0]['content'] ?? ''; }
$answer .= $content; $status = $resp["header"]["status"];
if($status == 2){ $content = $resp['payload']['choices']['text'][0]['content'] ?? '';
break; $answer .= $content;
} if($status == 2){
}else{
break; break;
} }
} }
@ -85,7 +84,7 @@ class AiAianalyse
'update_time' => time(), 'update_time' => time(),
]; ];
unset($data['data'], $data['data_field']); unset($data['data'], $data['data_field']);
Db::name('user_informationg_demand')->where($data)->fetchSql(false)->update($update_data); Db::name('user_informationg_demand')->where($data)->update($update_data);
} }
} catch (\Exception $e) {} } catch (\Exception $e) {}
$job->delete(); $job->delete();