Skip to content

Commit

Permalink
Merge pull request #2254 from Agenta-AI/litellm-patch
Browse files Browse the repository at this point in the history
Litellm patch
  • Loading branch information
jp-agenta authored Nov 19, 2024
2 parents fdc0e82 + d907961 commit a3c559a
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions agenta-cli/agenta/sdk/litellm/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,20 @@ def log_stream_event(
log.error("LiteLLM callback error: span not found.")
return

result = kwargs.get("complete_streaming_response")
try:
result = []
for choice in response_obj.choices:
message = choice.message.__dict__
result.append(message)

outputs = (
{"__default__": result} if not isinstance(result, dict) else result
)
outputs = {"completion": result}
self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)

self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)
except Exception as e:
pass

self.span.set_attributes(
attributes={"total": kwargs.get("response_cost")},
Expand Down Expand Up @@ -194,16 +198,20 @@ async def async_log_stream_event(
log.error("LiteLLM callback error: span not found.")
return

result = kwargs.get("complete_streaming_response")
try:
result = []
for choice in response_obj.choices:
message = choice.message.__dict__
result.append(message)

outputs = (
{"__default__": result} if not isinstance(result, dict) else result
)
outputs = {"completion": result}
self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)

self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)
except Exception as e:
pass

self.span.set_attributes(
attributes={"total": kwargs.get("response_cost")},
Expand Down Expand Up @@ -236,17 +244,20 @@ async def async_log_success_event(
log.error("LiteLLM callback error: span not found.")
return

# result = kwargs.get("complete_streaming_response")
result = response_obj.choices[0].message.content
try:
result = []
for choice in response_obj.choices:
message = choice.message.__dict__
result.append(message)

outputs = (
{"__default__": result} if not isinstance(result, dict) else result
)
outputs = {"completion": result}
self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)

self.span.set_attributes(
attributes={"outputs": outputs},
namespace="data",
)
except Exception as e:
pass

self.span.set_attributes(
attributes={"total": kwargs.get("response_cost")},
Expand Down

0 comments on commit a3c559a

Please sign in to comment.