Skip to content

Commit

Permalink
Output token usage in raw data for Google Gemini LLMs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannic Spreen-Ledebur committed Oct 2, 2024
1 parent f684acc commit 3821a41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG — llama-index-llms-gemini

## [0.3.6]

- Output token usage in `raw` data.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def completion_from_gemini_response(
**(type(top_candidate).to_dict(top_candidate)),
**(type(response.prompt_feedback).to_dict(response.prompt_feedback)),
}
if response.usage_metadata:
raw["usage_metadata"] = type(response.usage_metadata).to_dict(
response.usage_metadata
)
return CompletionResponse(text=response.text, raw=raw)


Expand All @@ -58,6 +62,10 @@ def chat_from_gemini_response(
**(type(top_candidate).to_dict(top_candidate)),
**(type(response.prompt_feedback).to_dict(response.prompt_feedback)),
}
if response.usage_metadata:
raw["usage_metadata"] = type(response.usage_metadata).to_dict(
response.usage_metadata
)
role = ROLES_FROM_GEMINI[top_candidate.content.role]
return ChatResponse(message=ChatMessage(role=role, content=response.text), raw=raw)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-llms-gemini"
readme = "README.md"
version = "0.3.5"
version = "0.3.6"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down

0 comments on commit 3821a41

Please sign in to comment.