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-12-18 16:06:01 -05:00
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
RSpec.describe DiscourseAi::Completions::Dialects::OrcaStyle do
|
|
|
|
let(:model_name) { "StableBeluga2" }
|
|
|
|
let(:context) { DialectContext.new(described_class, model_name) }
|
2023-12-18 16:06:01 -05:00
|
|
|
|
|
|
|
describe "#translate" do
|
2024-01-12 12:36:44 -05:00
|
|
|
it "translates a prompt written in our generic format to the Llama2 format" do
|
|
|
|
llama2_classic_version = <<~TEXT
|
2023-11-23 10:58:54 -05:00
|
|
|
### System:
|
2024-01-12 12:36:44 -05:00
|
|
|
#{context.system_insts}
|
|
|
|
#{described_class.tool_preamble}
|
|
|
|
<tools>
|
|
|
|
#{context.dialect_tools}</tools>
|
2023-11-23 10:58:54 -05:00
|
|
|
### User:
|
2024-01-12 12:36:44 -05:00
|
|
|
#{context.simple_user_input}
|
2023-11-23 10:58:54 -05:00
|
|
|
### Assistant:
|
|
|
|
TEXT
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
translated = context.system_user_scenario
|
2023-12-18 16:06:01 -05:00
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
expect(translated).to eq(llama2_classic_version)
|
2023-12-18 16:06:01 -05:00
|
|
|
end
|
|
|
|
|
2024-01-12 12:36:44 -05:00
|
|
|
it "translates tool messages" do
|
|
|
|
expected = +(<<~TEXT)
|
2023-12-18 16:06:01 -05:00
|
|
|
### System:
|
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
|
|
|
### User:
|
2024-01-12 12:36:44 -05:00
|
|
|
This is a message by a user
|
2023-12-18 16:06:01 -05:00
|
|
|
### Assistant:
|
2024-01-12 12:36:44 -05:00
|
|
|
I'm a previous bot reply, that's why there's no user
|
|
|
|
### User:
|
|
|
|
This is a new message by a user
|
2023-12-18 16:06:01 -05:00
|
|
|
### Assistant:
|
|
|
|
<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>
|
2024-01-12 12:36:44 -05:00
|
|
|
### Assistant:
|
2023-12-18 16:06:01 -05:00
|
|
|
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
|
|
|
|
end
|
2023-11-23 10:58:54 -05:00
|
|
|
end
|