llama-index-llms-openai 0.1.28__tar.gz → 0.1.30__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/PKG-INFO +1 -1
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/llama_index/llms/openai/base.py +20 -9
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/llama_index/llms/openai/utils.py +1 -0
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/pyproject.toml +1 -1
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/README.md +0 -0
- {llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/llama_index/llms/openai/__init__.py +0 -0
{llama_index_llms_openai-0.1.28 → llama_index_llms_openai-0.1.30}/llama_index/llms/openai/base.py
RENAMED
|
@@ -604,18 +604,29 @@ class OpenAI(FunctionCallingLLM):
|
|
|
604
604
|
|
|
605
605
|
def _get_response_token_counts(self, raw_response: Any) -> dict:
|
|
606
606
|
"""Get the token usage reported by the response."""
|
|
607
|
-
if
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
607
|
+
if hasattr(raw_response, "usage"):
|
|
608
|
+
try:
|
|
609
|
+
prompt_tokens = raw_response.usage.prompt_tokens
|
|
610
|
+
completion_tokens = raw_response.usage.completion_tokens
|
|
611
|
+
total_tokens = raw_response.usage.total_tokens
|
|
612
|
+
except AttributeError:
|
|
613
|
+
return {}
|
|
614
|
+
elif isinstance(raw_response, dict):
|
|
615
|
+
usage = raw_response.get("usage", {})
|
|
616
|
+
# NOTE: other model providers that use the OpenAI client may not report usage
|
|
617
|
+
if usage is None:
|
|
618
|
+
return {}
|
|
619
|
+
# Backwards compatibility with old dict type
|
|
620
|
+
prompt_tokens = usage.get("prompt_tokens", 0)
|
|
621
|
+
completion_tokens = usage.get("completion_tokens", 0)
|
|
622
|
+
total_tokens = usage.get("total_tokens", 0)
|
|
623
|
+
else:
|
|
613
624
|
return {}
|
|
614
625
|
|
|
615
626
|
return {
|
|
616
|
-
"prompt_tokens":
|
|
617
|
-
"completion_tokens":
|
|
618
|
-
"total_tokens":
|
|
627
|
+
"prompt_tokens": prompt_tokens,
|
|
628
|
+
"completion_tokens": completion_tokens,
|
|
629
|
+
"total_tokens": total_tokens,
|
|
619
630
|
}
|
|
620
631
|
|
|
621
632
|
# ===== Async Endpoints =====
|
|
File without changes
|
|
File without changes
|