AntonLV 2 лет назад
Родитель
Сommit
2e2857382d
2 измененных файлов с 19 добавлено и 19 удалено
  1. 12 5
      inc/classes/BxDolAIModelGpt35.php
  2. 7 14
      studio/classes/BxDolStudioAgentsAutomatorsCmts.php

+ 12 - 5
inc/classes/BxDolAIModelGpt35.php

@@ -24,21 +24,28 @@ class BxDolAIModelGpt35 extends BxDolAIModel
         $this->_sPathInst = BX_DIRECTORY_PATH_ROOT . 'ai/instructions/';
     }
 
-    public function getResponse($sType, $sMessage, $bInit = false)
+    public function getResponse($sType, $mixedMessage, $bInit = false)
     {
         $aMessages = [];
 
         if($bInit)
             $aMessages = [
-                ['role' => 'system', 'content' => $this->_getInstructions($sType . '_init')],
-                ['role' => 'user', 'content' => $sMessage]
+                ['role' => 'system', 'content' => $this->_getInstructions($sType . '_init')]
             ];
         else
             $aMessages = [
-                ['role' => 'system', 'content' => $this->_getInstructions($sType, true)],
-                ['role' => 'user', 'content' => $sMessage]
+                ['role' => 'system', 'content' => $this->_getInstructions($sType, true)]
             ];
         
+        if(is_array($mixedMessage)) {
+            foreach($mixedMessage as $aMessage)
+                $aMessages[] = [
+                    'role' => $aMessage['ai'] ? 'assistant' : 'user',
+                    'content' => $aMessage['content'] . (!$aMessage['ai'] ? ' return only function, without explanation or false if you havn`t enougth data' : '')
+                ];
+        }
+        else
+            $aMessages[] = ['role' => 'user', 'content' => $mixedMessage];
 
         $sResponse = $this->call($aMessages);
         if($sResponse == 'false')

+ 7 - 14
studio/classes/BxDolStudioAgentsAutomatorsCmts.php

@@ -178,30 +178,23 @@ class BxDolStudioAgentsAutomatorsCmts extends BxTemplCmts
         $mixedResult = parent::onPostAfter($iCmtId, $aDp);
         if($this->_bAuto || $mixedResult === false) 
             return $mixedResult;
-        
+
         $iObjId = (int)$this->getId();
-        
         $aAutomator = $this->_oAI->getAutomator($iObjId, true);
 
-        $aMessages = [
-            ['role' => 'system', 'content' => $this->_oAI->getAutomatorInstructions($aAutomator['type'], true)],
-        ];
-
         $aComments = $this->_oQuery->getCommentsBy(['type' => 'object_id', 'object_id' => $iObjId]);
         if($aAutomator['type'] == BX_DOL_AI_AUTOMATOR_EVENT && !empty($aAutomator['params']['trigger']))
             $aComments[0]['cmt_text'] .= $aAutomator['params']['trigger'];
 
-        foreach($aComments as $aComment) {
-            $bAuthorAi = (int)$aComment['cmt_author_id'] == $this->_iProfileIdAi;
-
+        $aMessages = [];
+        foreach($aComments as $aComment)
             $aMessages[] = [
-                'role' => $bAuthorAi ? 'assistant' : 'user',
-                'content' => $aComment['cmt_text'] . ($bAuthorAi ? '' : ' return only function, without explanation or false if you havn`t enougth data')
+                'ai' => (int)$aComment['cmt_author_id'] == $this->_iProfileIdAi,
+                'content' => $aComment['cmt_text']
             ];
-        }
 
-        $sResponse = $this->_oAI->chat($aAutomator['model_url'], $aAutomator['model_model'], $aAutomator['model_key'], $aAutomator['model_params'], $aMessages);
-        if($sResponse != 'false') {
+        $oAIModel = $this->_oAI->getModel($aAutomator['model_id']);
+        if(($sResponse = $oAIModel->getResponse($aAutomator['type'], $aMessages)) !== false) {
             $mixedResultAuto = $this->addAuto([
                 'cmt_author_id' => $this->_iProfileIdAi,
                 'cmt_parent_id' => 0,