diff --git a/ProcessMaker/Ai/Handlers/LanguageTranslationHandler.php b/ProcessMaker/Ai/Handlers/LanguageTranslationHandler.php index fda05562ff..b8a0571fa0 100644 --- a/ProcessMaker/Ai/Handlers/LanguageTranslationHandler.php +++ b/ProcessMaker/Ai/Handlers/LanguageTranslationHandler.php @@ -18,8 +18,8 @@ public function __construct() { parent::__construct(); $this->config = [ - 'model' => 'text-davinci-003', - 'max_tokens' => 2200, + 'model' => 'gpt-3.5-turbo-16k', + 'max_tokens' => 6000, 'temperature' => 0, 'top_p' => 1, 'n' => 1, @@ -52,6 +52,10 @@ public function generatePrompt(String $type = null, String $json_list) : Object $prompt = $this->replaceLanguage($prompt, $this->targetLanguage['humanLanguage']); $prompt = $this->replaceStopSequence($prompt); $this->config['prompt'] = $prompt; + $this->config['messages'] = [[ + 'role' => 'user', + 'content' => $prompt, + ]]; return $this; } @@ -61,17 +65,25 @@ public function execute() $listCharCount = strlen($this->json_list); $totalChars = $listCharCount * 3; $currentChunkCount = 0; + $config = $this->getConfig(); + unset($config['prompt']); $client = app(Client::class); $stream = $client - ->completions() - ->createStreamed(array_merge($this->getConfig())); + ->chat() + ->createStreamed(array_merge($config)); $fullResponse = ''; foreach ($stream as $response) { - $currentChunkCount += strlen($response->choices[0]->text); - self::sendResponse($response->choices[0]->text, $currentChunkCount, $totalChars); - $fullResponse .= $response->choices[0]->text; + if (array_key_exists('content', $response->choices[0]->toArray()['delta'])) { + $currentChunkCount += strlen($response->choices[0]->toArray()['delta']['content']); + self::sendResponse( + $response->choices[0]->toArray()['delta']['content'], + $currentChunkCount, + $totalChars + ); + $fullResponse .= $response->choices[0]->toArray()['delta']['content']; + } } return $this->formatResponse($fullResponse); diff --git a/ProcessMaker/Ai/Handlers/NlqToCategoryHandler.php b/ProcessMaker/Ai/Handlers/NlqToCategoryHandler.php index c89c17d1dd..54130e07fe 100644 --- a/ProcessMaker/Ai/Handlers/NlqToCategoryHandler.php +++ b/ProcessMaker/Ai/Handlers/NlqToCategoryHandler.php @@ -10,7 +10,7 @@ public function __construct() { parent::__construct(); $this->config = [ - 'model' => 'text-davinci-003', + 'model' => 'gpt-3.5-turbo', 'max_tokens' => 20, 'temperature' => 0, 'top_p' => 1, @@ -34,7 +34,10 @@ public function generatePrompt(String $type = null, String $question) : Object $prompt = $this->replaceStopSequence($prompt); $prompt = $this->replaceDefaultType($prompt, $type); - $this->config['prompt'] = $prompt; + $this->config['messages'] = [[ + 'role' => 'user', + 'content' => $prompt, + ]]; return $this; } @@ -43,15 +46,18 @@ public function execute() { $client = app(Client::class); $response = $client - ->completions() - ->create(array_merge($this->getConfig())); + ->chat() + ->create( + array_merge($this->getConfig() + ) + ); return $this->formatResponse($response); } private function formatResponse($response) { - $result = ltrim($response->choices[0]->text); + $result = ltrim($response->choices[0]->message->content); return [strtolower($result), $response->usage, $this->question]; } diff --git a/ProcessMaker/Ai/Handlers/NlqToPmqlHandler.php b/ProcessMaker/Ai/Handlers/NlqToPmqlHandler.php index 81d43b4dc3..c2eae050f4 100644 --- a/ProcessMaker/Ai/Handlers/NlqToPmqlHandler.php +++ b/ProcessMaker/Ai/Handlers/NlqToPmqlHandler.php @@ -10,7 +10,7 @@ public function __construct() { parent::__construct(); $this->config = [ - 'model' => 'text-davinci-003', + 'model' => 'gpt-3.5-turbo', 'max_tokens' => 1900, 'temperature' => 0, 'top_p' => 1, @@ -34,7 +34,10 @@ public function generatePrompt(String $type = null, String $question) : Object $prompt = $this->replaceStopSequence($prompt); $prompt = $this->replaceWithCurrentYear($prompt); - $this->config['prompt'] = $prompt; + $this->config['messages'] = [[ + 'role' => 'user', + 'content' => $prompt, + ]]; return $this; } @@ -43,15 +46,18 @@ public function execute() { $client = app(Client::class); $response = $client - ->completions() - ->create(array_merge($this->getConfig())); + ->chat() + ->create( + array_merge($this->getConfig() + ) + ); return $this->formatResponse($response); } private function formatResponse($response) { - $result = ltrim($response->choices[0]->text); + $result = ltrim($response->choices[0]->message->content); $result = explode('Question:', $result)[0]; $result = rtrim(rtrim(str_replace("\n", '', $result))); $result = str_replace('\'', '', $result);