-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(openai): handle async streaming responses for openai v1 client #421
Conversation
@pytest.mark.vcr | ||
async def test_async_completion(exporter, async_openai_client): | ||
await async_openai_client.completions.create( | ||
model="davinci-002", | ||
prompt="Tell me a joke about opentelemetry", | ||
) | ||
|
||
spans = exporter.get_finished_spans() | ||
assert [span.name for span in spans] == [ | ||
"openai.completion", | ||
] | ||
open_ai_span = spans[0] | ||
assert ( | ||
open_ai_span.attributes["llm.prompts.0.user"] | ||
== "Tell me a joke about opentelemetry" | ||
) | ||
assert open_ai_span.attributes.get("llm.completions.0.content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to split this into its own PR, figured some test coverage for non-streaming async calls would also be beneficial.
Thanks @najork! Looks like the tests aren't actually running since we're missing some pytest async plugin (see test run logs).
|
@@ -60,22 +60,23 @@ async def acompletion_wrapper(tracer, wrapped, instance, args, kwargs): | |||
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY): | |||
return wrapped(*args, **kwargs) | |||
|
|||
async with start_as_current_span_async( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing span.is_recording()
to return false in _abuild_from_streaming_response
, in turn causing the response attribute setter to short-circuit, and the test assertion for span content to fail
No description provided.