Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/completion_prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def messages_with_input(input)

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

messages_hash[:examples].to_a do |example_pair|
messages_hash[:examples].to_a.each do |example_pair|
prompt.push(type: :user, content: example_pair.first)
prompt.push(type: :model, content: example_pair.second)
end
Expand Down
24 changes: 24 additions & 0 deletions spec/models/completion_prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@
describe "messages_with_input" do
let(:user_input) { "A user wrote this." }

context "when mapping to a prompt" do
it "correctly maps everything to the prompt" do
cp =
CompletionPrompt.new(
messages: {
insts: "Instructions",
post_insts: "Post Instructions",
examples: [["Request 1", "Response 1"]],
},
)

prompt = cp.messages_with_input("hello")

expected = [
{ type: :system, content: "Instructions\nPost Instructions" },
{ type: :user, content: "Request 1" },
{ type: :model, content: "Response 1" },
{ type: :user, content: "<input>hello</input>" },
]

expect(prompt.messages).to eq(expected)
end
end

context "when the record has the custom_prompt type" do
let(:custom_prompt) { described_class.find(described_class::CUSTOM_PROMPT) }

Expand Down
Loading