forked from phoenix/litellm-mirror
fix(s3.py): fix s3 logging payload to have valid json values
Previously pydantic objects were being stringified, making them unparsable
This commit is contained in:
parent
eb6a0a32f1
commit
cda50e5d47
5 changed files with 244 additions and 23 deletions
|
@ -1166,3 +1166,55 @@ def test_turn_off_message_logging():
|
|||
|
||||
time.sleep(2)
|
||||
assert len(customHandler.errors) == 0
|
||||
|
||||
|
||||
##### VALID JSON ######
|
||||
|
||||
|
||||
def test_standard_logging_payload():
|
||||
"""
|
||||
Ensure valid standard_logging_payload is passed for logging calls to s3
|
||||
|
||||
Motivation: provide a standard set of things that are logged to s3/gcs/future integrations across all llm calls
|
||||
"""
|
||||
from litellm.types.utils import StandardLoggingPayload
|
||||
|
||||
# sync completion
|
||||
customHandler = CompletionCustomHandler()
|
||||
litellm.callbacks = [customHandler]
|
||||
|
||||
with patch.object(
|
||||
customHandler, "log_success_event", new=MagicMock()
|
||||
) as mock_client:
|
||||
_ = litellm.completion(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": "Hey, how's it going?"}],
|
||||
mock_response="Going well!",
|
||||
)
|
||||
|
||||
time.sleep(2)
|
||||
mock_client.assert_called_once()
|
||||
|
||||
print(
|
||||
f"mock_client_post.call_args: {mock_client.call_args.kwargs['kwargs'].keys()}"
|
||||
)
|
||||
assert "standard_logging_object" in mock_client.call_args.kwargs["kwargs"]
|
||||
assert (
|
||||
mock_client.call_args.kwargs["kwargs"]["standard_logging_object"]
|
||||
is not None
|
||||
)
|
||||
|
||||
print(mock_client.call_args.kwargs["kwargs"]["standard_logging_object"])
|
||||
|
||||
keys_list = list(StandardLoggingPayload.__annotations__.keys())
|
||||
|
||||
for k in keys_list:
|
||||
assert (
|
||||
k in mock_client.call_args.kwargs["kwargs"]["standard_logging_object"]
|
||||
)
|
||||
|
||||
## json serializable
|
||||
json_str_payload = json.dumps(
|
||||
mock_client.call_args.kwargs["kwargs"]["standard_logging_object"]
|
||||
)
|
||||
json.loads(json_str_payload)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue