Skip to content

Commit 668b94c

Browse files
Fixed migration, also left model column in the runs table
1 parent abf9cf5 commit 668b94c

File tree

7 files changed

+68
-40
lines changed

7 files changed

+68
-40
lines changed

app/models/assistant.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Assistant < ApplicationRecord
77
has_many :steps, dependent: :destroy
88
has_many :messages # TODO: What should happen if an assistant is deleted?
99

10-
belongs_to :language_model, required: false
10+
belongs_to :language_model
1111

1212
validates :tools, presence: true, allow_blank: true
1313

db/migrate/20240515080700_create_language_models.rb

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,62 @@ def up
77
t.timestamps
88
end
99

10-
# Currently supported models
11-
{
12-
1, 'gpt-best': 'Best OpenAI Model',
13-
2, 'claude-best': 'Best Anthropic Model',
14-
15-
3, 'gpt-4': 'ChatGPT 4',
16-
4, 'gpt-4-turbo': 'ChatGPT 4 Turbo with Vision (may update in future)',
17-
5, 'gpt-4-turbo-2024-04-09': 'ChatGPT-4 Turbo with Vision (2024-04-09)',
18-
6, 'gpt-4-turbo-preview': 'ChatGPT 4 Turbo Preview',
19-
7, 'gpt-4-0125-preview': 'ChatGPT 4 Turbo Preview (2024-01-25)',
20-
8, 'gpt-4-1106-preview': 'ChatGPT 4 Turbo Preview (2023-11-06)',
21-
9, 'gpt-4-vision-preview': 'ChatGPT 4 Turbo Model preview with the ability to understand images (2023-11-06)',
22-
10, 'gpt-4-1106-vision-preview': 'ChatGPT 4 Turbo preview with the ability to understand images (2023-11-06)',
23-
11, 'gpt-4-0613': 'ChatGPT 4 Snapshot improved function calling (2023-06-13)',
24-
25-
12, 'gpt-3.5-turbo': 'ChatGPT 3.5 Turbo',
26-
13, 'gpt-3.5-turbo-16k-0613': 'ChatGPT 3.5 Turbo (2022-06-13)',
27-
14, 'gpt-3.5-turbo-0125': 'ChatGPT 3.5 Turbo (2022-01-25)',
28-
15, 'gpt-3.5-turbo-1106': 'ChatGPT 3.5 Turbo (2022-11-06)',
29-
16, 'gpt-3.5-turbo-instruct': 'ChatGPT 3.5 Turbo Instruct',
30-
31-
17, 'claude-3-opus-20240229': 'Claude 3 Opus (2024-02-29)',
32-
18, 'claude-3-sonnet-20240229': 'Claude 3 Sonnet (2024-02-29)',
33-
19, 'claude-3-haiku-20240307': 'Claude 3 Haiku (2024-03-07)',
34-
20, 'claude-2.1': 'Claude 2.1',
35-
21, 'claude-2.0': 'Claude 2.0',
36-
22, 'claude-instant-1.2': 'Claude Instant 1.2'
37-
}.each do |name, description|
38-
LanguageModel.create(name: name, description: description)
10+
# Initially supported models
11+
[
12+
[1, 'gpt-best', 'Best OpenAI Model'],
13+
[2, 'claude-best', 'Best Anthropic Model'],
14+
15+
[3, 'gpt-4', 'ChatGPT 4'],
16+
[4, 'gpt-4-turbo', 'ChatGPT 4 Turbo with Vision (may update in future)'],
17+
[5, 'gpt-4-turbo-2024-04-09', 'ChatGPT-4 Turbo with Vision (2024-04-09)'],
18+
[6, 'gpt-4-turbo-preview', 'ChatGPT 4 Turbo Preview'],
19+
[7, 'gpt-4-0125-preview', 'ChatGPT 4 Turbo Preview (2024-01-25)'],
20+
[8, 'gpt-4-1106-preview', 'ChatGPT 4 Turbo Preview (2023-11-06)'],
21+
[9, 'gpt-4-vision-preview', 'ChatGPT 4 Turbo Model preview with the ability to understand images (2023-11-06)'],
22+
[10, 'gpt-4-1106-vision-preview', 'ChatGPT 4 Turbo preview with the ability to understand images (2023-11-06)'],
23+
[11, 'gpt-4-0613', 'ChatGPT 4 Snapshot improved function calling (2023-06-13)'],
24+
25+
[12, 'gpt-3.5-turbo', 'ChatGPT 3.5 Turbo'],
26+
[13, 'gpt-3.5-turbo-16k-0613', 'ChatGPT 3.5 Turbo (2022-06-13)'],
27+
[14, 'gpt-3.5-turbo-0125', 'ChatGPT 3.5 Turbo (2022-01-25)'],
28+
[15, 'gpt-3.5-turbo-1106', 'ChatGPT 3.5 Turbo (2022-11-06)'],
29+
[16, 'gpt-3.5-turbo-instruct', 'ChatGPT 3.5 Turbo Instruct'],
30+
31+
[17, 'claude-3-opus-20240229', 'Claude 3 Opus (2024-02-29)'],
32+
[18, 'claude-3-sonnet-20240229', 'Claude 3 Sonnet (2024-02-29)'],
33+
[19, 'claude-3-haiku-20240307', 'Claude 3 Haiku (2024-03-07)'],
34+
[20, 'claude-2.1', 'Claude 2.1'],
35+
[21, 'claude-2.0', 'Claude 2.0'],
36+
[22, 'claude-instant-1.2', 'Claude Instant 1.2']
37+
].each do |db_id, name, description|
38+
record = LanguageModel.new(name: name, description: description)
39+
record.id = db_id
40+
record.save!
3941
end
4042

43+
ActiveRecord::Base.connection.execute "ALTER SEQUENCE language_models_id_seq RESTART WITH 30;"
44+
4145
# Respect some users who may have added their own model values in the assistants table
4246
(Assistant.all.pluck(:model).uniq - LanguageModel.all.pluck(:name)).each do |model_name|
43-
LanguageModel.create(name: model_name, description: '???')
47+
Rails.logger.info "Create language_models record from assistants column value: #{model_name.inspect}"
48+
LanguageModel.create!(name: model_name, description: model_name)
4449
end
4550

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

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

5058
remove_column :assistants, :model
5159
end
5260

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

5765
remove_column :assistants, :language_model_id
5866
drop_table :language_models
59-
60-
remove_column :runs, :model
6167
end
6268
end

db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
t.jsonb "file_ids", default: [], null: false
181181
t.datetime "created_at", null: false
182182
t.datetime "updated_at", null: false
183+
t.string "model"
183184
t.index ["assistant_id"], name: "index_runs_on_assistant_id"
184185
t.index ["conversation_id"], name: "index_runs_on_conversation_id"
185186
end

test/controllers/assistants_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AssistantsControllerTest < ActionDispatch::IntegrationTest
1919

2020
test "should create assistant" do
2121
assert_difference("Assistant.count") do
22-
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}}
22+
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}}
2323
end
2424

2525
assert_redirected_to assistant_url(Assistant.last)

test/controllers/settings/assistants_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class Settings::AssistantsControllerTest < ActionDispatch::IntegrationTest
1212
end
1313

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

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

2121
assert_redirected_to edit_settings_assistant_url(Assistant.last)
2222
assert_nil flash[:error]
23-
assert_equal params, Assistant.last.slice(:name, :description, :instructions)
23+
assert_equal params, Assistant.last.slice(:name, :description, :instructions, :language_model_id)
2424
end
2525

2626
test "should get edit" do

test/fixtures/runs.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ hear_me_response:
99
expired_at: 2023-12-25 15:05:41
1010
cancelled_at:
1111
failed_at:
12+
model: gpt-4
1213
instructions: You are a helpful assistant
1314
additional_instructions:
1415
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -24,6 +25,7 @@ identify_photo_response:
2425
expired_at: 2023-12-25 15:08:41
2526
cancelled_at:
2627
failed_at:
28+
model: gpt-4
2729
instructions: You are a helpful assistant
2830
additional_instructions:
2931
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -40,6 +42,7 @@ what_day_response:
4042
expired_at: 2023-12-25 15:08:41
4143
cancelled_at:
4244
failed_at:
45+
model: gpt-4
4346
instructions: You are a helpful assistant
4447
additional_instructions:
4548
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -55,6 +58,7 @@ alive_response:
5558
expired_at: 2023-12-25 15:08:41
5659
cancelled_at:
5760
failed_at:
61+
model: gpt-4
5862
instructions: You are a helpful assistant
5963
additional_instructions:
6064
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -70,6 +74,7 @@ your_name_response:
7074
expired_at: 2023-12-25 15:05:41
7175
cancelled_at:
7276
failed_at:
77+
model: gpt-4
7378
instructions: You are a helpful assistant
7479
additional_instructions:
7580
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -85,6 +90,7 @@ examine_this_response:
8590
expired_at: 2023-12-25 15:08:41
8691
cancelled_at:
8792
failed_at:
93+
model: gpt-4
8894
instructions: You are a helpful assistant
8995
additional_instructions:
9096
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -101,6 +107,7 @@ what_month_response:
101107
expired_at: 2023-12-25 15:08:41
102108
cancelled_at:
103109
failed_at:
110+
model: gpt-4
104111
instructions: You are a helpful assistant
105112
additional_instructions:
106113
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -116,6 +123,7 @@ human_response:
116123
expired_at: 2023-12-25 15:08:41
117124
cancelled_at:
118125
failed_at:
126+
model: gpt-4
119127
instructions: You are a helpful assistant
120128
additional_instructions:
121129
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -131,6 +139,7 @@ can_you_hear_response:
131139
expired_at: 2023-12-25 15:05:41
132140
cancelled_at:
133141
failed_at:
142+
model: gpt-4
134143
instructions: You are a helpful assistant
135144
additional_instructions:
136145
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -146,6 +155,7 @@ one_attachment_response:
146155
expired_at: 2023-12-25 15:08:41
147156
cancelled_at:
148157
failed_at:
158+
model: gpt-4
149159
instructions: You are a helpful assistant
150160
additional_instructions:
151161
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -162,6 +172,7 @@ two_attachments_response:
162172
expired_at: 2023-12-25 15:08:41
163173
cancelled_at:
164174
failed_at:
175+
model: gpt-4
165176
instructions: You are a helpful assistant
166177
additional_instructions:
167178
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -178,6 +189,7 @@ popstate_response:
178189
expired_at: 2023-12-25 15:08:41
179190
cancelled_at:
180191
failed_at:
192+
model: gpt-4
181193
instructions:
182194
additional_instructions:
183195
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -193,6 +205,7 @@ ruby_version_response:
193205
expired_at: 2023-12-25 15:08:41
194206
cancelled_at:
195207
failed_at:
208+
model: gpt-4
196209
instructions:
197210
additional_instructions:
198211
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -208,6 +221,7 @@ filter_map_response:
208221
expired_at: 2023-12-27 15:05:41
209222
cancelled_at:
210223
failed_at:
224+
model: gpt-4
211225
instructions:
212226
additional_instructions:
213227
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -223,6 +237,7 @@ message0_v1_response:
223237
expired_at: 2023-1-1 1:01:00
224238
cancelled_at:
225239
failed_at:
240+
model: gpt-4
226241
instructions: You are a helpful assistant
227242
additional_instructions:
228243
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -238,6 +253,7 @@ message2_v1_response:
238253
expired_at: 2023-1-1 1:03:00
239254
cancelled_at:
240255
failed_at:
256+
model: gpt-4
241257
instructions: You are a helpful assistant
242258
additional_instructions:
243259
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -253,6 +269,7 @@ message2_v2_response:
253269
expired_at: 2023-1-1 1:05:00
254270
cancelled_at:
255271
failed_at:
272+
model: gpt-4
256273
instructions: You are a helpful assistant
257274
additional_instructions:
258275
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -268,6 +285,7 @@ message4_v2_response:
268285
expired_at: 2023-1-1 1:07:00
269286
cancelled_at:
270287
failed_at:
288+
model: gpt-4
271289
instructions: You are a helpful assistant
272290
additional_instructions:
273291
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -283,6 +301,7 @@ msg0_v1_response:
283301
expired_at: 2023-1-1 1:07:00
284302
cancelled_at:
285303
failed_at:
304+
model: gpt-4
286305
instructions: You are a helpful assistant
287306
additional_instructions:
288307
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -298,6 +317,7 @@ msg2_v1_response:
298317
expired_at: 2023-1-1 1:07:00
299318
cancelled_at:
300319
failed_at:
320+
model: gpt-4
301321
instructions: You are a helpful assistant
302322
additional_instructions:
303323
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]
@@ -313,6 +333,7 @@ msg3_v2_response:
313333
expired_at: 2023-1-1 1:07:00
314334
cancelled_at:
315335
failed_at:
336+
model: gpt-4
316337
instructions: You are a helpful assistant
317338
additional_instructions:
318339
tools: [{"type": "code_interpreter"}, {"type": "retrieval"}, {"type": "function"}]

test/models/assistant_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class AssistantTest < ActiveSupport::TestCase
3131

3232
test "simple create works" do
3333
assert_nothing_raised do
34-
Assistant.create!(user: users(:keith))
34+
Assistant.create!(user: users(:keith), language_model_id: 1)
3535
end
3636
end
3737

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

0 commit comments

Comments
 (0)