Merge pull request #4714 from djliden/main

updates cost tracking example code in docs to resolve errors
This commit is contained in:
Krish Dholakia 2024-07-15 14:50:09 -07:00 committed by GitHub
commit 177424c27c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,7 @@ Define your custom callback class in a python file.
```python
from litellm.integrations.custom_logger import CustomLogger
import litellm
import logging
# This file includes the custom callbacks for LiteLLM Proxy
# Once defined, these can be passed in proxy_config.yaml
@ -25,9 +26,9 @@ class MyCustomHandler(CustomLogger):
datefmt='%Y-%m-%d %H:%M:%S'
)
response_cost = litellm.completion_cost(completion_response=completion_response)
response_cost = litellm.completion_cost(completion_response=response_obj)
print("regular response_cost", response_cost)
logging.info(f"Model {completion_response.model} Cost: ${response_cost:.8f}")
logging.info(f"Model {response_obj.model} Cost: ${response_cost:.8f}")
except:
pass
@ -78,4 +79,4 @@ curl --location 'http://0.0.0.0:4000/chat/completions' \
"user": "ishaan-app",
"temperature": 0.2
}'
```
```