diff --git a/src/Helpers/Chatbot.php b/src/Helpers/Chatbot.php index 39145f8..9a9649a 100644 --- a/src/Helpers/Chatbot.php +++ b/src/Helpers/Chatbot.php @@ -29,12 +29,12 @@ public function askBot(string $question): array } return [ - 'data' => $pinecone_res->json()['matches'][0]['metadata']['text'], + 'data' => $pinecone_res->json()['matches'], 'vectors' => $openai_res->embeddings[0]->toArray()['embedding'], ]; } - public function botResponse($chunks, string $question): CreateResponse + public function botResponse(string $chunks, string $question): CreateResponse { $this->textNote('Generating answer...'); @@ -46,7 +46,7 @@ public function botResponse($chunks, string $question): CreateResponse 'messages' => [ [ 'role' => 'system', - 'content' => config('laragenie.bot.instruction').$chunks, + 'content' => config('laragenie.bot.instructions').$chunks, ], [ 'role' => 'user', diff --git a/src/Helpers/Questions.php b/src/Helpers/Questions.php index bddec38..aae7aa3 100644 --- a/src/Helpers/Questions.php +++ b/src/Helpers/Questions.php @@ -29,8 +29,16 @@ public function userQuestion(string $user_question): void if ($laragenie->exists && config('laragenie.database.fetch') && ! $ai) { $this->textOutput($laragenie->answer); } else { - $questionResponse = $this->askBot($formattedQuestion); - $botResponse = $this->botResponse($questionResponse['data'], $question); + $results = (array) $this->askBot($formattedQuestion); + $embeddings = []; + + foreach ($results['data'] as $key => $result) { + $embeddings[$key] = $result['metadata']['text']; + } + + $chunks = implode(',', $embeddings); + + $botResponse = $this->botResponse($chunks, $question); if ($botResponse) { $answer = $botResponse->choices[0]->message->content; @@ -41,7 +49,7 @@ public function userQuestion(string $user_question): void $laragenie->fill([ 'answer' => $answer, 'cost' => $calculatedCost, - 'vectors' => $questionResponse['vectors'], + 'vectors' => $results['vectors'], ]); $laragenie->save();