Skip to content

Commit

Permalink
Fixed migration, also left model column in the runs table
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-buckmaster committed May 16, 2024
1 parent abf9cf5 commit 668b94c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 40 deletions.
2 changes: 1 addition & 1 deletion app/models/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Assistant < ApplicationRecord
has_many :steps, dependent: :destroy
has_many :messages # TODO: What should happen if an assistant is deleted?

belongs_to :language_model, required: false
belongs_to :language_model

validates :tools, presence: true, allow_blank: true

Expand Down
74 changes: 40 additions & 34 deletions db/migrate/20240515080700_create_language_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,62 @@ def up
t.timestamps
end

# Currently supported models
{
1, 'gpt-best': 'Best OpenAI Model',
2, 'claude-best': 'Best Anthropic Model',

3, 'gpt-4': 'ChatGPT 4',
4, 'gpt-4-turbo': 'ChatGPT 4 Turbo with Vision (may update in future)',
5, 'gpt-4-turbo-2024-04-09': 'ChatGPT-4 Turbo with Vision (2024-04-09)',
6, 'gpt-4-turbo-preview': 'ChatGPT 4 Turbo Preview',
7, 'gpt-4-0125-preview': 'ChatGPT 4 Turbo Preview (2024-01-25)',
8, 'gpt-4-1106-preview': 'ChatGPT 4 Turbo Preview (2023-11-06)',
9, 'gpt-4-vision-preview': 'ChatGPT 4 Turbo Model preview with the ability to understand images (2023-11-06)',
10, 'gpt-4-1106-vision-preview': 'ChatGPT 4 Turbo preview with the ability to understand images (2023-11-06)',
11, 'gpt-4-0613': 'ChatGPT 4 Snapshot improved function calling (2023-06-13)',

12, 'gpt-3.5-turbo': 'ChatGPT 3.5 Turbo',
13, 'gpt-3.5-turbo-16k-0613': 'ChatGPT 3.5 Turbo (2022-06-13)',
14, 'gpt-3.5-turbo-0125': 'ChatGPT 3.5 Turbo (2022-01-25)',
15, 'gpt-3.5-turbo-1106': 'ChatGPT 3.5 Turbo (2022-11-06)',
16, 'gpt-3.5-turbo-instruct': 'ChatGPT 3.5 Turbo Instruct',

17, 'claude-3-opus-20240229': 'Claude 3 Opus (2024-02-29)',
18, 'claude-3-sonnet-20240229': 'Claude 3 Sonnet (2024-02-29)',
19, 'claude-3-haiku-20240307': 'Claude 3 Haiku (2024-03-07)',
20, 'claude-2.1': 'Claude 2.1',
21, 'claude-2.0': 'Claude 2.0',
22, 'claude-instant-1.2': 'Claude Instant 1.2'
}.each do |name, description|
LanguageModel.create(name: name, description: description)
# Initially supported models
[
[1, 'gpt-best', 'Best OpenAI Model'],
[2, 'claude-best', 'Best Anthropic Model'],

[3, 'gpt-4', 'ChatGPT 4'],
[4, 'gpt-4-turbo', 'ChatGPT 4 Turbo with Vision (may update in future)'],
[5, 'gpt-4-turbo-2024-04-09', 'ChatGPT-4 Turbo with Vision (2024-04-09)'],
[6, 'gpt-4-turbo-preview', 'ChatGPT 4 Turbo Preview'],
[7, 'gpt-4-0125-preview', 'ChatGPT 4 Turbo Preview (2024-01-25)'],
[8, 'gpt-4-1106-preview', 'ChatGPT 4 Turbo Preview (2023-11-06)'],
[9, 'gpt-4-vision-preview', 'ChatGPT 4 Turbo Model preview with the ability to understand images (2023-11-06)'],
[10, 'gpt-4-1106-vision-preview', 'ChatGPT 4 Turbo preview with the ability to understand images (2023-11-06)'],
[11, 'gpt-4-0613', 'ChatGPT 4 Snapshot improved function calling (2023-06-13)'],

[12, 'gpt-3.5-turbo', 'ChatGPT 3.5 Turbo'],
[13, 'gpt-3.5-turbo-16k-0613', 'ChatGPT 3.5 Turbo (2022-06-13)'],
[14, 'gpt-3.5-turbo-0125', 'ChatGPT 3.5 Turbo (2022-01-25)'],
[15, 'gpt-3.5-turbo-1106', 'ChatGPT 3.5 Turbo (2022-11-06)'],
[16, 'gpt-3.5-turbo-instruct', 'ChatGPT 3.5 Turbo Instruct'],

[17, 'claude-3-opus-20240229', 'Claude 3 Opus (2024-02-29)'],
[18, 'claude-3-sonnet-20240229', 'Claude 3 Sonnet (2024-02-29)'],
[19, 'claude-3-haiku-20240307', 'Claude 3 Haiku (2024-03-07)'],
[20, 'claude-2.1', 'Claude 2.1'],
[21, 'claude-2.0', 'Claude 2.0'],
[22, 'claude-instant-1.2', 'Claude Instant 1.2']
].each do |db_id, name, description|
record = LanguageModel.new(name: name, description: description)
record.id = db_id
record.save!
end

ActiveRecord::Base.connection.execute "ALTER SEQUENCE language_models_id_seq RESTART WITH 30;"

# Respect some users who may have added their own model values in the assistants table
(Assistant.all.pluck(:model).uniq - LanguageModel.all.pluck(:name)).each do |model_name|
LanguageModel.create(name: model_name, description: '???')
Rails.logger.info "Create language_models record from assistants column value: #{model_name.inspect}"
LanguageModel.create!(name: model_name, description: model_name)
end

add_reference :assistants, :language_model, null: true, foreign_key: { to_table: :language_models}

ActiveRecord::Base.connection.execute 'update assistants a set language_model_id = (select id from language_models lm where lm.name = a.model)'
Assistant.all.each do |a|
Rails.logger.info "Have assistant #{a.id} with model #{a.model}"
end
ActiveRecord::Base.connection.execute "update assistants a set language_model_id = (select id from language_models lm where lm.name = a.model)"

remove_column :assistants, :model
end

def down
add_column :assistants, :model, :string
ActiveRecord::Base.connection.execute 'update assistants a set model = (select name from language_models lm where lm.id = a.language_model_id)'
ActiveRecord::Base.connection.execute "update assistants a set model = (select name from language_models lm where lm.id=a.language_model_id)"

remove_column :assistants, :language_model_id
drop_table :language_models

remove_column :runs, :model
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
t.jsonb "file_ids", default: [], null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "model"
t.index ["assistant_id"], name: "index_runs_on_assistant_id"
t.index ["conversation_id"], name: "index_runs_on_conversation_id"
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/assistants_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AssistantsControllerTest < ActionDispatch::IntegrationTest

test "should create assistant" do
assert_difference("Assistant.count") do
post assistants_url, params: {assistant: {description: @assistant.description, instructions: @assistant.instructions, alnguage_model_id: 1, name: @assistant.name, tools: @assistant.tools, user_id: @assistant.user_id}}
post assistants_url, params: {assistant: {description: @assistant.description, instructions: @assistant.instructions, language_model_id: 1, name: @assistant.name, tools: @assistant.tools, user_id: @assistant.user_id}}
end

assert_redirected_to assistant_url(Assistant.last)
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/settings/assistants_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class Settings::AssistantsControllerTest < ActionDispatch::IntegrationTest
end

test "should create assistant" do
params = assistants(:samantha).slice(:name, :description, :instructions)
params = assistants(:samantha).slice(:name, :description, :instructions, :language_model_id)

assert_difference("Assistant.count") do
post settings_assistants_url, params: { assistant: params }
end

assert_redirected_to edit_settings_assistant_url(Assistant.last)
assert_nil flash[:error]
assert_equal params, Assistant.last.slice(:name, :description, :instructions)
assert_equal params, Assistant.last.slice(:name, :description, :instructions, :language_model_id)
end

test "should get edit" do
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/runs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hear_me_response:
expired_at: 2023-12-25 15:05:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -24,6 +25,7 @@ identify_photo_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -40,6 +42,7 @@ what_day_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -55,6 +58,7 @@ alive_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -70,6 +74,7 @@ your_name_response:
expired_at: 2023-12-25 15:05:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -85,6 +90,7 @@ examine_this_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -101,6 +107,7 @@ what_month_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -116,6 +123,7 @@ human_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -131,6 +139,7 @@ can_you_hear_response:
expired_at: 2023-12-25 15:05:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -146,6 +155,7 @@ one_attachment_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -162,6 +172,7 @@ two_attachments_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -178,6 +189,7 @@ popstate_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions:
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -193,6 +205,7 @@ ruby_version_response:
expired_at: 2023-12-25 15:08:41
cancelled_at:
failed_at:
model: gpt-4
instructions:
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -208,6 +221,7 @@ filter_map_response:
expired_at: 2023-12-27 15:05:41
cancelled_at:
failed_at:
model: gpt-4
instructions:
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -223,6 +237,7 @@ message0_v1_response:
expired_at: 2023-1-1 1:01:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -238,6 +253,7 @@ message2_v1_response:
expired_at: 2023-1-1 1:03:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -253,6 +269,7 @@ message2_v2_response:
expired_at: 2023-1-1 1:05:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -268,6 +285,7 @@ message4_v2_response:
expired_at: 2023-1-1 1:07:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -283,6 +301,7 @@ msg0_v1_response:
expired_at: 2023-1-1 1:07:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -298,6 +317,7 @@ msg2_v1_response:
expired_at: 2023-1-1 1:07:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
Expand All @@ -313,6 +333,7 @@ msg3_v2_response:
expired_at: 2023-1-1 1:07:00
cancelled_at:
failed_at:
model: gpt-4
instructions: You are a helpful assistant
additional_instructions:
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
4 changes: 2 additions & 2 deletions test/models/assistant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class AssistantTest < ActiveSupport::TestCase

test "simple create works" do
assert_nothing_raised do
Assistant.create!(user: users(:keith))
Assistant.create!(user: users(:keith), language_model_id: 1)
end
end

test "tools defaults to empty array on create" do
a = Assistant.create!(user: users(:keith))
a = Assistant.create!(user: users(:keith), language_model_id: 1)
assert_equal [], a.tools
end

Expand Down

0 comments on commit 668b94c

Please sign in to comment.