Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit d56a7e0

Browse files
committed
FEATURE: Add locale detection prompt from translator
1 parent 2900d2c commit d56a7e0

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

app/models/completion_prompt.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class CompletionPrompt < ActiveRecord::Base
88
CUSTOM_PROMPT = -305
99
EXPLAIN = -306
1010
ILLUSTRATE_POST = -308
11+
DETECT_TEXT_LOCALE = -309
1112

1213
enum :prompt_type, { text: 0, list: 1, diff: 2 }
1314

db/fixtures/ai_helper/603_completion_prompts.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,20 @@
200200
cp.prompt_type = CompletionPrompt.prompt_types[:list]
201201
cp.messages = {}
202202
end
203+
204+
CompletionPrompt.seed do |cp|
205+
cp.id = -309
206+
cp.name = "detect_text_locale"
207+
cp.prompt_type = CompletionPrompt.prompt_types[:text]
208+
cp.messages = {
209+
insts: <<~TEXT,
210+
I want you to act as a language expert, determining the locale for a set of text.
211+
The locale is a language identifier, such as "en" for English, "de" for German, etc,
212+
and can also include a region identifier, such as "en-GB" for British English, or "zh-Hans" for Simplified Chinese.
213+
I will provide you with text, and you will determine the locale of the text.
214+
You will find the text between <input></input> XML tags.
215+
Include your locale between <output></output> XML tags.
216+
TEXT
217+
examples: [["<input>Hello my favourite colour is red</input>", "<output>en-GB</output>"]],
218+
}
219+
end

spec/lib/modules/ai_helper/assistant_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@
4848
it "returns all available prompts" do
4949
prompts = subject.available_prompts(user)
5050

51-
expect(prompts.length).to eq(6)
51+
expect(prompts.length).to eq(7)
5252
expect(prompts.map { |p| p[:name] }).to contain_exactly(
5353
"translate",
5454
"generate_titles",
5555
"proofread",
5656
"markdown_table",
5757
"custom_prompt",
5858
"explain",
59+
"detect_text_locale",
5960
)
6061
end
6162

@@ -73,7 +74,7 @@
7374
it "returns the illustrate_post prompt in the list of all prompts" do
7475
prompts = subject.available_prompts(user)
7576

76-
expect(prompts.length).to eq(7)
77+
expect(prompts.length).to eq(8)
7778
expect(prompts.map { |p| p[:name] }).to contain_exactly(
7879
"translate",
7980
"generate_titles",
@@ -82,6 +83,7 @@
8283
"custom_prompt",
8384
"explain",
8485
"illustrate_post",
86+
"detect_text_locale",
8587
)
8688
end
8789
end

spec/plugin_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
it "returns the available prompts" do
4545
expect(serializer.ai_helper_prompts).to be_present
46-
expect(serializer.ai_helper_prompts.object.count).to eq(6)
46+
expect(serializer.ai_helper_prompts.object.count).to eq(7)
4747
end
4848
end
4949
end

0 commit comments

Comments
 (0)