diff --git a/test/multiverse/suites/ruby_openai/openai_helpers.rb b/test/multiverse/suites/ruby_openai/openai_helpers.rb index 75375168c4..8bd0e3643b 100644 --- a/test/multiverse/suites/ruby_openai/openai_helpers.rb +++ b/test/multiverse/suites/ruby_openai/openai_helpers.rb @@ -31,6 +31,19 @@ def error_response(return_value: false) end end + class EmbeddingsResponse + def body(return_value: false) + {'object' => 'list', + 'data' => [{ + 'object' => 'embedding', + 'index' => 0, + 'embedding' => [0.002297497, 1, -0.016932933, 0.018126108, -0.014432343, -0.0030051514] # A real embeddings response includes dozens more vector points. + }], + 'model' => 'text-embedding-ada-002', + 'usage' => {'prompt_tokens' => 8, 'total_tokens' => 8}} + end + end + def client @client ||= OpenAI::Client.new(access_token: 'FAKE_ACCESS_TOKEN') end @@ -181,4 +194,16 @@ def stub_error_post_request(&blk) end end end + + def stub_embeddings_post_request(&blk) + if Gem::Version.new(::OpenAI::VERSION) <= Gem::Version.new('3.4.0') + HTTParty.stub(:post, EmbeddingsResponse.new.body(return_value: true)) do + yield + end + else + connection_client.stub(:conn, faraday_connection) do + yield + end + end + end end diff --git a/test/multiverse/suites/ruby_openai/ruby_openai_instrumentation_test.rb b/test/multiverse/suites/ruby_openai/ruby_openai_instrumentation_test.rb index 5dec72f4a0..0dff89aaf9 100644 --- a/test/multiverse/suites/ruby_openai/ruby_openai_instrumentation_test.rb +++ b/test/multiverse/suites/ruby_openai/ruby_openai_instrumentation_test.rb @@ -183,7 +183,7 @@ def test_conversation_id_added_to_message_events def test_openai_embedding_segment_name txn = in_transaction do - stub_post_request do + stub_embeddings_post_request do client.embeddings(parameters: embeddings_params) end end @@ -193,7 +193,7 @@ def test_openai_embedding_segment_name def test_embedding_has_duration_of_segment txn = in_transaction do - stub_post_request do + stub_embeddings_post_request do client.embeddings(parameters: embeddings_params) end end @@ -205,7 +205,7 @@ def test_embedding_has_duration_of_segment def test_openai_metric_recorded_for_embeddings_every_time in_transaction do - stub_post_request do + stub_embeddings_post_request do client.embeddings(parameters: embeddings_params) client.embeddings(parameters: embeddings_params) end @@ -226,7 +226,7 @@ def test_embedding_event_sets_error_true_if_raised def test_set_llm_agent_attribute_on_embedding_transaction in_transaction do |txn| - stub_post_request do + stub_embeddings_post_request do client.embeddings(parameters: embeddings_params) end end