Skip to content

Commit

Permalink
Correctly import by slug
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Nov 26, 2024
1 parent 2512211 commit b5621a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/assistant/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def import_from_file(path: Rails.root.join(DEFAULT_ASSISTANT_FILE), users: User.
assistants.each do |assistant|
assistant = assistant.with_indifferent_access
users.each do |user|
asst = user.assistants.find_or_create_by(name: assistant["name"])
asst.assign_attributes(assistant.except("name"))
asst = user.assistants.find_or_create_by(slug: assistant["slug"])
asst.assign_attributes(assistant.except("slug"))
asst.save!
end
end
Expand Down
3 changes: 3 additions & 0 deletions assistants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ assistants:
- name: GPT-4o
slug: gpt-4o
language_model_api_name: gpt-4o
- name: GPT-4o Mini
slug: gpt-4o-mini
language_model_api_name: gpt-4o-mini
- name: Claude 3.5 Sonnet
slug: claude-sonnet
language_model_api_name: claude-3-5-sonnet-20241022
Expand Down
14 changes: 6 additions & 8 deletions test/models/assistant/export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Assistant::ExportTest < ActiveSupport::TestCase
assert File.exist?(path)
storage = JSON.load_file(path)
assistants = storage["assistants"]
assert_equal assistants.first.keys.sort, %w[name description instructions tools language_model_api_name].sort
assert_equal assistants.first.keys.sort, %w[name description instructions slug language_model_api_name].sort
end

test "export_to_file yaml" do
Expand All @@ -30,7 +30,7 @@ class Assistant::ExportTest < ActiveSupport::TestCase
assert File.exist?(path)
storage = YAML.load_file(path)
assistants = storage["assistants"]
assert_equal assistants.first.keys.sort, %w[name description instructions tools language_model_api_name].sort
assert_equal assistants.first.keys.sort, %w[name description instructions slug language_model_api_name].sort
end

test "import_from_file with only new models" do
Expand Down Expand Up @@ -77,15 +77,14 @@ class Assistant::ExportTest < ActiveSupport::TestCase
assert user.assistants.find_by(external_id: "new external_id")
end

test "import_from_file with existing models by name" do
test "import_from_file with existing models by slug" do
user = users(:keith)
assistant = user.assistants.not_deleted.first
assistants = [{
name: assistant.name,
name: "new name",
slug: assistant.slug,
description: "new description",
instructions: "new instructions",
tools: "new tools",
external_id: "new external_id",
language_model_api_name: language_models(:gpt_4o).api_name
}]
storage = {
Expand All @@ -97,10 +96,9 @@ class Assistant::ExportTest < ActiveSupport::TestCase
Assistant.import_from_file(path:, users: [user])
end
assistant.reload
assert_equal "new name", assistant.name
assert_equal "new description", assistant.description
assert_equal "new instructions", assistant.instructions
assert_equal "new tools", assistant.tools
assert_equal "new external_id", assistant.external_id
assert_equal language_models(:gpt_4o).api_name, assistant.language_model_api_name
end
end

0 comments on commit b5621a2

Please sign in to comment.