From 9aae1c5c2e2a9b37909f25c0f174db2f25058e69 Mon Sep 17 00:00:00 2001 From: Marcus Green Date: Thu, 6 Jun 2024 15:34:54 +0100 Subject: [PATCH] Fix to the translation to return json against global json format later --- question.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/question.php b/question.php index 4061e27..5c84848 100755 --- a/question.php +++ b/question.php @@ -244,17 +244,18 @@ public function process_feedback(string $feedback) { * @param string $text * @return string */ - protected function llm_translate(string $text) :string { + protected function llm_translate(string $text): string { if (current_language() == 'en') { return $text; } $ai = new ai\ai(); $cache = cache::make('qtype_aitext', 'stringdata'); if (($translation = $cache->get(current_language().'_'.$text)) === false) { - $prompt = 'translate "'.$text .'" into '.current_language(); + $prompt = 'translate "'.$text .'" into '.current_language(). ' respond with json object named transltion with a single field named translated'; $llmresponse = $ai->prompt_completion($prompt); $translation = $llmresponse['response']['choices'][0]['message']['content']; - $translation = trim($translation, '"'); + $translationobject = json_decode($translation); + $translation = trim($translationobject->translated, '"'); $cache->set(current_language().'_'.$text, $translation); } return $translation;