Skip to content

Commit

Permalink
fix(openai): handle empty finish_reason (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga authored Jun 5, 2024
1 parent 91816c4 commit e79394e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ def _set_chat_metrics(
def _set_choice_counter_metrics(choice_counter, choices, shared_attributes):
choice_counter.add(len(choices), attributes=shared_attributes)
for choice in choices:
attributes_with_reason = {
**shared_attributes,
"llm.response.finish_reason": choice["finish_reason"],
}
attributes_with_reason = {**shared_attributes}
if choice.get("finish_reason"):
attributes_with_reason["llm.response.finish_reason"] = choice.get(
"finish_reason"
)
choice_counter.add(1, attributes=attributes_with_reason)


Expand Down Expand Up @@ -561,6 +562,7 @@ def _shared_attributes(self):
is_streaming=True,
)

@dont_throw
def _close_span(self):
if not is_azure_openai(self._instance):
_set_streaming_token_metrics(
Expand Down

0 comments on commit e79394e

Please sign in to comment.