Skip to content

Commit 80de27a

Browse files
elastic-opentelemetry-instrumentation-openai: formats test yaml same as upstream (#30)
Co-authored-by: Adrian Cole <[email protected]>
1 parent 8c54caa commit 80de27a

File tree

77 files changed

+11442
-4739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+11442
-4739
lines changed

instrumentation/elastic-opentelemetry-instrumentation-openai/README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,38 @@ Integration tests default to using ollama, to avoid cost and leaking sensitive i
9696
However, unit test recordings should use the authoritative OpenAI platform unless the test is
9797
about a specific portability corner case.
9898

99-
To refresh a test, delete its cassette file in tests/cassettes and make sure you have the
100-
following environment variables set for OpenAI recordings:
99+
To refresh a test, delete its cassette file in tests/cassettes and make sure you have environment
100+
variables set for recordings, detailed later.
101+
102+
If writing a new test, start with the test logic with no assertions. If extending an existing unit test
103+
rather than writing a new one, remove the corresponding recorded response from [cassettes](./tests/cassettes/)
104+
instead.
105+
106+
Then, run `pytest` as normal. It will execute a request against the LLM and record it. Update the
107+
test with correct assertions until it passes. Following executions of `pytest` will use the recorded
108+
response without querying the LLM.
109+
110+
### OpenAI Environment Variables
101111

102112
* `OPENAI_API_KEY` - from https://platform.openai.com/settings/profile?tab=api-keys
103113
* It should look like `sk-...`
104114

105-
and the following for Azure recordings, deployment url and api key are available for each deployment
106-
in https://oai.azure.com/resource/deployments:
115+
### Azure OpenAI Environment Variables
116+
117+
Azure is different from OpenAI primarily in that a URL has an implicit model. This means it ignores
118+
the model parameter set by the OpenAI SDK. The implication is that one endpoint cannot serve both
119+
chat and embeddings at the same time. Hence, we need separate environment variables for chat and
120+
embeddings. In either case, the `DEPLOYMENT_URL` is the "Endpoint Target URI" and the `API_KEY` is
121+
the `Endpoint Key` for a corresponding deployment in https://oai.azure.com/resource/deployments
107122

108123
* `AZURE_CHAT_COMPLETIONS_DEPLOYMENT_URL`
124+
* It should look like https://endpoint.com/openai/deployments/my-deployment/chat/completions?api-version=2023-05-15
109125
* `AZURE_CHAT_COMPLETIONS_API_KEY`
126+
* It should be in hex like `abc01...` and possibly the same as `AZURE_EMBEDDINGS_API_KEY`
110127
* `AZURE_EMBEDDINGS_DEPLOYMENT_URL`
128+
* It should look like https://endpoint.com/openai/deployments/my-deployment/embeddings?api-version=2023-05-15
111129
* `AZURE_EMBEDDINGS_API_KEY`
112-
113-
If writing a new test, start with the test logic with no assertions. If extending an existing unit test
114-
rather than writing a new one, remove the corresponding recorded response from [cassettes](./tests/cassettes/)
115-
instead.
116-
117-
Then, run `pytest` as normal. It will execute a request against the LLM and record it. Update the
118-
test with correct assertions until it passes. Following executions of `pytest` will use the recorded
119-
response without querying the LLM.
130+
* It should be in hex like `abc01...` and possibly the same as `AZURE_CHAT_COMPLETIONS_API_KEY`
120131

121132
## License
122133

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_all_the_client_options[azure_provider_chat_completions].yaml

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
interactions:
22
- request:
3-
body: '{"messages": [{"role": "user", "content": "Answer in up to 3 words: Which
4-
ocean contains the falkland islands?"}], "model": "gpt-4o-mini", "frequency_penalty":
5-
0, "max_tokens": 100, "presence_penalty": 0, "stop": "foo", "temperature": 1,
6-
"top_p": 1}'
3+
body: |-
4+
{
5+
"messages": [
6+
{
7+
"role": "user",
8+
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
9+
}
10+
],
11+
"model": "unused",
12+
"frequency_penalty": 0,
13+
"max_tokens": 100,
14+
"presence_penalty": 0,
15+
"stop": "foo",
16+
"temperature": 1,
17+
"top_p": 1
18+
}
719
headers:
820
accept:
921
- application/json
@@ -16,70 +28,133 @@ interactions:
1628
connection:
1729
- keep-alive
1830
content-length:
19-
- '249'
31+
- '244'
2032
content-type:
2133
- application/json
2234
host:
2335
- test.openai.azure.com
2436
user-agent:
25-
- AzureOpenAI/Python 1.50.0
37+
- AzureOpenAI/Python 1.54.3
2638
x-stainless-arch:
27-
- x64
39+
- arm64
2840
x-stainless-async:
2941
- 'false'
3042
x-stainless-lang:
3143
- python
3244
x-stainless-os:
33-
- Linux
45+
- MacOS
3446
x-stainless-package-version:
35-
- 1.50.0
47+
- 1.54.3
3648
x-stainless-retry-count:
3749
- '0'
3850
x-stainless-runtime:
3951
- CPython
4052
x-stainless-runtime-version:
41-
- 3.10.12
53+
- 3.12.6
4254
method: POST
43-
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2023-03-15-preview
55+
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview
4456
response:
4557
body:
46-
string: '{"choices":[{"finish_reason":"stop","index":0,"message":{"content":"South
47-
Atlantic Ocean.","role":"assistant"}}],"created":1727962531,"id":"chatcmpl-AEGHLLqYkgJxUgLgX8RCLeL85irQR","model":"gpt-4o-mini","object":"chat.completion","system_fingerprint":"fp_878413d04d","usage":{"completion_tokens":4,"prompt_tokens":24,"total_tokens":28}}
48-
49-
'
58+
string: |-
59+
{
60+
"choices": [
61+
{
62+
"content_filter_results": {
63+
"hate": {
64+
"filtered": false,
65+
"severity": "safe"
66+
},
67+
"self_harm": {
68+
"filtered": false,
69+
"severity": "safe"
70+
},
71+
"sexual": {
72+
"filtered": false,
73+
"severity": "safe"
74+
},
75+
"violence": {
76+
"filtered": false,
77+
"severity": "safe"
78+
}
79+
},
80+
"finish_reason": "stop",
81+
"index": 0,
82+
"logprobs": null,
83+
"message": {
84+
"content": "Atlantic Ocean",
85+
"role": "assistant"
86+
}
87+
}
88+
],
89+
"created": 1731466203,
90+
"id": "chatcmpl-ASxkBZGOa53uXX1Ciygl77IrF8PbB",
91+
"model": "gpt-4-32k",
92+
"object": "chat.completion",
93+
"prompt_filter_results": [
94+
{
95+
"prompt_index": 0,
96+
"content_filter_results": {
97+
"hate": {
98+
"filtered": false,
99+
"severity": "safe"
100+
},
101+
"self_harm": {
102+
"filtered": false,
103+
"severity": "safe"
104+
},
105+
"sexual": {
106+
"filtered": false,
107+
"severity": "safe"
108+
},
109+
"violence": {
110+
"filtered": false,
111+
"severity": "safe"
112+
}
113+
}
114+
}
115+
],
116+
"system_fingerprint": null,
117+
"usage": {
118+
"completion_tokens": 2,
119+
"prompt_tokens": 24,
120+
"total_tokens": 26
121+
}
122+
}
50123
headers:
124+
Cache-Control:
125+
- no-cache, must-revalidate
51126
Content-Length:
52-
- '336'
127+
- '805'
53128
Content-Type:
54129
- application/json
55130
Date:
56-
- Thu, 03 Oct 2024 13:35:31 GMT
131+
- Wed, 13 Nov 2024 02:50:02 GMT
57132
Set-Cookie: test_set_cookie
58133
Strict-Transport-Security:
59134
- max-age=31536000; includeSubDomains; preload
135+
access-control-allow-origin:
136+
- '*'
60137
apim-request-id:
61-
- c017b850-54f6-40dd-9505-d1a9ee9a45b5
138+
- f0e5ae5b-b609-4908-bedb-533ec71e9bfa
62139
azureml-model-session:
63-
- d009-20240925074800
64-
openai-organization: test_openai_org_key
140+
- d156-20241010120317
141+
openai-organization: test_openai_org_id
65142
x-accel-buffering:
66143
- 'no'
67144
x-content-type-options:
68145
- nosniff
69-
x-envoy-upstream-service-time:
70-
- '249'
71146
x-ms-client-request-id:
72-
- c017b850-54f6-40dd-9505-d1a9ee9a45b5
147+
- f0e5ae5b-b609-4908-bedb-533ec71e9bfa
73148
x-ms-rai-invoked:
74149
- 'true'
75150
x-ms-region:
76-
- East US
151+
- Switzerland North
77152
x-ratelimit-remaining-requests:
78-
- '909'
153+
- '78'
79154
x-ratelimit-remaining-tokens:
80-
- '90883'
155+
- '79884'
81156
x-request-id:
82-
- fba991b8-1a4f-4c6e-8a53-8b826a61a78a
157+
- 3a1ee803-cce9-472f-ad04-2d0757009288
83158
status:
84159
code: 200
85160
message: OK

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_all_the_client_options[ollama_provider_chat_completions].yaml

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
interactions:
22
- request:
3-
body: '{"messages": [{"role": "user", "content": "Answer in up to 3 words: Which
4-
ocean contains the falkland islands?"}], "model": "qwen2.5:0.5b", "frequency_penalty":
5-
0, "max_completion_tokens": 100, "presence_penalty": 0, "stop": "foo", "temperature":
6-
1, "top_p": 1}'
3+
body: |-
4+
{
5+
"messages": [
6+
{
7+
"role": "user",
8+
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
9+
}
10+
],
11+
"model": "qwen2.5:0.5b",
12+
"frequency_penalty": 0,
13+
"max_tokens": 100,
14+
"presence_penalty": 0,
15+
"stop": "foo",
16+
"temperature": 1,
17+
"top_p": 1
18+
}
719
headers:
820
accept:
921
- application/json
@@ -14,44 +26,63 @@ interactions:
1426
connection:
1527
- keep-alive
1628
content-length:
17-
- '261'
29+
- '250'
1830
content-type:
1931
- application/json
2032
host:
2133
- localhost:11434
2234
user-agent:
23-
- OpenAI/Python 1.50.0
35+
- OpenAI/Python 1.50.2
2436
x-stainless-arch:
25-
- x64
37+
- arm64
2638
x-stainless-async:
2739
- 'false'
2840
x-stainless-lang:
2941
- python
3042
x-stainless-os:
31-
- Linux
43+
- MacOS
3244
x-stainless-package-version:
33-
- 1.50.0
45+
- 1.50.2
3446
x-stainless-retry-count:
3547
- '0'
3648
x-stainless-runtime:
3749
- CPython
3850
x-stainless-runtime-version:
39-
- 3.10.12
51+
- 3.12.6
4052
method: POST
4153
uri: http://localhost:11434/v1/chat/completions
4254
response:
4355
body:
44-
string: '{"id":"chatcmpl-398","object":"chat.completion","created":1727962341,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"The
45-
Great British Oceanic Peninsula."},"finish_reason":"stop"}],"usage":{"prompt_tokens":46,"completion_tokens":8,"total_tokens":54}}
46-
47-
'
56+
string: |-
57+
{
58+
"id": "chatcmpl-46",
59+
"object": "chat.completion",
60+
"created": 1731311779,
61+
"model": "qwen2.5:0.5b",
62+
"system_fingerprint": "fp_ollama",
63+
"choices": [
64+
{
65+
"index": 0,
66+
"message": {
67+
"role": "assistant",
68+
"content": "The Falklands Islands are located in Atlantic Oceans."
69+
},
70+
"finish_reason": "stop"
71+
}
72+
],
73+
"usage": {
74+
"prompt_tokens": 46,
75+
"completion_tokens": 12,
76+
"total_tokens": 58
77+
}
78+
}
4879
headers:
4980
Content-Length:
50-
- '322'
81+
- '339'
5182
Content-Type:
5283
- application/json
5384
Date:
54-
- Thu, 03 Oct 2024 13:32:21 GMT
85+
- Mon, 11 Nov 2024 07:56:19 GMT
5586
Set-Cookie: test_set_cookie
5687
openai-organization: test_openai_org_key
5788
status:

0 commit comments

Comments
 (0)