diff --git a/lib/configuration/embeddings_module_validator.rb b/lib/configuration/embeddings_module_validator.rb index 08db06925..bd5a38bc5 100644 --- a/lib/configuration/embeddings_module_validator.rb +++ b/lib/configuration/embeddings_module_validator.rb @@ -42,8 +42,9 @@ def error_message def can_generate_embeddings?(val) DiscourseAi::Embeddings::VectorRepresentations::Base .find_representation(val) - .new(DiscourseAi::Embeddings::Strategies::Truncation.new) - .vector_from("this is a test") + .new + .inference_client + .perform!("this is a test") .present? end end diff --git a/spec/lib/configuration/embeddings_module_validator_spec.rb b/spec/lib/configuration/embeddings_module_validator_spec.rb new file mode 100644 index 000000000..0b1e5713c --- /dev/null +++ b/spec/lib/configuration/embeddings_module_validator_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +RSpec.describe DiscourseAi::Configuration::EmbeddingsModuleValidator do + let(:validator) { described_class.new } + + describe "#can_generate_embeddings?" do + it "returns true if embeddings can be generated" do + stub_request( + :post, + "https://generativelanguage.googleapis.com/v1beta/models/embedding-001:embedContent?key=", + ).to_return(status: 200, body: { embedding: { values: [1, 2, 3] } }.to_json) + expect(validator.can_generate_embeddings?("gemini")).to eq(true) + end + end +end