@@ -1975,24 +1975,6 @@ async def test_streaming_chat_completion_async(
19751975 "content" : "You are a helpful assistant." ,
19761976 }
19771977 ]
1978-
1979- assert "hello" in span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
1980- assert "hello world" in span ["attributes" ][SPANDATA .GEN_AI_RESPONSE_TEXT ]
1981-
1982- try :
1983- import tiktoken # type: ignore # noqa # pylint: disable=unused-import
1984-
1985- if "blocks" in param_id :
1986- assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
1987- assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 7
1988- assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 9
1989- else :
1990- assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
1991- assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 12
1992- assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 14
1993-
1994- except ImportError :
1995- pass # if tiktoken is not installed, we can't guarantee token usage will be calculated properly
19961978 else :
19971979 assert json .loads (
19981980 span ["attributes" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
@@ -2007,23 +1989,23 @@ async def test_streaming_chat_completion_async(
20071989 },
20081990 ]
20091991
2010- assert "hello" in span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
2011- assert "hello world" in span ["attributes" ][SPANDATA .GEN_AI_RESPONSE_TEXT ]
1992+ assert "hello" in span ["attributes" ][SPANDATA .GEN_AI_REQUEST_MESSAGES ]
1993+ assert "hello world" in span ["attributes" ][SPANDATA .GEN_AI_RESPONSE_TEXT ]
20121994
2013- try :
2014- import tiktoken # type: ignore # noqa # pylint: disable=unused-import
1995+ try :
1996+ import tiktoken # type: ignore # noqa # pylint: disable=unused-import
20151997
2016- if "blocks" in param_id :
2017- assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
2018- assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 7
2019- assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 9
2020- else :
2021- assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
2022- assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 12
2023- assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 14
1998+ if "blocks" in param_id :
1999+ assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
2000+ assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 7
2001+ assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 9
2002+ else :
2003+ assert span ["attributes" ]["gen_ai.usage.output_tokens" ] == 2
2004+ assert span ["attributes" ]["gen_ai.usage.input_tokens" ] == 12
2005+ assert span ["attributes" ]["gen_ai.usage.total_tokens" ] == 14
20242006
2025- except ImportError :
2026- pass # if tiktoken is not installed, we can't guarantee token usage will be calculated properly
2007+ except ImportError :
2008+ pass # if tiktoken is not installed, we can't guarantee token usage will be calculated properly
20272009 else :
20282010 events = capture_events ()
20292011
0 commit comments