Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Homepage = "https://github.com/elastic/elastic-otel-python-instrumentations"
"Bug Tracker" = "https://github.com/elastic/elastic-otel-python-instrumentations/issues"

[project.optional-dependencies]
dev = ["pytest", "pip-tools", "openai", "numpy", "opentelemetry-test-utils", "vcrpy", "pytest-asyncio", "pytest-vcr"]
dev = ["pytest", "pip-tools", "openai", "numpy", "opentelemetry-test-utils", "vcrpy", "pytest-asyncio", "pytest-vcr", "pydantic"]
instruments = [
"openai >= 1.2.0",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ def _is_set(value):
if isinstance(response_format, Mapping):
if _is_set(response_format_type := response_format.get("type")):
span_attributes[GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT] = response_format_type
else:
elif isinstance(response_format, str):
span_attributes[GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT] = response_format
else:
# Assume structured output lazily parsed to a schema via type_to_response_format_param or similar.
# e.g. pydantic._internal._model_construction.ModelMetaclass
span_attributes[GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT] = "json_schema"

return span_attributes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
interactions:
- request:
body: |-
{
"messages": [
{
"role": "user",
"content": "Provide up to 3 words explaining why 2 + 2 equals 4 in JSON format with a 'reason' key."
}
],
"model": "gpt-4o-mini",
"response_format": {
"type": "json_object"
},
"stream": false
}
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- Bearer test_openai_api_key
connection:
- keep-alive
content-length:
- '219'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.54.4
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-helper-method:
- beta.chat.completions.parse
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.54.4
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.12.8
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: |-
{
"id": "chatcmpl-BCQUdjVKJTEdMSvJ2QOiAWDrK0snY",
"object": "chat.completion",
"created": 1742301475,
"model": "gpt-4o-mini-2024-07-18",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "{\n \"reason\": \"Basic arithmetic rules\"\n}",
"refusal": null,
"annotations": []
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 33,
"completion_tokens": 12,
"total_tokens": 45,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": "fp_06737a9306"
}
headers:
CF-RAY:
- 9224c8bc4fd0d6d4-IAD
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Tue, 18 Mar 2025 12:37:55 GMT
Server:
- cloudflare
Set-Cookie: test_set_cookie
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '853'
openai-organization: test_openai_org_id
openai-processing-ms:
- '349'
openai-version:
- '2020-10-01'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- '10000'
x-ratelimit-limit-tokens:
- '200000'
x-ratelimit-remaining-requests:
- '9999'
x-ratelimit-remaining-tokens:
- '199961'
x-ratelimit-reset-requests:
- 8.64s
x-ratelimit-reset-tokens:
- 11ms
x-request-id:
- req_028aaf689eb983bd5826084c8a234d93
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
interactions:
- request:
body: |-
{
"messages": [
{
"role": "user",
"content": "Provide up to 3 words explaining why 2 + 2 equals 4 in JSON format with a 'reason' key."
}
],
"model": "gpt-4o-mini",
"response_format": {
"type": "json_schema",
"json_schema": {
"schema": {
"properties": {
"reason": {
"title": "Reason",
"type": "string"
}
},
"required": [
"reason"
],
"title": "Reason",
"type": "object",
"additionalProperties": false
},
"name": "Reason",
"strict": true
}
},
"stream": false
}
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- Bearer test_openai_api_key
connection:
- keep-alive
content-length:
- '439'
content-type:
- application/json
host:
- api.openai.com
user-agent:
- OpenAI/Python 1.54.4
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-helper-method:
- beta.chat.completions.parse
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.54.4
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.12.8
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: |-
{
"id": "chatcmpl-BCQyQRM6O8IAVbMuCXPbdLjZWwJrX",
"object": "chat.completion",
"created": 1742303322,
"model": "gpt-4o-mini-2024-07-18",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "{\"reason\":\"Basic arithmetic operation\"}",
"refusal": null,
"annotations": []
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 69,
"completion_tokens": 8,
"total_tokens": 77,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": "fp_3267753c5d"
}
headers:
CF-RAY:
- 9224f5d58bc4c9b0-IAD
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Tue, 18 Mar 2025 13:08:42 GMT
Server:
- cloudflare
Set-Cookie: test_set_cookie
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '849'
openai-organization: test_openai_org_id
openai-processing-ms:
- '367'
openai-version:
- '2020-10-01'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- '10000'
x-ratelimit-limit-tokens:
- '200000'
x-ratelimit-remaining-requests:
- '9999'
x-ratelimit-remaining-tokens:
- '199961'
x-ratelimit-reset-requests:
- 8.64s
x-ratelimit-reset-tokens:
- 11ms
x-request-id:
- req_1d2a78ae178add9f8c2bece1d549d000
status:
code: 200
message: OK
version: 1
Loading