-
Notifications
You must be signed in to change notification settings - Fork 609
ref(openai): Separate output handling #5543
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,7 +462,7 @@ def _set_embeddings_input_data( | |
| _commmon_set_input_data(span, kwargs) | ||
|
|
||
|
|
||
| def _set_output_data( | ||
| def _common_set_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
|
|
@@ -706,11 +706,109 @@ def _new_chat_completion_common(f: "Any", *args: "Any", **kwargs: "Any") -> "Any | |
| start_time = time.perf_counter() | ||
| response = yield f, args, kwargs | ||
|
|
||
| _set_output_data(span, response, kwargs, integration, start_time, finish_span=True) | ||
| is_streaming_response = kwargs.get("stream", False) | ||
| if is_streaming_response: | ||
| _set_streaming_completions_api_output_data( | ||
| span, response, kwargs, integration, start_time, finish_span=True | ||
| ) | ||
| else: | ||
| _set_completions_api_output_data( | ||
| span, response, kwargs, integration, start_time, finish_span=True | ||
| ) | ||
|
|
||
| return response | ||
|
|
||
|
|
||
| def _set_completions_api_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
| integration: "OpenAIIntegration", | ||
| start_time: "Optional[float]" = None, | ||
| finish_span: bool = True, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I can see there being a possibility that the name If it's not a massive pain, it might be worth renaming to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very good point, naming is hard 😅 |
||
| ) -> None: | ||
| _common_set_output_data( | ||
| span, | ||
| response, | ||
| kwargs, | ||
| integration, | ||
| start_time, | ||
| finish_span, | ||
| ) | ||
|
|
||
|
|
||
| def _set_streaming_completions_api_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
| integration: "OpenAIIntegration", | ||
| start_time: "Optional[float]" = None, | ||
| finish_span: bool = True, | ||
| ) -> None: | ||
| _common_set_output_data( | ||
| span, | ||
| response, | ||
| kwargs, | ||
| integration, | ||
| start_time, | ||
| finish_span, | ||
| ) | ||
|
|
||
|
|
||
| def _set_responses_api_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
| integration: "OpenAIIntegration", | ||
| start_time: "Optional[float]" = None, | ||
| finish_span: bool = True, | ||
| ) -> None: | ||
| _common_set_output_data( | ||
| span, | ||
| response, | ||
| kwargs, | ||
| integration, | ||
| start_time, | ||
| finish_span, | ||
| ) | ||
|
|
||
|
|
||
| def _set_streaming_responses_api_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
| integration: "OpenAIIntegration", | ||
| start_time: "Optional[float]" = None, | ||
| finish_span: bool = True, | ||
| ) -> None: | ||
| _common_set_output_data( | ||
| span, | ||
| response, | ||
| kwargs, | ||
| integration, | ||
| start_time, | ||
| finish_span, | ||
| ) | ||
|
|
||
|
|
||
| def _set_embeddings_output_data( | ||
| span: "Span", | ||
| response: "Any", | ||
| kwargs: "dict[str, Any]", | ||
| integration: "OpenAIIntegration", | ||
| start_time: "Optional[float]" = None, | ||
| finish_span: bool = True, | ||
| ) -> None: | ||
| _common_set_output_data( | ||
| span, | ||
| response, | ||
| kwargs, | ||
| integration, | ||
| start_time, | ||
| finish_span, | ||
| ) | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _wrap_chat_completion_create(f: "Callable[..., Any]") -> "Callable[..., Any]": | ||
| def _execute_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any": | ||
| gen = _new_chat_completion_common(f, *args, **kwargs) | ||
|
|
@@ -795,7 +893,9 @@ def _new_embeddings_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "A | |
|
|
||
| response = yield f, args, kwargs | ||
|
|
||
| _set_output_data(span, response, kwargs, integration, finish_span=False) | ||
| _set_embeddings_output_data( | ||
| span, response, kwargs, integration, finish_span=False | ||
| ) | ||
|
|
||
| return response | ||
|
|
||
|
|
@@ -885,7 +985,15 @@ def _new_responses_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "An | |
| start_time = time.perf_counter() | ||
| response = yield f, args, kwargs | ||
|
|
||
| _set_output_data(span, response, kwargs, integration, start_time, finish_span=True) | ||
| is_streaming_response = kwargs.get("stream", False) | ||
| if is_streaming_response: | ||
| _set_streaming_responses_api_output_data( | ||
| span, response, kwargs, integration, start_time, finish_span=True | ||
| ) | ||
| else: | ||
| _set_responses_api_output_data( | ||
| span, response, kwargs, integration, start_time, finish_span=True | ||
| ) | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
| return response | ||
|
|
||
|
|
||
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.
Nit:
_set_common_output_dataThere 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.
addressed 63acf10