diff --git a/app/Pusher.php b/app/Pusher.php index e892da4..b0a06dc 100644 --- a/app/Pusher.php +++ b/app/Pusher.php @@ -30,6 +30,10 @@ class Pusher public function onMessage(TcpConnection $connection, $data) { + $data=json_decode($data,true); + if(isset($data[0])&&$data[0]['content']==''){ + return $connection->send(['header'=>['code'=>10003,'message'=>'消息不能为空']]); + } if ($data != '') { $client = new Client($this->assembleAuthUrl('wss://spark-api.xf-yun.com/v2.1/chat')); // 连接到 WebSocket 服务器 @@ -60,6 +64,9 @@ class Pusher break; } } + if($code==10004){ + return $connection->send(['header'=>['code'=>10004,'message'=>'上下文超出限制,请清空后重试']]); + } } } } @@ -84,15 +91,13 @@ class Pusher "chat" => array( "domain" => "generalv2", "temperature" => 0.5, - "max_tokens" => 1024 + "max_tokens" => 8192 ) ); $payload = array( "message" => array( - "text" => array( - array("role" => "user", "content" => $question) - ) + "text" => $question ) );