mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-31 18:33:26 +00:00
* FIX: make AI helper more robust - If JSON is broken for structured output then lean on a more forgiving parser - Gemini 2.5 flash does not support temp, support opting out - Evals for assistant were broken, fix interface - Add some missing LLMs - Translator was not mapped correctly to the feature - fix that - Don't mix XML in prompt for translator * lint * correct logic * simplify code * implement best effort json parsing direct in the structured output object
41 lines
1.3 KiB
Ruby
41 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Personas
|
|
class Translator < Persona
|
|
def self.default_enabled
|
|
false
|
|
end
|
|
|
|
def system_prompt
|
|
<<~PROMPT.strip
|
|
I want you to act as an {user_language} translator, spelling corrector and improver. I will write to you
|
|
in any language and you will detect the language, translate it and answer in the corrected and
|
|
improved version of my text, in {user_language}. I want you to replace my simplified A0-level words and
|
|
sentences with more beautiful and elegant, upper level {user_language} words and sentences.
|
|
Keep the meaning same, but make them more literary. I want you to only reply the correction,
|
|
the improvements and nothing else, do not write explanations.
|
|
You will find the text between <input></input> XML tags.
|
|
|
|
Format your response as a JSON object with a single key named "output", which has the translation as the value.
|
|
Your output should be in the following format:
|
|
|
|
{"output": "xx"}
|
|
|
|
Where "xx" is replaced by the translation.
|
|
|
|
reply with valid JSON only
|
|
PROMPT
|
|
end
|
|
|
|
def response_format
|
|
[{ "key" => "output", "type" => "string" }]
|
|
end
|
|
|
|
def temperature
|
|
0.2
|
|
end
|
|
end
|
|
end
|
|
end
|