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

Commit 7c65dd1

Browse files
authored
FIX: regression, no longer sending examples to AI helper (#993)
For a while now we have not been sending the examples to AI helper, which can lead to inconsistent results. Note: this also means that in non English we did not send English results, so this may end up reducing performance That said first thing we need to do is fix the regression.
1 parent e3f5e86 commit 7c65dd1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

app/models/completion_prompt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def messages_with_input(input)
3737

3838
prompt = DiscourseAi::Completions::Prompt.new(instructions)
3939

40-
messages_hash[:examples].to_a do |example_pair|
40+
messages_hash[:examples].to_a.each do |example_pair|
4141
prompt.push(type: :user, content: example_pair.first)
4242
prompt.push(type: :model, content: example_pair.second)
4343
end

spec/models/completion_prompt_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@
2222
describe "messages_with_input" do
2323
let(:user_input) { "A user wrote this." }
2424

25+
context "when mapping to a prompt" do
26+
it "correctly maps everything to the prompt" do
27+
cp =
28+
CompletionPrompt.new(
29+
messages: {
30+
insts: "Instructions",
31+
post_insts: "Post Instructions",
32+
examples: [["Request 1", "Response 1"]],
33+
},
34+
)
35+
36+
prompt = cp.messages_with_input("hello")
37+
38+
expected = [
39+
{ type: :system, content: "Instructions\nPost Instructions" },
40+
{ type: :user, content: "Request 1" },
41+
{ type: :model, content: "Response 1" },
42+
{ type: :user, content: "<input>hello</input>" },
43+
]
44+
45+
expect(prompt.messages).to eq(expected)
46+
end
47+
end
48+
2549
context "when the record has the custom_prompt type" do
2650
let(:custom_prompt) { described_class.find(described_class::CUSTOM_PROMPT) }
2751

0 commit comments

Comments
 (0)