Skip to content

Commit 3d77728

Browse files
committed
beta chat completions are gone in recent openai versions
1 parent 81e0a8a commit 3d77728

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _instrument(self, **kwargs):
117117

118118
def _patch(self, module):
119119
version = tuple([int(x) for x in getattr(getattr(module, "version"), "VERSION").split(".")])
120-
self.beta_chat_available = version >= (1, 40, 0)
120+
self.beta_chat_available = version >= (1, 40, 0) and version < (1, 93, 0)
121121
wrap_function_wrapper(
122122
"openai.resources.chat.completions",
123123
"Completions.create",

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_beta_chat_completions.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
TEST_CHAT_MODEL = "gpt-4o-mini"
6767
TEST_CHAT_RESPONSE_MODEL = "gpt-4o-mini-2024-07-18"
6868
TEST_CHAT_INPUT = "Answer in up to 3 words: Which ocean contains Bouvet Island?"
69+
HAS_BETA_CHAT_COMPLETIONS = (1, 40, 0) <= OPENAI_VERSION < (1, 93, 0)
6970

7071

71-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
72+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
7273
@pytest.mark.vcr()
7374
def test_chat(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
7475
client = openai.OpenAI()
@@ -133,7 +134,7 @@ def test_chat(default_openai_env, trace_exporter, metrics_reader, logs_exporter)
133134
)
134135

135136

136-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
137+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
137138
@pytest.mark.vcr()
138139
def test_chat_with_developer_role_message(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
139140
client = openai.OpenAI()
@@ -206,7 +207,7 @@ def test_chat_with_developer_role_message(default_openai_env, trace_exporter, me
206207
)
207208

208209

209-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
210+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
210211
@pytest.mark.vcr()
211212
def test_chat_all_the_client_options(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
212213
client = openai.OpenAI()
@@ -295,7 +296,7 @@ def test_chat_all_the_client_options(default_openai_env, trace_exporter, metrics
295296
)
296297

297298

298-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
299+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
299300
@pytest.mark.vcr()
300301
def test_chat_multiple_choices_with_capture_message_content(
301302
default_openai_env, trace_exporter, metrics_reader, logs_exporter
@@ -370,7 +371,7 @@ def test_chat_multiple_choices_with_capture_message_content(
370371
)
371372

372373

373-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
374+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
374375
@pytest.mark.vcr()
375376
def test_chat_function_calling_with_tools(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
376377
client = openai.OpenAI()
@@ -473,7 +474,7 @@ def test_chat_function_calling_with_tools(default_openai_env, trace_exporter, me
473474
)
474475

475476

476-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
477+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
477478
@pytest.mark.vcr()
478479
def test_chat_tools_with_capture_message_content(default_openai_env, trace_exporter, logs_exporter, metrics_reader):
479480
# Redo the instrumentation dance to be affected by the environment variable
@@ -584,7 +585,7 @@ def test_chat_tools_with_capture_message_content(default_openai_env, trace_expor
584585
)
585586

586587

587-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
588+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
588589
@pytest.mark.integration
589590
def test_chat_tools_with_capture_message_content_integration(trace_exporter, logs_exporter, metrics_reader):
590591
client = get_integration_client()
@@ -695,7 +696,7 @@ def test_chat_tools_with_capture_message_content_integration(trace_exporter, log
695696
)
696697

697698

698-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
699+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
699700
def test_chat_connection_error(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
700701
client = openai.Client(base_url="http://localhost:9999/v5", api_key="not-read", max_retries=1)
701702
messages = [
@@ -746,7 +747,7 @@ def test_chat_connection_error(default_openai_env, trace_exporter, metrics_reade
746747
)
747748

748749

749-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
750+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
750751
@pytest.mark.integration
751752
def test_chat_with_capture_message_content_integration(trace_exporter, logs_exporter, metrics_reader):
752753
model = os.getenv("TEST_CHAT_MODEL", TEST_CHAT_MODEL)
@@ -822,7 +823,7 @@ def test_chat_with_capture_message_content_integration(trace_exporter, logs_expo
822823
)
823824

824825

825-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
826+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
826827
@pytest.mark.vcr()
827828
def test_chat_with_capture_message_content(default_openai_env, trace_exporter, logs_exporter, metrics_reader):
828829
client = openai.OpenAI()
@@ -893,7 +894,7 @@ def test_chat_with_capture_message_content(default_openai_env, trace_exporter, l
893894
)
894895

895896

896-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
897+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
897898
@pytest.mark.vcr()
898899
def test_chat_tools_with_followup_and_capture_message_content(
899900
default_openai_env, trace_exporter, metrics_reader, logs_exporter
@@ -1065,7 +1066,7 @@ def test_chat_tools_with_followup_and_capture_message_content(
10651066
)
10661067

10671068

1068-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1069+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
10691070
@pytest.mark.asyncio
10701071
@pytest.mark.vcr()
10711072
async def test_chat_async(default_openai_env, trace_exporter, metrics_reader, logs_exporter):
@@ -1131,7 +1132,7 @@ async def test_chat_async(default_openai_env, trace_exporter, metrics_reader, lo
11311132
)
11321133

11331134

1134-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1135+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
11351136
@pytest.mark.asyncio
11361137
@pytest.mark.vcr()
11371138
async def test_chat_async_with_capture_message_content(
@@ -1205,7 +1206,7 @@ async def test_chat_async_with_capture_message_content(
12051206
)
12061207

12071208

1208-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1209+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
12091210
@pytest.mark.integration
12101211
@pytest.mark.asyncio
12111212
async def test_chat_async_with_capture_message_content_integration(trace_exporter, logs_exporter, metrics_reader):
@@ -1279,7 +1280,7 @@ async def test_chat_async_with_capture_message_content_integration(trace_exporte
12791280
)
12801281

12811282

1282-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1283+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
12831284
@pytest.mark.vcr()
12841285
@pytest.mark.asyncio
12851286
async def test_chat_async_tools_with_capture_message_content(
@@ -1393,7 +1394,7 @@ async def test_chat_async_tools_with_capture_message_content(
13931394
)
13941395

13951396

1396-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1397+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
13971398
@pytest.mark.vcr()
13981399
def test_chat_without_model_parameter(default_openai_env, trace_exporter, metrics_reader):
13991400
client = openai.OpenAI()
@@ -1439,7 +1440,7 @@ def test_chat_without_model_parameter(default_openai_env, trace_exporter, metric
14391440
)
14401441

14411442

1442-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1443+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
14431444
@pytest.mark.vcr()
14441445
def test_chat_with_model_not_found(default_openai_env, trace_exporter, metrics_reader):
14451446
client = openai.OpenAI()
@@ -1485,7 +1486,7 @@ def test_chat_with_model_not_found(default_openai_env, trace_exporter, metrics_r
14851486
)
14861487

14871488

1488-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1489+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
14891490
@pytest.mark.vcr()
14901491
def test_chat_exported_schema_version(default_openai_env, trace_exporter, metrics_reader):
14911492
client = openai.OpenAI()
@@ -1511,7 +1512,7 @@ def test_chat_exported_schema_version(default_openai_env, trace_exporter, metric
15111512
assert scope_metrics.schema_url == "https://opentelemetry.io/schemas/1.31.0"
15121513

15131514

1514-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1515+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
15151516
@pytest.mark.vcr()
15161517
def test_parse_response_format_json_object_with_capture_message_content(
15171518
default_openai_env, trace_exporter, metrics_reader, logs_exporter
@@ -1588,7 +1589,7 @@ class Reason(BaseModel):
15881589
reason: str
15891590

15901591

1591-
@pytest.mark.skipif(OPENAI_VERSION < (1, 40, 0), reason="beta completions added in 1.40.0")
1592+
@pytest.mark.skipif(not HAS_BETA_CHAT_COMPLETIONS, reason="beta completions added in 1.40.0, removed in 1.93.0")
15921593
@pytest.mark.vcr()
15931594
def test_parse_response_format_structured_output_with_capture_message_content(
15941595
default_openai_env, trace_exporter, metrics_reader, logs_exporter

0 commit comments

Comments
 (0)