Skip to content

Commit

Permalink
Fix when exception is raised, there is no Judgement object to store i…
Browse files Browse the repository at this point in the history
…t in, so move that out of the service.
  • Loading branch information
epugh committed Jan 20, 2025
1 parent db7891c commit 63a1705
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/jobs/run_judge_judy_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def perform book, judge, number_of_pairs
query_doc_pair = SelectionStrategy.random_query_doc_based_on_strategy(book, judge)
break if query_doc_pair.nil?

judgement = Judgement.new(query_doc_pair: query_doc_pair, user: judge)
begin
judgement = llm_service.make_judgement(judge, query_doc_pair)
judgement = llm_service.perform_judgement(judgement)
rescue RuntimeError => e
case e.message
when /401/
raise # we can't do anything about this, so pass it up
else
judgement.explanation = "BOOM: #{e}"
judgement.explanation = "BOOM: #{e}"
judgement.unrateable = true
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/services/llm_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def initialize openai_key, _opts = {}
@openai_key = openai_key
end

def make_judgement judge, query_doc_pair
user_prompt = make_user_prompt query_doc_pair
results = get_llm_response user_prompt, judge.system_prompt
judgement = Judgement.new(query_doc_pair: query_doc_pair, user: judge)
def perform_judgement judgement
user_prompt = make_user_prompt judgement.query_doc_pair
results = get_llm_response user_prompt, judgement.user.system_prompt

judgement.rating = results[:judgment]
judgement.explanation = results[:explanation]

Expand Down
3 changes: 2 additions & 1 deletion test/services/llm_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class LlmServiceTest < ActiveSupport::TestCase
end

test 'creating a judgement' do
judgement = service.make_judgement judge, query_doc_pair
judgement = Judgement.new(query_doc_pair: query_doc_pair, user: judge)
judgement = service.perform_judgement judgement

assert_instance_of Float, judgement.rating
assert_not_nil judgement.explanation
Expand Down

0 comments on commit 63a1705

Please sign in to comment.