diff --git a/question.php b/question.php index 4061e27..875b007 100755 --- a/question.php +++ b/question.php @@ -244,17 +244,19 @@ 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 with a single field named transation'; $llmresponse = $ai->prompt_completion($prompt); $translation = $llmresponse['response']['choices'][0]['message']['content']; - $translation = trim($translation, '"'); + $translationobject = json_decode($translation); + $translation = trim($translationobject->translation, '"'); $cache->set(current_language().'_'.$text, $translation); } return $translation;