Skip to content

Commit 0e319f1

Browse files
committed
Fix tiktoken test variant
1 parent e45420e commit 0e319f1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def get_file_text(file_name):
6060
"httpx": ["httpx>=0.16.0"],
6161
"huey": ["huey>=2"],
6262
"loguru": ["loguru>=0.5"],
63+
"openai": ["openai>=1.0.0", "tiktoken>=0.3.0"],
6364
"opentelemetry": ["opentelemetry-distro>=0.35b0"],
6465
"opentelemetry-experimental": [
6566
"opentelemetry-distro~=0.40b0",

tests/integrations/openai/test_openai.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ def test_streaming_chat_completion(sentry_init, capture_events):
118118
assert tx["type"] == "transaction"
119119
span = tx["spans"][0]
120120
assert span["op"] == "openai.chat_completions.create"
121-
assert span["data"][COMPLETION_TOKENS_USED] == 2
122-
assert span["data"][PROMPT_TOKENS_USED] == 1
123-
assert span["data"][TOTAL_TOKENS_USED] == 3
121+
122+
try:
123+
import tiktoken # type: ignore # noqa # pylint: disable=unused-import
124+
125+
assert span["data"][COMPLETION_TOKENS_USED] == 2
126+
assert span["data"][PROMPT_TOKENS_USED] == 1
127+
assert span["data"][TOTAL_TOKENS_USED] == 3
128+
except ImportError:
129+
pass # if tiktoken is not installed, we can't guarantee token usage will be calculated properly
124130

125131

126132
def test_bad_chat_completion(sentry_init, capture_events):

0 commit comments

Comments
 (0)