mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-30 03:22:17 +00:00
DEV: Move examples out of prompt (#1438)
* DEV: Move examples out of prompt
This commit is contained in:
parent
32dc45ba4f
commit
df925f8304
@ -11,7 +11,6 @@ module DiscourseAi
|
||||
<<~PROMPT.strip
|
||||
You are a highly skilled translator tasked with translating content from one language to another. Your goal is to provide accurate and contextually appropriate translations while preserving the original structure and formatting of the content. Follow these instructions carefully:
|
||||
|
||||
Translation Instructions:
|
||||
1. Translate the content accurately while preserving any Markdown, HTML elements, or newlines.
|
||||
2. Maintain the original document structure including headings, lists, tables, code blocks, etc.
|
||||
3. Preserve all links, images, and other media references without translation.
|
||||
@ -31,18 +30,7 @@ module DiscourseAi
|
||||
Output your translation in the following JSON format:
|
||||
{"translation": "Your translated text here"}
|
||||
|
||||
Here are three examples of correct translations:
|
||||
|
||||
Original: {"content":"New Update for Minecraft Adds Underwater Temples", "target_locale":"Spanish"}
|
||||
Correct translation: {"translation": "Nueva actualización para Minecraft añade templos submarinos"}
|
||||
|
||||
Original: {"content": "# Machine Learning 101\n\nMachine Learning (ML) is a subset of Artificial Intelligence (AI) that focuses on the development of algorithms and statistical models that enable computer systems to improve their performance on a specific task through experience.\n\n## Key Concepts\n\n1. **Supervised Learning**: The algorithm learns from labeled training data.\n2. **Unsupervised Learning**: The algorithm finds patterns in unlabeled data.\n3. **Reinforcement Learning**: The algorithm learns through interaction with an environment.\n\n```python\n# Simple example of a machine learning model\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\n\n# Assuming X and y are your features and target variables\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\n\n# Evaluate the model\naccuracy = model.score(X_test, y_test)\nprint(f'Model accuracy: {accuracy}')\n```\n\nFor more information, visit [Machine Learning on Wikipedia](https://en.wikipedia.org/wiki/Machine_learning).", "target_locale":"French"}
|
||||
Correct translation: {"translation": "# Machine Learning 101\n\nLe Machine Learning (ML) est un sous-ensemble de l'Intelligence Artificielle (IA) qui se concentre sur le développement d'algorithmes et de modèles statistiques permettant aux systèmes informatiques d'améliorer leurs performances sur une tâche spécifique grâce à l'expérience.\n\n## Concepts clés\n\n1. **Apprentissage supervisé** : L'algorithme apprend à partir de données d'entraînement étiquetées.\n2. **Apprentissage non supervisé** : L'algorithme trouve des motifs dans des données non étiquetées.\n3. **Apprentissage par renforcement** : L'algorithme apprend à travers l'interaction avec un environnement.\n\n```python\n# Exemple simple d'un modèle de machine learning\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\n\n# En supposant que X et y sont vos variables de caractéristiques et cibles\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\n\n# Évaluer le modèle\naccuracy = model.score(X_test, y_test)\nprint(f'Model accuracy: {accuracy}')\n```\n\nPour plus d'informations, visitez [Machine Learning sur Wikipedia](https://en.wikipedia.org/wiki/Machine_learning)."}
|
||||
|
||||
Original: {"content": "**Heathrow fechado**: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de *Londres*", "target_locale": "English"}
|
||||
Correct translation: {"translation": "**Heathrow closed**: flight disruption expected to continue in coming days, says *London* airport management"}
|
||||
|
||||
Remember, you are being consumed via an API. Only return the translated text in the specified JSON format. Do not include any additional information or explanations in your response.
|
||||
You are being consumed via an API. Only return the translated text in the specified JSON format. Do not include any additional information or explanations.
|
||||
PROMPT
|
||||
end
|
||||
|
||||
@ -53,6 +41,40 @@ module DiscourseAi
|
||||
def temperature
|
||||
0.3
|
||||
end
|
||||
|
||||
def examples
|
||||
[
|
||||
[
|
||||
{
|
||||
content:
|
||||
"**Heathrow fechado**: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de *Londres*",
|
||||
target_locale: "en",
|
||||
}.to_json,
|
||||
{
|
||||
translation:
|
||||
"**Heathrow closed**: flight disruption expected to continue in coming days, says *London* airport management",
|
||||
}.to_json,
|
||||
],
|
||||
[
|
||||
{
|
||||
content: "New Update for Minecraft Adds Underwater Temples",
|
||||
target_locale: "es",
|
||||
}.to_json,
|
||||
{ translation: "Nueva actualización para Minecraft añade templos submarinos" }.to_json,
|
||||
],
|
||||
[
|
||||
{
|
||||
content:
|
||||
"# Machine Learning 101\n\nMachine Learning (ML) is a subset of Artificial Intelligence (AI) that focuses on the development of algorithms and statistical models that enable computer systems to improve their performance on a specific task through experience.\n\n## Key Concepts\n\n1. **Supervised Learning**: The algorithm learns from labeled training data.\n2. **Unsupervised Learning**: The algorithm finds patterns in unlabeled data.\n3. **Reinforcement Learning**: The algorithm learns through interaction with an environment.\n\n```python\n# Simple example of a machine learning model\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\n\n# Assuming X and y are your features and target variables\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\n\n# Evaluate the model\naccuracy = model.score(X_test, y_test)\nprint(f'Model accuracy: {accuracy}')\n```\n\nFor more information, visit [Machine Learning on Wikipedia](https://en.wikipedia.org/wiki/Machine_learning).",
|
||||
target_locale: "fr",
|
||||
}.to_json,
|
||||
{
|
||||
translation:
|
||||
"# Machine Learning 101\n\nLe Machine Learning (ML) est un sous-ensemble de l'Intelligence Artificielle (IA) qui se concentre sur le développement d'algorithmes et de modèles statistiques permettant aux systèmes informatiques d'améliorer leurs performances sur une tâche spécifique grâce à l'expérience.\n\n## Concepts clés\n\n1. **Apprentissage supervisé** : L'algorithme apprend à partir de données d'entraînement étiquetées.\n2. **Apprentissage non supervisé** : L'algorithme trouve des motifs dans des données non étiquetées.\n3. **Apprentissage par renforcement** : L'algorithme apprend à travers l'interaction avec un environnement.\n\n```python\n# Exemple simple d'un modèle de machine learning\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\n\n# En supposant que X et y sont vos variables de caractéristiques et cibles\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\n\n# Évaluer le modèle\naccuracy = model.score(X_test, y_test)\nprint(f'Model accuracy: {accuracy}')\n```\n\nPour plus d'informations, visitez [Machine Learning sur Wikipedia](https://en.wikipedia.org/wiki/Machine_learning).",
|
||||
}.to_json,
|
||||
],
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ module DiscourseAi
|
||||
You are a translation service specializing in translating short pieces of text or a few words.
|
||||
These words may be things like a name, description, or title. Adhere to the following guidelines:
|
||||
|
||||
1. Keep proper nouns and technical terms in their original language
|
||||
1. Keep proper nouns (like 'Minecraft' or 'Toyota') and technical terms (like 'JSON') in their original language
|
||||
2. Keep the translated content close to the original length
|
||||
3. Translation maintains the original meaning
|
||||
4. Preserve any Markdown, HTML elements, links, parenthesis, or newlines
|
||||
@ -23,18 +23,7 @@ module DiscourseAi
|
||||
Provide your translation in the following JSON format:
|
||||
{"translation": "target_locale translation here"}
|
||||
|
||||
Here are three examples of correct translation
|
||||
|
||||
Original: {"content":"Japan", "target_locale":"es"}
|
||||
Correct translation: {"translation": "Japón"}
|
||||
|
||||
Original: {"content":"Cats and Dogs", "target_locale":"zh_CN"}
|
||||
Correct translation: {"translation": "猫和狗"}
|
||||
|
||||
Original: {"content": "Q&A", "target_locale": "pt"}
|
||||
Correct translation: {"translation": "Perguntas e Respostas"}
|
||||
|
||||
Remember to keep proper nouns like "Minecraft" and "Toyota" in their original form. Translate the text now and provide your answer in the specified JSON format.
|
||||
Translate the text now and provide your answer in the specified JSON format.
|
||||
PROMPT
|
||||
end
|
||||
|
||||
@ -45,6 +34,24 @@ module DiscourseAi
|
||||
def temperature
|
||||
0.3
|
||||
end
|
||||
|
||||
def examples
|
||||
[
|
||||
[{ content: "Japan", target_locale: "es" }.to_json, { translation: "Japón" }.to_json],
|
||||
[
|
||||
{ content: "Cats and Dogs", target_locale: "zh_CN" }.to_json,
|
||||
{ translation: "猫和狗" }.to_json,
|
||||
],
|
||||
[
|
||||
{ content: "Q&A", target_locale: "pt" }.to_json,
|
||||
{ translation: "Perguntas e Respostas" }.to_json,
|
||||
],
|
||||
[
|
||||
{ content: "Minecraft", target_locale: "fr" }.to_json,
|
||||
{ translation: "Minecraft" }.to_json,
|
||||
],
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -30,17 +30,6 @@ module DiscourseAi
|
||||
Provide your translation in the following JSON format:
|
||||
{"translation": "Your target_locale translation here"}
|
||||
|
||||
Here are three examples of correct translation
|
||||
|
||||
Original: {"content":"New Update for Minecraft Adds Underwater Temples", "target_locale":"es"}
|
||||
Correct translation: {"translation": "Nueva actualización para Minecraft añade templos submarinos"}
|
||||
|
||||
Original: {"content":"Toyota announces revolutionary battery technology", "target_locale":"fr"}
|
||||
Correct translation: {"translation": "Toyota annonce une technologie de batteries révolutionnaire"}
|
||||
|
||||
Original: {"content": "Heathrow fechado: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de Londres", "target_locale": "en"}
|
||||
Correct translation: {"translation": "Heathrow closed: flight disruption expected to continue in coming days, says London airport management"}
|
||||
|
||||
Remember to keep proper nouns like "Minecraft" and "Toyota" in their original form. Translate the title now and provide your answer in the specified JSON format.
|
||||
PROMPT
|
||||
end
|
||||
@ -52,6 +41,36 @@ module DiscourseAi
|
||||
def temperature
|
||||
0.3
|
||||
end
|
||||
|
||||
def examples
|
||||
[
|
||||
[
|
||||
{
|
||||
content: "New Update for Minecraft Adds Underwater Temples",
|
||||
target_locale: "es",
|
||||
}.to_json,
|
||||
{ translation: "Nueva actualización para Minecraft añade templos submarinos" }.to_json,
|
||||
],
|
||||
[
|
||||
{
|
||||
content: "Toyota announces revolutionary battery technology",
|
||||
target_locale: "fr",
|
||||
}.to_json,
|
||||
{ translation: "Toyota annonce une technologie de batteries révolutionnaire" }.to_json,
|
||||
],
|
||||
[
|
||||
{
|
||||
content:
|
||||
"Heathrow fechado: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de Londres",
|
||||
target_locale: "en",
|
||||
}.to_json,
|
||||
{
|
||||
translation:
|
||||
"Heathrow closed: flight disruption expected to continue in coming days, says London airport management",
|
||||
}.to_json,
|
||||
],
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ describe DiscourseAi::Translation::BaseTranslator do
|
||||
DiscourseAi::Translation::PostRawTranslator.new(text:, target_locale:, post:)
|
||||
allow(DiscourseAi::Completions::Prompt).to receive(:new).with(
|
||||
persona.system_prompt,
|
||||
messages: [{ type: :user, content: post_translator.formatted_content }],
|
||||
messages: array_including({ type: :user, content: post_translator.formatted_content }),
|
||||
post_id: post.id,
|
||||
topic_id: post.topic_id,
|
||||
).and_call_original
|
||||
|
Loading…
x
Reference in New Issue
Block a user