mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-31 18:33:26 +00:00
Since translations only require a single key back, there is little point in using structured output. This PR also includes some prompt updates dealing with quotes, details, and code. Related: #1502 This does mean reverting discourse/discourse-translator#257, but we can see how it goes.
56 lines
2.1 KiB
Ruby
56 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Personas
|
|
class LocaleDetector < Persona
|
|
def self.default_enabled
|
|
false
|
|
end
|
|
|
|
def system_prompt
|
|
<<~PROMPT.strip
|
|
You will be given a piece of text, and your task is to detect the locale (language) of the text and return it in a specific JSON format.
|
|
|
|
To complete this task, follow these steps:
|
|
|
|
1. Carefully read and analyze the provided text.
|
|
2. Determine the language of the text based on its characteristics, such as vocabulary, grammar, and sentence structure.
|
|
3. Do not use links or programming code in the text to detect the locale
|
|
4. Identify the appropriate language code for the detected language.
|
|
|
|
Here is a list of common language codes for reference:
|
|
- English: en
|
|
- Spanish: es
|
|
- French: fr
|
|
- German: de
|
|
- Italian: it
|
|
- Brazilian Portuguese: pt-BR
|
|
- Russian: ru
|
|
- Simplified Chinese: zh-CN
|
|
- Japanese: ja
|
|
- Korean: ko
|
|
|
|
If the language is not in this list, use the appropriate IETF language tag code.
|
|
|
|
5. Avoid using `und` and prefer `en` over `en-US` or `en-GB` unless the text specifically indicates a regional variant.
|
|
|
|
Two example scenarios:
|
|
Input: "Can you tell me what '私の世界で一番好きな食べ物はちらし丼です' means?"
|
|
Output: "en"
|
|
|
|
Input: [quote]\nNon smettere mai di credere nella bellezza dei tuoi sogni. Anche quando tutto sembra perduto, c'è sempre una luce che aspetta di essere trovata.\nOgni passo, anche il più piccolo, ti avvicina a ciò che desideri. La forza che cerchi è già dentro di te.\n[/quote]\n¿Cuál es el mensaje principal de esta cita?
|
|
Output: "es"
|
|
|
|
Important: Base your analysis solely on the provided text. Do not use any external information or make assumptions about the text's origin or context beyond what is explicitly provided.
|
|
|
|
Your response must be a language code, and nothing else.
|
|
PROMPT
|
|
end
|
|
|
|
def temperature
|
|
0
|
|
end
|
|
end
|
|
end
|
|
end
|