2023-11-23 10:58:54 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
require_relative "dialect_context"
|
2023-11-23 10:58:54 -05:00
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
RSpec.describe DiscourseAi::Completions::Dialects::Llama2Classic do
|
|
|
|
let(:model_name) { "Llama2-chat-hf" }
|
|
|
|
let(:context) { DialectContext.new(described_class, model_name) }
|
2023-11-23 10:58:54 -05:00
|
|
|
|
|
|
|
describe "#translate" do
|
|
|
|
it "translates a prompt written in our generic format to the Llama2 format" do
|
|
|
|
llama2_classic_version = <<~TEXT
|
2023-12-18 16:06:01 -05:00
|
|
|
[INST]
|
|
|
|
<<SYS>>
|
2024-01-12 12:36:44 -05:00
|
|
|
#{context.system_insts}
|
|
|
|
#{described_class.tool_preamble}
|
|
|
|
<tools>
|
|
|
|
#{context.dialect_tools}</tools>
|
2023-12-18 16:06:01 -05:00
|
|
|
<</SYS>>
|
|
|
|
[/INST]
|
2024-01-12 12:36:44 -05:00
|
|
|
[INST]#{context.simple_user_input}[/INST]
|
2023-11-23 10:58:54 -05:00
|
|
|
TEXT
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
translated = context.system_user_scenario
|
2023-11-23 10:58:54 -05:00
|
|
|
|
|
|
|
expect(translated).to eq(llama2_classic_version)
|
|
|
|
end
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
it "translates tool messages" do
|
|
|
|
expected = +(<<~TEXT)
|
2023-12-18 16:06:01 -05:00
|
|
|
[INST]
|
|
|
|
<<SYS>>
|
2024-01-12 12:36:44 -05:00
|
|
|
#{context.system_insts}
|
|
|
|
#{described_class.tool_preamble}
|
2023-12-18 16:06:01 -05:00
|
|
|
<tools>
|
2024-01-12 12:36:44 -05:00
|
|
|
#{context.dialect_tools}</tools>
|
2023-12-18 16:06:01 -05:00
|
|
|
<</SYS>>
|
|
|
|
[/INST]
|
2024-01-12 12:36:44 -05:00
|
|
|
[INST]This is a message by a user[/INST]
|
|
|
|
I'm a previous bot reply, that's why there's no user
|
|
|
|
[INST]This is a new message by a user[/INST]
|
2023-12-18 16:06:01 -05:00
|
|
|
[INST]
|
|
|
|
<function_results>
|
|
|
|
<result>
|
|
|
|
<tool_name>tool_id</tool_name>
|
|
|
|
<json>
|
2024-01-12 12:36:44 -05:00
|
|
|
"I'm a tool result"
|
2023-12-18 16:06:01 -05:00
|
|
|
</json>
|
|
|
|
</result>
|
|
|
|
</function_results>
|
|
|
|
[/INST]
|
|
|
|
TEXT
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
expect(context.multi_turn_scenario).to eq(expected)
|
2023-12-18 16:06:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "trims content if it's getting too long" do
|
2024-01-12 12:36:44 -05:00
|
|
|
translated = context.long_user_input_scenario
|
2023-12-18 16:06:01 -05:00
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
expect(translated.length).to be < context.long_message_text.length
|
2023-12-18 16:06:01 -05:00
|
|
|
end
|
2023-11-23 10:58:54 -05:00
|
|
|
end
|
|
|
|
end
|