Skip to content

Commit

Permalink
Populate runs.model from the name of the assistant's language_model
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-buckmaster committed May 16, 2024
1 parent 668b94c commit 6f3fbd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/models/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class Run < ApplicationRecord

enum status: %w[queued in_progress requires_action cancelling cancelled failed completed expired].index_by(&:to_sym)

validates :status, :expired_at, :instructions, presence: true
before_validation :set_model, on: :create
validates :status, :expired_at, :model, :instructions, presence: true
validates :tools, :file_ids, presence: true, allow_blank: true

private

def set_model
self.model = assistant&.language_model&.name
end
end
11 changes: 11 additions & 0 deletions test/models/run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class RunTest < ActiveSupport::TestCase
end
end

test "model populated from assistant" do
r = Run.create!(
assistant: assistants(:keith_claude3),
conversation: conversations(:greeting),
instructions: "Some instructions",
status: "queued",
expired_at: 1.minute.from_now
)
assert_equal 'claude-3-opus-20240229', r.model
end

test "associations are deleted upon destroy" do
assert_difference "Step.count", -1 do
runs(:hear_me_response).destroy
Expand Down

0 comments on commit 6f3fbd0

Please sign in to comment.