-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreason_generator.rb
More file actions
42 lines (34 loc) · 881 Bytes
/
reason_generator.rb
File metadata and controls
42 lines (34 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module AutoEvaluation
class Faithfulness::ReasonGenerator
def self.call(...) = new(...).call
def initialize(score:, verdicts:)
@score = score
@verdicts = verdicts
end
def call
result = BedrockOpenAIOssInvoke.call(user_prompt, tools)
[result.evaluation_data.fetch("reason"), result.llm_response, result.metrics]
end
private
attr_reader :score, :verdicts
def llm_prompts
Prompts.config
.faithfulness
.fetch(:reason)
end
def user_prompt
sprintf(
llm_prompts.fetch(:user_prompt),
score:,
contradictions:,
)
end
def tools
[llm_prompts.fetch(:tool_spec)]
end
def contradictions
verdicts.select { |verdict| verdict["verdict"].strip.downcase == "no" }
.map { |verdict| verdict["reason"] }
end
end
end