|
17 | 17 | it "creates the correct prompt" do |
18 | 18 | allow(DiscourseAi::Completions::Prompt).to receive(:new).with( |
19 | 19 | <<~TEXT, |
20 | | - You are a highly skilled linguist and web programmer, with expertise in many languages, and very well versed in HTML. |
| 20 | + You are a highly skilled linguist of many languages and have expert knowledge in HTML. |
21 | 21 | Your task is to identify the language of the text I provide and accurately translate it into this language locale "de" while preserving the meaning, tone, and nuance of the original text. |
22 | | - The text will contain html tags, which must absolutely be preserved in the translation. |
| 22 | + The text may or may not contain html tags. If they do, preserve them. |
23 | 23 | Maintain proper grammar, spelling, and punctuation in the translated version. |
24 | | - Wrap the translated text in a <translation> tag. |
| 24 | + You will find the text between <input></input> XML tags. |
| 25 | + Include your translation between <output></output> XML tags. |
| 26 | + Do not write explanations. |
25 | 27 | TEXT |
26 | | - messages: [{ type: :user, content: text_to_translate, id: "user" }], |
| 28 | + messages: [{ type: :user, content: "<input>cats are great</input>", id: "user" }], |
27 | 29 | ).and_call_original |
28 | 30 |
|
29 | 31 | described_class.new(text_to_translate, target_language).translate |
|
48 | 50 |
|
49 | 51 | it "returns the translation from the llm's response in the translation tag" do |
50 | 52 | DiscourseAi::Completions::Llm.with_prepared_responses( |
51 | | - ["<translation>hur dur hur dur!</translation>"], |
| 53 | + ["<output>hur dur hur dur!</output>"], |
52 | 54 | ) do |
53 | 55 | expect( |
54 | 56 | described_class.new(text_to_translate, target_language).translate, |
55 | 57 | ).to eq "hur dur hur dur!" |
56 | 58 | end |
57 | 59 | end |
58 | 60 |
|
59 | | - it "returns the raw response if the translation tag is not present" do |
| 61 | + it "returns an empty string if the translation tag is not present" do |
60 | 62 | DiscourseAi::Completions::Llm.with_prepared_responses(["raw response."]) do |
61 | | - expect( |
62 | | - described_class.new(text_to_translate, target_language).translate, |
63 | | - ).to eq "raw response." |
| 63 | + expect(described_class.new(text_to_translate, target_language).translate).to eq "" |
64 | 64 | end |
65 | 65 | end |
66 | 66 | end |
|
0 commit comments