Skip to content

Commit

Permalink
Merge pull request #1189 from newrelic/fix-failing-openai
Browse files Browse the repository at this point in the history
Change to using auto bind on openai base client
  • Loading branch information
hmstepanek authored Aug 7, 2024
2 parents 60fe0b6 + 1fa0688 commit 6350bd3
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions newrelic/hooks/mlmodel_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,6 @@ def wrap_convert_to_openai_object(wrapped, instance, args, kwargs):
return returned_response


def bind_base_client_process_response(
cast_to,
options,
response,
stream,
stream_cls,
):
nr_response_headers = getattr(response, "headers", None) or {}
return nr_response_headers


def wrap_base_client_process_response_sync(wrapped, instance, args, kwargs):
"""Obtain response headers for v1."""
transaction = current_transaction()
Expand All @@ -704,7 +693,9 @@ def wrap_base_client_process_response_sync(wrapped, instance, args, kwargs):
if not settings.ai_monitoring.enabled:
return wrapped(*args, **kwargs)

nr_response_headers = bind_base_client_process_response(*args, **kwargs)
bound_args = bind_args(wrapped, args, kwargs)
nr_response_headers = getattr(bound_args["response"], "headers", None) or {}

return_val = wrapped(*args, **kwargs)
return_val._nr_response_headers = nr_response_headers
return return_val
Expand All @@ -720,7 +711,8 @@ async def wrap_base_client_process_response_async(wrapped, instance, args, kwarg
if not settings.ai_monitoring.enabled:
return await wrapped(*args, **kwargs)

nr_response_headers = bind_base_client_process_response(*args, **kwargs)
bound_args = bind_args(wrapped, args, kwargs)
nr_response_headers = getattr(bound_args["response"], "headers", None) or {}
return_val = await wrapped(*args, **kwargs)
return_val._nr_response_headers = nr_response_headers
return return_val
Expand Down

0 comments on commit 6350bd3

Please sign in to comment.