FIX: typo causing text_embedding_3_large to fail (#460)

This commit is contained in:
Sam 2024-02-05 11:16:36 +11:00 committed by GitHub
parent a3c827efcc
commit ba3c3951cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 3 deletions

View File

@ -48,7 +48,7 @@ module DiscourseAi
response = response =
DiscourseAi::Inference::OpenAiEmbeddings.perform!( DiscourseAi::Inference::OpenAiEmbeddings.perform!(
text, text,
model: self.clas.name, model: self.class.name,
dimensions: dimensions, dimensions: dimensions,
) )
response[:data].first[:embedding] response[:data].first[:embedding]

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require_relative "vector_rep_shared_examples"
RSpec.describe DiscourseAi::Embeddings::VectorRepresentations::TextEmbedding3Large do
subject(:vector_rep) { described_class.new(truncation) }
let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new }
def stub_vector_mapping(text, expected_embedding)
EmbeddingsGenerationStubs.openai_service(
described_class.name,
text,
expected_embedding,
extra_args: {
dimensions: 2000,
},
)
end
it_behaves_like "generates and store embedding using with vector representation"
end

View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
require_relative "vector_rep_shared_examples"
RSpec.describe DiscourseAi::Embeddings::VectorRepresentations::TextEmbedding3Small do
subject(:vector_rep) { described_class.new(truncation) }
let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new }
def stub_vector_mapping(text, expected_embedding)
EmbeddingsGenerationStubs.openai_service(described_class.name, text, expected_embedding)
end
it_behaves_like "generates and store embedding using with vector representation"
end

View File

@ -13,10 +13,10 @@ class EmbeddingsGenerationStubs
.to_return(status: 200, body: JSON.dump(embedding)) .to_return(status: 200, body: JSON.dump(embedding))
end end
def openai_service(model, string, embedding) def openai_service(model, string, embedding, extra_args: {})
WebMock WebMock
.stub_request(:post, "https://api.openai.com/v1/embeddings") .stub_request(:post, "https://api.openai.com/v1/embeddings")
.with(body: JSON.dump({ model: model, input: string })) .with(body: JSON.dump({ model: model, input: string }.merge(extra_args)))
.to_return(status: 200, body: JSON.dump({ data: [{ embedding: embedding }] })) .to_return(status: 200, body: JSON.dump({ data: [{ embedding: embedding }] }))
end end
end end