-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Feature Request : Incorporation of Token Count Feature for Gemini #373
Comments
You mean before you do the request? I can't quite imagine how that would fit into the existing ellmer API. |
Hi @hadley , Assume we have prompt and then some data (may be a pdf or an image file) which are passed as inputs to Gemini. As an end user, we would be interested to know how much input tokens are being consumed . This helps us in optimizing the prompt and the type of input which we can pass (obviously having control over the cost ). The Output token in gemini (max can be 8124 and configurable). This is very similar to computing token cost Sharing you python sample code from gemini documentation (vertex ai) from google import genai
from google.genai.types import HttpOptions, Part
client = genai.Client(http_options=HttpOptions(api_version="v1"))
contents = [
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/video/pixel8.mp4",
mime_type="video/mp4",
),
"Provide a description of the video.",
]
response = client.models.count_tokens(
model="gemini-2.0-flash-001",
contents=contents,
)
print(response) Example output: Thanks |
I understand how this could be done, but it's very far from the existing ellmer interface and I don't think many other proividers provide a way to determine the number of tokens apart from actually doing the request. |
Anthropic also supports it https://docs.anthropic.com/en/docs/build-with-claude/token-counting Last time I looked, OpenAI didn't appear to have API for this, but in Python there is |
Hi @cpsievert , Running this code shall give the count of input and output tokens Thanks |
Hi Team,
Request you to incorporate the token count feature inside gemini.R as it will help users to get a view of tokens (both input and output) for cost budgeting (informed decision making)
Documentation Reference: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/get-token-count
Thanks
Arun
The text was updated successfully, but these errors were encountered: