FIX: embedding validation (#1043)

This commit is contained in:
Sam 2024-12-24 09:37:23 +11:00 committed by GitHub
parent 792df58fbc
commit 47ecf86aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -42,8 +42,9 @@ module DiscourseAi
def can_generate_embeddings?(val) def can_generate_embeddings?(val)
DiscourseAi::Embeddings::VectorRepresentations::Base DiscourseAi::Embeddings::VectorRepresentations::Base
.find_representation(val) .find_representation(val)
.new(DiscourseAi::Embeddings::Strategies::Truncation.new) .new
.vector_from("this is a test") .inference_client
.perform!("this is a test")
.present? .present?
end end
end end

View File

@ -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