Skip to content

Commit

Permalink
FIX: embedding validation (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron authored Dec 23, 2024
1 parent 792df58 commit 47ecf86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/configuration/embeddings_module_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/configuration/embeddings_module_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 47ecf86

Please sign in to comment.