FIX: typo causing text_embedding_3_large to fail (#460)
This commit is contained in:
parent
a3c827efcc
commit
ba3c3951cf
|
@ -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]
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue