Skip to content

Commit

Permalink
some progress, so much more
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Oct 28, 2024
1 parent b2a2533 commit 6114688
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ GEM
faraday-net_http (3.3.0)
net-http
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
font-awesome-sass (6.5.2)
sassc (~> 2.0)
Expand Down Expand Up @@ -278,6 +279,8 @@ GEM
nio4r (2.7.3)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
numo-narray (0.9.2.1)
Expand Down Expand Up @@ -507,6 +510,7 @@ GEM

PLATFORMS
aarch64-linux
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/ai_judges_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class AiJudgesController < ApplicationController
def create
@book = Book.find(params[:book_id])
@user = User.find(params[:user_id])

@ai_user = AiJudge.new(book: @book, user: @user)

if @ai_user.save
redirect_to @book, notice: 'User was successfully added as an AI Judge.'
else
render :new
end
end

def destroy
@ai_judge = User.find(params[:id])
@book = Book.find(params[:book_id])
@book.judge
@ai_user.destroy
redirect_to @ai_user.book, notice: 'AI Judge was successfully removed.'
end
end
3 changes: 2 additions & 1 deletion app/jobs/run_judge_judy_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class RunJudgeJudyJob < ApplicationJob
sidekiq_options log_level: :warn

def perform book
judge = book.ai_judge
#judge = book.ai_judge
judge = nil
if judge # only run the job if we have a judge defined
loop do
query_doc_pair = SelectionStrategy.random_query_doc_based_on_strategy(book, judge)
Expand Down
11 changes: 8 additions & 3 deletions app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# support_implicit_judgements :boolean
# created_at :datetime not null
# updated_at :datetime not null
# ai_judge_id :integer
# owner_id :integer
# scorer_id :integer
# selection_strategy_id :bigint not null
Expand All @@ -33,8 +32,14 @@ class Book < ApplicationRecord
belongs_to :owner,
class_name: 'User', optional: true

belongs_to :ai_judge,
class_name: 'User', optional: true
#belongs_to :ai_judge,
# class_name: 'User', optional: true
#
#has_many :users, dependent: :destroy
#has_many :ai_judges, through: :ai_judges
has_and_belongs_to_many :ai_judges,
class_name: 'User',
join_table: 'ai_judges'

belongs_to :selection_strategy
belongs_to :scorer
Expand Down
11 changes: 9 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class User < ApplicationRecord
has_many :shared_scorers,
through: :teams,
source: :scorers

has_many :permissions,
dependent: :destroy

Expand All @@ -120,6 +120,9 @@ class User < ApplicationRecord
dependent: :destroy

has_many :announcements, foreign_key: 'author_id', dependent: :destroy, inverse_of: :author

#has_many :ai_judges, dependent: :destroy
#has_many :books, through: :ai_judges

# Validations

Expand Down Expand Up @@ -210,7 +213,11 @@ def store_raw_invitation_token

# Scopes
# default_scope -> { includes(:permissions) }
scope :ai_judges, -> { where('`users`.`openai_key` IS NOT NULL') }
scope :only_ai_judges, -> { where('`users`.`openai_key` IS NOT NULL') }

def ai_judge?
return !openai_key.nil?
end

def num_queries
queries.count
Expand Down
19 changes: 18 additions & 1 deletion app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,29 @@
<div class="mb-3">
<%= form.label :ai_judge_id, class: 'form-label' %>
<%
ai_judges = book.teams.collect{|team| team.members.ai_judges }.flatten
ai_judges = book.ai_judges
%>
<%= form.collection_select(:ai_judge_id, ai_judges, :id, :name, { include_blank: true, prompt: true }, required: false, class: 'form-control') %>
<div class="form-text">You can specify an AI powered Judge to evaluate this book. This list is derived from Judges created for your teams, so you must associate the book with a team first!</div>
</div>

<div class="mb-3">
<%= form_with(url: book_ai_judges_path(@book), method: :post) do |form| %>
<%= select_tag 'user_id', options_from_collection_for_select(@book.teams.collect{|team| team.members.only_ai_judges }.flatten, :id, :name) %>
<%= form.submit 'Add AI Judge' %>
<% end %>
</div>

<h3>AI Judges</h3>
<ul>
<% @book.ai_judges.each do |user| %>
<li>
<%= user.name %>
<%= button_to 'Remove', book_ai_judge_path(@book, user), method: :delete, class: 'btn btn-danger btn-sm' %>
</li>
<% end %>
</ul>

<div class="mb-3">
<%= form.label :show_rank, class: 'form-check-label' %>
<%= form.check_box :show_rank, class: 'form-check-input' %>
Expand Down
11 changes: 8 additions & 3 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ This book consists of <%= @book.query_doc_pairs.count %> query document pairs an

<%= render 'judgements/moar_judgements_needed', book: @book %>
<% if @book.ai_judge %>
We have an AI Judge, <i><%= @book.ai_judge.fullname %></i> helping us.
<% if !@book.ai_judges.empty? %>
We have some AI Judges, <i><%= @book.ai_judges.map(&:name).to_sentence %></i> helping us.
<br/>
<%= button_to 'Run Judgment Process', run_judge_judy_book_path(@book), method: :patch %>
<p/>
Expand Down Expand Up @@ -174,7 +174,12 @@ This book consists of <%= @book.query_doc_pairs.count %> query document pairs an
<tbody>
<% @stats_data.each do | row | %>
<tr>
<th scope="row"><%=display_judge_name (row[:judge]) %></th>
<th scope="row">
<%=display_judge_name (row[:judge]) %>
<% if row[:judge] && row[:judge].ai_judge? %>
<i class="bi bi-robot"></i>
<% end %>
</th>
<td>
<% if row[:judge] %>
<%=row[:unrateable] %> <%= link_to_if(row[:judge] && row[:unrateable] > 0, "reset", reset_unrateable_book_path(@book,row[:judge].id), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" }){ '' } %>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@

resources :books do
resources :judgements
resources :ai_judges
resources :query_doc_pairs do
resources :judgements
resources :judgements
post 'unrateable' => 'judgements#unrateable'
patch 'unrateable' => 'judgements#unrateable'
get 'judge_later' => 'judgements#judge_later'
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20241017005156_create_ai_judges_join_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateAiJudgesJoinTable < ActiveRecord::Migration[7.2]
def change
create_table :ai_judges do |t|
t.references :book, null: false, foreign_key: true
# user doesn't have explicit fk because the id are different types
t.references :user, null: false #, foreign_key: true
t.timestamps
end

add_index :ai_judges, [:book_id, :user_id], unique: true
end
end
14 changes: 12 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/fixtures/books.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# support_implicit_judgements :boolean
# created_at :datetime not null
# updated_at :datetime not null
# ai_judge_id :integer
# owner_id :integer
# scorer_id :integer
# selection_strategy_id :bigint not null
Expand Down
2 changes: 1 addition & 1 deletion test/integration/judge_judy_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JudgeJudyFlowTest < ActionDispatch::IntegrationTest
judge_judy.teams << team
judge_judy.save!
# Add her to the book as the judge. Like owner_id but it's ai_judge_id
book.ai_judge = judge_judy
#book.ai_judge = judge_judy
book.save!

# Wait for her to judge
Expand Down
1 change: 0 additions & 1 deletion test/models/book_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# support_implicit_judgements :boolean
# created_at :datetime not null
# updated_at :datetime not null
# ai_judge_id :integer
# owner_id :integer
# scorer_id :integer
# selection_strategy_id :bigint not null
Expand Down

0 comments on commit 6114688

Please sign in to comment.