|
3 | 3 | let(:prompts) { AutoEvaluation::Prompts.config.answer_relevancy } |
4 | 4 | let(:question_message) { "This is a test question message." } |
5 | 5 | let(:answer_message) { "This is a test answer message." } |
| 6 | + let(:question) { build(:question, message: question_message) } |
| 7 | + let(:answer) { build(:answer, question:, message: answer_message) } |
6 | 8 |
|
7 | 9 | let(:statements) { ["This is the first statement.", "This is the second statement."] } |
8 | 10 | let(:statements_json) { { statements: }.to_json } |
|
67 | 69 | allow(Clock).to receive(:monotonic_time) |
68 | 70 | .and_return(200.0, 202.0, 204.0, 206.0, 208.0, 210.0) |
69 | 71 |
|
70 | | - result = described_class.call( |
71 | | - question_message:, |
72 | | - answer_message:, |
73 | | - ) |
| 72 | + result = described_class.call(answer) |
74 | 73 |
|
75 | 74 | expected_llm_responses = { |
76 | 75 | statements: JSON.parse(statements_stub.response.body), |
|
100 | 99 | ) |
101 | 100 | end |
102 | 101 |
|
| 102 | + context "when the answer has a rephrased question" do |
| 103 | + let(:question_message) { "This is a rephrased test question." } |
| 104 | + let(:answer) { build(:answer, message: answer_message, rephrased_question: question_message) } |
| 105 | + |
| 106 | + it "uses the rephrased question in the prompt" do |
| 107 | + result = described_class.call(answer) |
| 108 | + expect(result.reason).to eq(reason) |
| 109 | + end |
| 110 | + end |
| 111 | + |
103 | 112 | context "when 'idk' verdicts are present" do |
104 | 113 | let(:verdicts) do |
105 | 114 | [ |
|
109 | 118 | end |
110 | 119 |
|
111 | 120 | it "treats 'idk' verdicts as positive in the score" do |
112 | | - result = described_class.call( |
113 | | - question_message:, |
114 | | - answer_message:, |
115 | | - ) |
| 121 | + result = described_class.call(answer) |
116 | 122 |
|
117 | 123 | expect(result.score).to eq(0.5) |
118 | 124 | end |
|
124 | 130 | it "returns a result object with the expected attributes" do |
125 | 131 | allow(Clock).to receive(:monotonic_time).and_return(200.0, 202.0) |
126 | 132 |
|
127 | | - result = described_class.call( |
128 | | - question_message:, |
129 | | - answer_message:, |
130 | | - ) |
| 133 | + result = described_class.call(answer) |
131 | 134 |
|
132 | 135 | expect(result) |
133 | 136 | .to be_a(AutoEvaluation::ScoreResult) |
|
148 | 151 | allow(Clock).to receive(:monotonic_time) |
149 | 152 | .and_return(200.0, 202.0, 204.0, 206.0) |
150 | 153 |
|
151 | | - result = described_class.call( |
152 | | - question_message:, |
153 | | - answer_message:, |
154 | | - ) |
| 154 | + result = described_class.call(answer) |
155 | 155 |
|
156 | 156 | expect(result) |
157 | 157 | .to be_a(AutoEvaluation::ScoreResult) |
|
177 | 177 | it "returns a result object with the expected attributes" do |
178 | 178 | allow(Clock).to receive(:monotonic_time).and_return(200.0, 202.0, 204.0, 206.0) |
179 | 179 |
|
180 | | - result = described_class.call( |
181 | | - question_message:, |
182 | | - answer_message:, |
183 | | - ) |
| 180 | + result = described_class.call(answer) |
184 | 181 |
|
185 | 182 | expect(result) |
186 | 183 | .to be_a(AutoEvaluation::ScoreResult) |
|
0 commit comments