amic 2 mēneši atpakaļ
vecāks
revīzija
5e8ce25fac

+ 3 - 3
models/NvidiaAI.php

@@ -21,16 +21,16 @@ class NvidiaAI extends \app\models\base\BaseAI
 		$this->SetHeader($header);
 	}
 
-	public function generate( $promt, $context = '' ){
+	public function generate( $promt, $context = '', $tokens = 0 ){
 		$url = $this->host.self::$urlgen;
-
+		$tokens = ( $tokens == 0 )?1024:$tokens;
 		$cmd = array(
 			"model" => $this->model,
 			"messages" =>array(array("role"=>"user", "content"=>$promt)),
 			"stream" => false,
 			"temperature" => 0.2,
 			"top_p" => 0.7,
-			"max_tokens" => 1024,
+			"max_tokens" => $tokens,
 		);
 		if( $context ){
 //			$cmd['context'] = $context;

+ 2 - 1
modules/manager/controllers/AiController.php

@@ -18,6 +18,7 @@ class AiController extends BaseController
 			$cache = Yii::$app->cache;
 			$type = Yii::$app->request->post('AI');
 			$text = Yii::$app->request->post('text');
+			$tokens = Yii::$app->request->post('tokens');
 			$progress = Yii::$app->request->post('progress');
 			$key = 'AI_time_mid'.$type.$progress;
 
@@ -46,7 +47,7 @@ class AiController extends BaseController
 					$ses = true;
 				}
 				$nv = new NvidiaAI();
-				$r = $nv->generate(strip_tags($text));
+				$r = $nv->generate(strip_tags($text), '', $tokens);
 				if( $r ){
 					$data = $nv->Getres();
 				}else{

+ 7 - 1
modules/manager/views/default/formNews.php

@@ -281,6 +281,10 @@ echo $form->field($news, 'title')->textInput([
 	<label class="control-label" for="news-lid">Новость кратко</label> <span class="badge badge-info" id="lid_count"></span>
 	<textarea id="news-lid" class="form-control js-word-count-input" name="News[lid]" placeholder="Лид" aria-required="true"><?=$news->lid?></textarea>
 	<div class="help-block">Краткое содержание статьи</div>
+	<span type="button" class="btn btn-outline-primary btn-block btn-sm aiget" style="width: fit-content;" id="ailid" data-pb="saiprogressx1" data-max_tokens="1000" data-preprompt="Напиши очень коротко discription для статьи менбше 200 символов несколько вариантов" title="Сгенерировать нейросетью, время гениратции примерно <?=round($AI_time_mid)?>сек."><i class="fa fa-robot"></i> Гена</span>
+		<div class="progress progress-sm active hidden" id="saiprogress">
+			<div class="progress-bar bg-success progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%" id="saiprogressx1"><span class="sr-only">40</span></div>
+		</div>
 </div>
 <div class="form-group">
 	<label class="control-label" for="news-link">Прямой переход на URL</label>
@@ -943,6 +947,8 @@ $(function() {
 		window.robotr = true;
 		let text = CKEDITOR.instances.js_news_content.getData();
 		let preprompt = $(this).data('preprompt');
+		let max_tokens = $(this).data('max_tokens');
+		if( !max_tokens ) max_tokens = 0;
 		text = preprompt+': '+text;
 		let pbar = '#'+$(this).data('pb');
 		$(pbar).parent().removeClass('hidden');
@@ -959,7 +965,7 @@ $(function() {
 		}, "json");
 
 		data.timer = setInterval(countprogress, 1000, pbar, data);
-		$.post("/manager/ai/ajax-get-title", {AI:'nv',text:text, progress: pbar}, function( data ) {
+		$.post("/manager/ai/ajax-get-title", {AI:'nv',text:text, progress: pbar, tokens: max_tokens}, function( data ) {
 			if( data.status == 'ok' ){
 				var data_all = data.data;
 				$("#AItext").html(data_all);