-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
472 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
97 changes: 97 additions & 0 deletions
97
...umentation/opentelemetry-instrumentation-openai/tests/cassettes/test_chat_completion.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
interactions: | ||
- request: | ||
body: '{"messages": [{"role": "user", "content": "Say this is a test three times"}], | ||
"model": "gpt-4", "stream": false}' | ||
headers: | ||
accept: | ||
- application/json | ||
accept-encoding: | ||
- gzip, deflate | ||
connection: | ||
- keep-alive | ||
content-length: | ||
- '112' | ||
content-type: | ||
- application/json | ||
host: | ||
- api.openai.com | ||
user-agent: | ||
- OpenAI/Python 1.47.0 | ||
x-stainless-arch: | ||
- arm64 | ||
x-stainless-async: | ||
- 'false' | ||
x-stainless-lang: | ||
- python | ||
x-stainless-os: | ||
- MacOS | ||
x-stainless-package-version: | ||
- 1.47.0 | ||
x-stainless-runtime: | ||
- CPython | ||
x-stainless-runtime-version: | ||
- 3.11.5 | ||
method: POST | ||
uri: https://api.openai.com/v1/chat/completions | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAAAAAAAAAwAAAP//hJBBS8NAEIXv+RXDntuSpLXV3BQPIihSxItI2CbTZO1md81MoFr632W3 | ||
MakH8RLI+/Y93rxDBCBUKTIQRS25aJyeXt/cN+r26bH72q9f4v0Dzuu79a78KPQllWLiHXbzjgX/ | ||
uGaFbZxGVtaccNGiZPSpySpdpcskThcBNLZE7W2V4+liGi+Tee+orSqQRAavEQDAIXx9N1PiXmQQ | ||
T36UBolkhSIbHgGI1mqvCEmkiKVhMRlhYQ2jCXWfa0WgCCQwEs/gn//zlBa3HUnf3nRa9/pxqKVt | ||
5Vq7oZ4P+lYZRXXeoiRrfAVi60SgxwjgLZzf/bpIuNY2jnO2OzQ+MFmc4sQ49Bm86CFblnrU06u/ | ||
THmJLJWmswnFqZ8y1RgQDyXDlYI+ibHJt8pU2LpWhUXDFsfoGwAA//8DAOtohWdIAgAA | ||
headers: | ||
CF-Cache-Status: | ||
- DYNAMIC | ||
CF-RAY: | ||
- 8c8a6a3c3e5f11ac-MRS | ||
Connection: | ||
- keep-alive | ||
Content-Encoding: | ||
- gzip | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 25 Sep 2024 10:43:45 GMT | ||
Server: | ||
- cloudflare | ||
Set-Cookie: | ||
- __cf_bm=oXnQwjslhtdFXjG89Oureoj0ycU2U3.JD0YOmXVf7Oo-1727261025-1.0.1.1-8zkkMufvVyON_EWorQBeCtOhIav5dyIQ7s5UoEMu2gTW.uaDA3owAxnO_LwCkccXJhC56ryfDhKmS49nV855yA; | ||
path=/; expires=Wed, 25-Sep-24 11:13:45 GMT; domain=.api.openai.com; HttpOnly; | ||
Secure; SameSite=None | ||
- _cfuvid=YSEnhEKHk_5duU.2X6td9ALnCbun1O0M.YvR4OF5DgU-1727261025973-0.0.1.1-604800000; | ||
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None | ||
Transfer-Encoding: | ||
- chunked | ||
X-Content-Type-Options: | ||
- nosniff | ||
access-control-expose-headers: | ||
- X-Request-ID | ||
openai-organization: | ||
- scale3-1 | ||
openai-processing-ms: | ||
- '1074' | ||
openai-version: | ||
- '2020-10-01' | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains; preload | ||
x-ratelimit-limit-requests: | ||
- '10000' | ||
x-ratelimit-limit-tokens: | ||
- '1000000' | ||
x-ratelimit-remaining-requests: | ||
- '9999' | ||
x-ratelimit-remaining-tokens: | ||
- '999975' | ||
x-ratelimit-reset-requests: | ||
- 6ms | ||
x-ratelimit-reset-tokens: | ||
- 1ms | ||
x-request-id: | ||
- req_c4bc5f6decb9ecc1d59dd8e9435531bf | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
157 changes: 157 additions & 0 deletions
157
.../opentelemetry-instrumentation-openai/tests/cassettes/test_chat_completion_streaming.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
interactions: | ||
- request: | ||
body: '{"messages": [{"role": "user", "content": "Say this is a test three times"}], | ||
"model": "gpt-4", "stream": true, "stream_options": {"include_usage": true}}' | ||
headers: | ||
accept: | ||
- application/json | ||
accept-encoding: | ||
- gzip, deflate | ||
connection: | ||
- keep-alive | ||
content-length: | ||
- '154' | ||
content-type: | ||
- application/json | ||
host: | ||
- api.openai.com | ||
user-agent: | ||
- OpenAI/Python 1.47.0 | ||
x-stainless-arch: | ||
- arm64 | ||
x-stainless-async: | ||
- 'false' | ||
x-stainless-lang: | ||
- python | ||
x-stainless-os: | ||
- MacOS | ||
x-stainless-package-version: | ||
- 1.47.0 | ||
x-stainless-runtime: | ||
- CPython | ||
x-stainless-runtime-version: | ||
- 3.11.5 | ||
method: POST | ||
uri: https://api.openai.com/v1/chat/completions | ||
response: | ||
body: | ||
string: 'data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"This"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
is"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
a"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
test"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
This"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
is"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
a"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
test"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
This"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
is"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
a"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" | ||
test"},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"usage":null} | ||
data: {"id":"chatcmpl-ABKBOah1RoDknkRPBm3mgtT3raLaI","object":"chat.completion.chunk","created":1727262554,"model":"gpt-4-0613","system_fingerprint":null,"choices":[],"usage":{"prompt_tokens":14,"completion_tokens":15,"total_tokens":29,"completion_tokens_details":{"reasoning_tokens":0}}} | ||
data: [DONE] | ||
' | ||
headers: | ||
CF-Cache-Status: | ||
- DYNAMIC | ||
CF-RAY: | ||
- 8c8a8f963be411a4-MRS | ||
Connection: | ||
- keep-alive | ||
Content-Type: | ||
- text/event-stream; charset=utf-8 | ||
Date: | ||
- Wed, 25 Sep 2024 11:09:15 GMT | ||
Server: | ||
- cloudflare | ||
Set-Cookie: | ||
- __cf_bm=hvo156nahnyIUFXHe9iuYr0tn0dKzveWlQN7suEYz9Q-1727262555-1.0.1.1-L1wMbo_r0VTMdA..XHJ_8JDmEIjnuzOW_umwSN1y.LlARvkoK3fluYzgsPa5W1Wd_.Hx0yB__0kriyR1pszyDw; | ||
path=/; expires=Wed, 25-Sep-24 11:39:15 GMT; domain=.api.openai.com; HttpOnly; | ||
Secure; SameSite=None | ||
- _cfuvid=imSGB7bQZURuXPnMTuFDyO6GqwZI2ELFF_y9AyZcOwk-1727262555002-0.0.1.1-604800000; | ||
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None | ||
Transfer-Encoding: | ||
- chunked | ||
X-Content-Type-Options: | ||
- nosniff | ||
access-control-expose-headers: | ||
- X-Request-ID | ||
openai-organization: | ||
- scale3-1 | ||
openai-processing-ms: | ||
- '195' | ||
openai-version: | ||
- '2020-10-01' | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains; preload | ||
x-ratelimit-limit-requests: | ||
- '10000' | ||
x-ratelimit-limit-tokens: | ||
- '1000000' | ||
x-ratelimit-remaining-requests: | ||
- '9999' | ||
x-ratelimit-remaining-tokens: | ||
- '999975' | ||
x-ratelimit-reset-requests: | ||
- 6ms | ||
x-ratelimit-reset-tokens: | ||
- 1ms | ||
x-request-id: | ||
- req_49e07a9a2909db3c1d58e009add4f3ad | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
52 changes: 52 additions & 0 deletions
52
instrumentation/opentelemetry-instrumentation-openai/tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Unit tests configuration module.""" | ||
|
||
import os | ||
|
||
import pytest | ||
from openai import OpenAI | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
from opentelemetry.sdk.trace.export.in_memory_span_exporter import ( | ||
InMemorySpanExporter, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def exporter(): | ||
exporter = InMemorySpanExporter() | ||
processor = SimpleSpanProcessor(exporter) | ||
|
||
provider = TracerProvider() | ||
provider.add_span_processor(processor) | ||
trace.set_tracer_provider(provider) | ||
|
||
return exporter | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def clear_exporter(exporter): | ||
exporter.clear() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def environment(): | ||
if not os.getenv("OPENAI_API_KEY"): | ||
os.environ["OPENAI_API_KEY"] = "test-api-key" | ||
|
||
|
||
@pytest.fixture | ||
def openai_client(): | ||
return OpenAI() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def vcr_config(): | ||
return {"filter_headers": ["authorization", "api-key"]} | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def instrument(): | ||
OpenAIInstrumentor().instrument() |
Oops, something went wrong.