|
3 | 3 | RSpec.describe "Managing Embeddings configurations", type: :system, js: true do |
4 | 4 | fab!(:admin) |
5 | 5 | let(:page_header) { PageObjects::Components::DPageHeader.new } |
| 6 | + let(:form) { PageObjects::Components::FormKit.new("form") } |
6 | 7 |
|
7 | 8 | before { sign_in(admin) } |
8 | 9 |
|
|
16 | 17 |
|
17 | 18 | find("[data-preset-id='text-embedding-3-small'] button").click() |
18 | 19 |
|
19 | | - find(".form-kit__control-password").fill_in(with: api_key) |
20 | | - find(".ai-embedding-editor__save").click() |
| 20 | + form.field("api_key").fill_in(api_key) |
| 21 | + form.submit |
21 | 22 |
|
22 | 23 | expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-embeddings") |
23 | 24 |
|
|
45 | 46 |
|
46 | 47 | find("[data-preset-id='manual'] button").click() |
47 | 48 |
|
48 | | - find("#control-display_name input").fill_in(with: "text-embedding-3-small") |
49 | | - |
50 | | - find("#control-provider select").select(EmbeddingDefinition::OPEN_AI) |
51 | | - |
52 | | - find("#control-url input").fill_in(with: "https://api.openai.com/v1/embeddings") |
53 | | - find("#control-api_key input").fill_in(with: api_key) |
54 | | - |
55 | | - find("#control-tokenizer_class select").select("OpenAiTokenizer") |
| 49 | + # Use the FormKit helper to fill in the form fields |
| 50 | + form.field("display_name").fill_in("text-embedding-3-small") |
| 51 | + form.field("provider").select(EmbeddingDefinition::OPEN_AI) |
| 52 | + form.field("url").fill_in("https://api.openai.com/v1/embeddings") |
| 53 | + form.field("api_key").fill_in(api_key) |
| 54 | + form.field("tokenizer_class").select("DiscourseAi::Tokenizer::OpenAiTokenizer") |
56 | 55 |
|
57 | 56 | embed_prefix = "On creation:" |
58 | 57 | search_prefix = "On search:" |
59 | | - find("#control-embed_prompt textarea").fill_in(with: embed_prefix) |
60 | | - find("#control-search_prompt textarea").fill_in(with: search_prefix) |
61 | | - find("#control-dimensions input").fill_in(with: 1536) |
62 | | - find("#control-max_sequence_length input").fill_in(with: 8191) |
| 58 | + form.field("embed_prompt").fill_in(embed_prefix) |
| 59 | + form.field("search_prompt").fill_in(search_prefix) |
| 60 | + form.field("dimensions").fill_in(1536) |
| 61 | + form.field("max_sequence_length").fill_in(8191) |
| 62 | + form.field("pg_function").select("<=>") |
63 | 63 |
|
64 | | - find("#control-pg_function select").select("Cosine distance") |
65 | | - |
66 | | - find(".ai-embedding-editor__save").click() |
| 64 | + form.submit |
67 | 65 |
|
68 | 66 | expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-embeddings") |
69 | 67 |
|
70 | 68 | embedding_def = EmbeddingDefinition.order(:id).last |
| 69 | + |
71 | 70 | expect(embedding_def.api_key).to eq(api_key) |
72 | 71 |
|
73 | 72 | preset = EmbeddingDefinition.presets.find { |p| p[:preset_id] == "text-embedding-3-small" } |
|
0 commit comments