Skip to content

Commit bb32de5

Browse files
Update assistants/language_models link, add LanguageModel constants according to the ids used in the migration
1 parent ffe6de5 commit bb32de5

13 files changed

Lines changed: 79 additions & 111 deletions

File tree

app/jobs/get_next_ai_message_job.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ class WaitForPrevious < StandardError; end
55
retry_on WaitForPrevious, wait: ->(run) { (2**run - 1).seconds }, attempts: 3
66

77
def ai_backend
8-
if @assistant.model.starts_with?('gpt-')
9-
AIBackends::OpenAI
10-
else
11-
AIBackends::Anthropic
12-
end
8+
@assistant.language_model.ai_backend
139
end
1410

1511
def perform(user_id, message_id, assistant_id, attempt = 1)

app/models/assistant.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ class Assistant < ApplicationRecord
99

1010
belongs_to :language_model, required: false
1111

12-
def model=(model_name)
13-
self.language_model_id = LanguageModel.where(name: model_name).first.id
14-
end
15-
16-
def model
17-
self.language_model.name
18-
end
19-
2012
validates :tools, presence: true, allow_blank: true
2113

2214
MAX_LIST_DISPLAY = 5

app/models/concerns/user/registerable.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module User::Registerable
88
private
99

1010
def create_initial_assistants
11-
assistants.create! name: "GPT (best)", model: "gpt-best", images: true
12-
assistants.create! name: "GPT-3.5", model: "gpt-3.5-turbo-0125", images: false
13-
assistants.create! name: "Claude (best)", model: "claude-best", images: true
14-
assistants.create! name: "Claude 3 Sonnet", model: "claude-3-sonnet-20240229", images: true
11+
assistants.create! name: "GPT (best)", language_model_id: LanguageModel::GPT_BEST_ID, images: true
12+
assistants.create! name: "GPT-3.5", language_model_id: LanguageModel::GPT_3_5_ID, images: false
13+
assistants.create! name: "Claude (best)", language_model_id: LanguageModel::CLAUDE_BEST_ID, images: true
14+
assistants.create! name: "Claude 3 Sonnet", language_model_id: LanguageModel::CLAUDE_3_SONNET_ID, images: true
1515
end
1616
end

app/models/language_model.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
# We don't care about large or not
22
class LanguageModel < ApplicationRecord
3-
def readonly?() = !new_record?
4-
def before_destroy() = raise ActiveRecord::ReadOnlyRecord
3+
def readonly?() = !new_record?
4+
def before_destroy() = raise ActiveRecord::ReadOnlyRecord
55

6-
PROVIDER_ID_MAP = {'gpt-best': 'gpt-4-turbo',
6+
PROVIDER_ID_MAP = {'gpt-best': 'gpt-4-turbo',
77
'claude-best': 'claude-3-opus-20240229'}
8-
def provider_id
9-
PROVIDER_ID_MAP[self.name.to_sym] || self.name unless self.name =~ /^best/
10-
end
8+
9+
GPT_BEST_ID = 1
10+
CLAUDE_BEST_ID = 2
11+
GPT_3_5_ID = 12
12+
CLAUDE_3_SONNET_ID = 18
13+
14+
def provider_id
15+
PROVIDER_ID_MAP[self.name.to_sym] || self.name unless self.name =~ /^best/
16+
end
17+
18+
def ai_backend
19+
if name.starts_with?('gpt-')
20+
AIBackends::OpenAI
21+
else
22+
AIBackends::Anthropic
23+
end
24+
end
1125
end

app/models/run.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class Run < ApplicationRecord
77

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

10-
validates :status, :expired_at, :model, :instructions, presence: true
10+
validates :status, :expired_at, :instructions, presence: true
1111
validates :tools, :file_ids, presence: true, allow_blank: true
1212
end

app/views/assistants/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<p class="my-5">
1111
<strong class="block font-medium mb-1">Model:</strong>
12-
<%= @assistant.model %>
12+
<%= @assistant.language_model.description %>
1313
</p>
1414

1515
<p class="my-5">

db/migrate/20240515080700_create_language_models.rb

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ def up
99

1010
# Currently supported models
1111
{
12-
'gpt-best': 'Best OpenAI Model',
13-
'claude-best': 'Best Anthropic Model',
14-
15-
'gpt-4': 'ChatGPT 4',
16-
'gpt-4-turbo': 'ChatGPT 4 Turbo with Vision (may update in future)',
17-
'gpt-4-turbo-2024-04-09': 'ChatGPT-4 Turbo with Vision (2024-04-09)',
18-
'gpt-4-turbo-preview': 'ChatGPT 4 Turbo Preview',
19-
'gpt-4-0125-preview': 'ChatGPT 4 Turbo Preview (2024-01-25)',
20-
'gpt-4-1106-preview': 'ChatGPT 4 Turbo Preview (2023-11-06)',
21-
'gpt-4-vision-preview': 'ChatGPT 4 Turbo Model preview with the ability to understand images (2023-11-06)',
22-
'gpt-4-1106-vision-preview': 'ChatGPT 4 Turbo preview with the ability to understand images (2023-11-06)',
23-
'gpt-4-0613': 'ChatGPT 4 Snapshot improved function calling (2023-06-13)',
24-
25-
'gpt-3.5-turbo': 'ChatGPT 3.5 Turbo',
26-
'gpt-3.5-turbo-16k-0613': 'ChatGPT 3.5 Turbo (2022-06-13)',
27-
'gpt-3.5-turbo-0125': 'ChatGPT 3.5 Turbo (2022-01-25)',
28-
'gpt-3.5-turbo-1106': 'ChatGPT 3.5 Turbo (2022-11-06)',
29-
'gpt-3.5-turbo-instruct': 'ChatGPT 3.5 Turbo Instruct',
30-
31-
'claude-3-opus-20240229': 'Claude 3 Opus (2024-02-29)',
32-
'claude-3-sonnet-20240229': 'Claude 3 Sonnet (2024-02-29)',
33-
'claude-3-haiku-20240307': 'Claude 3 Haiku (2024-03-07)',
34-
'claude-2.1': 'Claude 2.1',
35-
'claude-2.0': 'Claude 2.0',
36-
'claude-instant-1.2': 'Claude Instant 1.2'
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'
3737
}.each do |name, description|
3838
LanguageModel.create(name: name, description: description)
3939
end
@@ -56,5 +56,7 @@ def down
5656

5757
remove_column :assistants, :language_model_id
5858
drop_table :language_models
59+
60+
remove_column :runs, :model
5961
end
6062
end

db/schema.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@
174174
t.datetime "cancelled_at", precision: nil
175175
t.datetime "failed_at", precision: nil
176176
t.datetime "completed_at", precision: nil
177-
t.string "model", null: false
178177
t.string "instructions"
179178
t.string "additional_instructions"
180179
t.jsonb "tools", default: [], null: false

test/controllers/assistants_controller_test.rb

Lines changed: 2 additions & 2 deletions
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, model: @assistant.model, name: @assistant.name, tools: @assistant.tools, user_id: @assistant.user_id}}
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}}
2323
end
2424

2525
assert_redirected_to assistant_url(Assistant.last)
@@ -36,7 +36,7 @@ class AssistantsControllerTest < ActionDispatch::IntegrationTest
3636
end
3737

3838
test "should update assistant" do
39-
patch assistant_url(@assistant), params: {assistant: {description: @assistant.description, instructions: @assistant.instructions, model: @assistant.model, name: @assistant.name, tools: @assistant.tools, user_id: @assistant.user_id}}
39+
patch assistant_url(@assistant), params: {assistant: {description: @assistant.description, instructions: @assistant.instructions, language_model_id: @assistant.language_model_id, name: @assistant.name, tools: @assistant.tools, user_id: @assistant.user_id}}
4040
assert_redirected_to assistant_url(@assistant)
4141
end
4242

test/fixtures/assistants.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
samantha:
22
user: keith
3-
language_model_id: 123456
3+
language_model_id: 3
44
name: Samantha
55
description: My personal assistant
66
instructions: You are a helpful assistant
@@ -9,7 +9,7 @@ samantha:
99

1010
keith_gpt4:
1111
user: keith
12-
language_model_id: 12345678
12+
language_model_id: 3
1313
name: GPT-4
1414
description: OpenAI's GPT-4
1515
instructions:
@@ -18,7 +18,7 @@ keith_gpt4:
1818

1919
keith_claude3:
2020
user: keith
21-
language_model_id: 1234567
21+
language_model_id: 17
2222
name: Claude 3 Opus
2323
description: Claude 3, Opus version
2424
instructions:
@@ -27,7 +27,7 @@ keith_claude3:
2727

2828
rob_gpt4:
2929
user: rob
30-
language_model_id: 12345678
30+
language_model_id: 3
3131
name: GPT-4
3232
description: OpenAI's GPT-4
3333
instructions:

0 commit comments

Comments
 (0)