request->isPost){ $cache = Yii::$app->cache; $type = Yii::$app->request->post('AI'); $text = Yii::$app->request->post('text'); $progress = Yii::$app->request->post('progress'); $key = 'AI_time_mid'.$type.$progress; if( $text && $type == 'ollama' ){ $ses = false; if( \Yii::$app->session->isActive ){ \Yii::$app->session->close(); $ses = true; } $ollama = new OllamaAI(); $r = $ollama->generate(strip_tags($text)); $data = $ollama->Getres(); $t = $ollama->GetTime(); $tm = $cache->get($key); if( $tm ){ $cache->set($key, ($t+$tm)/2); }else{ $cache->set($key, $t); } if( $ses ) \Yii::$app->session->open(); return json_encode( ['status'=>'ok', 'data'=>$data, 'progress'=>$progress] ); }elseif( $text && $type == 'nv' ){ $ses = false; if( \Yii::$app->session->isActive ){ \Yii::$app->session->close(); $ses = true; } $nv = new NvidiaAI(); $r = $nv->generate(strip_tags($text)); if( $r ){ $data = $nv->Getres(); }else{ if( $ses ) \Yii::$app->session->open(); return json_encode( ['status'=>'err', 'msg'=>'Нет доступа до AI '.$type] ); } $t = $nv->GetTime(); $tm = $cache->get($key); if( $tm ){ $cache->set($key, ($t+$tm)/2); }else{ $cache->set($key, $t); } if( $ses ) \Yii::$app->session->open(); return json_encode( ['status'=>'ok', 'data'=>$data, 'progress'=>$progress] ); }else{ return json_encode( ['status'=>'err', 'msg'=>'Нет доступа до AI '.$type] ); } } return json_encode( ['status'=>'err', 'msg'=>'Ошибка получения данных'] ); } public function actionAjaxTime() { $tm = 0; if (Yii::$app->request->isPost){ $cache = Yii::$app->cache; $type = Yii::$app->request->post('AI'); $progress = Yii::$app->request->post('progress'); $key = 'AI_time_mid'.$type.$progress; $tm = $cache->get($key); } return json_encode( ['status'=>'ok', 'time'=>$tm] ); } }