FIX: Clean unicode usernames when adding messages through prompt's contrstuctor (#425)
This commit is contained in:
parent
37e6ac169e
commit
ff4da6ace8
|
@ -22,6 +22,10 @@ module DiscourseAi
|
|||
@messages.concat(messages)
|
||||
|
||||
@messages.each { |message| validate_message(message) }
|
||||
@messages.each do |message|
|
||||
message[:id] = clean_username(message[:id]) if message[:type] == :user &&
|
||||
message[:id].present?
|
||||
end
|
||||
@messages.each_cons(2) { |last_turn, new_turn| validate_turn(last_turn, new_turn) }
|
||||
|
||||
@tools = tools
|
||||
|
|
|
@ -21,6 +21,18 @@ RSpec.describe DiscourseAi::Completions::Prompt do
|
|||
bad_messages3 = [{ content: "some content associated to no one" }]
|
||||
expect { described_class.new("a bot", messages: bad_messages3) }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "cleans unicode usernames" do
|
||||
unicode_username = "罗马罗马"
|
||||
|
||||
prompt =
|
||||
described_class.new(
|
||||
"a bot",
|
||||
messages: [{ type: :user, content: user_msg, id: unicode_username }],
|
||||
)
|
||||
|
||||
expect(prompt.messages.last[:id]).to eq("____")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#push" do
|
||||
|
@ -62,5 +74,14 @@ RSpec.describe DiscourseAi::Completions::Prompt do
|
|||
expect(system_message[:content]).to eq(user_msg)
|
||||
expect(system_message[:id]).to eq(username)
|
||||
end
|
||||
|
||||
it "cleans unicode usernames" do
|
||||
unicode_username = "罗马罗马"
|
||||
prompt.push(type: :user, content: user_msg, id: unicode_username)
|
||||
|
||||
user_message = prompt.messages.last
|
||||
|
||||
expect(user_message[:id]).to eq("____")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue