Skip to content

Commit bb942cd

Browse files
committed
Try to have some helpers that are judge specific.
1 parent 79c397d commit bb942cd

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

app/models/user.rb

+18-4
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ class User < ApplicationRecord
122122

123123
validates :password,
124124
presence: true,
125-
length: { maximum: 80 }
125+
length: { maximum: 80 },
126+
unless: :ai_judge?
126127

127-
validates :password, confirmation: { message: 'should match confirmation' }
128+
validates :password, confirmation: { message: 'should match confirmation' }, unless: :ai_judge?
128129

129130
validates :reset_password_token,
130131
length: { maximum: 255 }
@@ -147,8 +148,6 @@ class User < ApplicationRecord
147148
validates :openai_key, length: { maximum: 255 }, allow_nil: true, presence: true, if: :ai_judge?
148149
validates :system_prompt, length: { maximum: 4000 }, allow_nil: true, presence: true, if: :ai_judge?
149150

150-
# serialize :options, coder: JSON
151-
152151
def terms_and_conditions?
153152
Rails.application.config.terms_and_conditions_url.present?
154153
end
@@ -276,6 +275,21 @@ def unseen_app_notifications
276275
.order(:created_at)
277276
end
278277

278+
def judge_options
279+
# ugh, why isn't this :judge_options?
280+
opts = options&.dig('judge_options') || {}
281+
opts.deep_symbolize_keys
282+
end
283+
284+
def judge_options= value
285+
# Initialize options as empty hash if nil
286+
self.options ||= {}
287+
288+
# Set the judge_options within options
289+
self.options = options.merge(judge_options: value)
290+
pp self.options
291+
end
292+
279293
private
280294

281295
def set_defaults

test/models/user_test.rb

+41-3
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class UserTest < ActiveSupport::TestCase
325325
end
326326

327327
describe 'User is AI Judge' do
328+
let(:joey) { users(:joey) }
328329
it 'uses the existence of the key to decide ai_judge' do
329330
user = User.new
330331
assert_not user.ai_judge?
@@ -333,13 +334,50 @@ class UserTest < ActiveSupport::TestCase
333334
assert_not user.valid?
334335
end
335336

336-
it 'does not require an email address to be valid when is a judge' do
337+
it 'does not require an email or password address to be valid when is a judge' do
337338
user = User.new(openai_key: '1234')
338339
assert user.ai_judge?
339-
340-
user.password = 'fakeme'
341340
assert user.valid?
342341
end
342+
343+
describe 'options to configure the llm server' do
344+
it 'provides an empty hash' do
345+
user = User.new(openai_key: '1234')
346+
opts_hash = user.judge_options
347+
assert_equal({}, opts_hash)
348+
end
349+
350+
it 'lets you update the options hash' do
351+
user = User.new(openai_key: '1234')
352+
opts_hash = user.judge_options
353+
354+
opts_hash[:model] = 'gpt-3.5-turbo'
355+
assert_equal('gpt-3.5-turbo', opts_hash[:model])
356+
user.save!
357+
user.reload
358+
assert_equal('gpt-3.5-turbo', user.judge_options[:model])
359+
end
360+
361+
it 'works with other prexisting options' do
362+
joey.options = { special_options: { key1: 'opt1', key2: 2, key3: true } }
363+
assert joey.save
364+
# joey.judge_options[:model] = 'gpt-3.5-turbo'
365+
# Do not do this, it won't work. You need to work with the full hash
366+
# joey.judge_options = 'gpt-3.5-turbo'
367+
judge_options = joey.judge_options
368+
judge_options[:model] = 'gpt-3.5-turbo'
369+
joey.judge_options = judge_options
370+
assert joey.save!
371+
joey.reload
372+
373+
puts 'optons'
374+
puts joey.options
375+
376+
judge_options = joey.judge_options
377+
pp judge_options
378+
assert_equal('gpt-3.5-turbo', judge_options[:model])
379+
end
380+
end
343381
end
344382

345383
describe 'The full name of the user' do

0 commit comments

Comments
 (0)