Skip to content
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

Update count_tokens.py #459

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Conversation

rachelsaunders
Copy link
Contributor

Description of the change

  • integrated returns into main snippets
  • updated code comments for clarity and completeness
  • pulled text of prompts out of the requests to generate_content

Motivation

Alignment and clarification of docs snippets

Type of change

Documentation - code snippets

Checklist

  • I have performed a self-review of my code.
  • I have added detailed comments to my code where applicable.
  • I have verified that my change does not break existing code.
  • My PR is based on the latest changes of the main branch (if unsure, please run git pull --rebase upstream main).
  • I am familiar with the Google Style Guide for the language I have coded in.
  • I have read through the Contributing Guide and signed the Contributor License Agreement.

- integrated returns into main snippet
- updated code comments
- pulled text of prompts out of the requests to generate_content
@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Jul 12, 2024
@logankilpatrick logankilpatrick merged commit 4e1dcd6 into google-gemini:main Jul 12, 2024
7 of 8 checks passed
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Jul 12, 2024
Copy link

@eliben eliben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by review

# Returns the "context window" for the model (the combined input and output token limits)

# Returns the "context window" for the model,
# which is the combined input and output token limits.
print(f"{model_info.input_token_limit=}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the output is printed as key=value, whereas in most other places it's key: value.
Is there some system/method behind this?

print(response.usage_metadata)
# ( prompt_token_count: 11, candidates_token_count: 73, total_token_count: 84 )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the token count differs between the two approaches: 10 vs 11

print(response.usage_metadata)
# ( prompt_token_count: 264, candidates_token_count: 80, total_token_count: 345 )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some off-by-1 issues here: prompt token count 263 vs 264
Also 264+80 != 345

prompt = "Please give a short summary of this file."

# Call `count_tokens` to get input token count
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample uploads a text file, not a video - should the comment be amended?

eliben added a commit to google/generative-ai-go that referenced this pull request Jul 12, 2024
Aligning with the Python samples per
google-gemini/generative-ai-python#459

Main change is in the way output of snippets is marked
TadeKDev pushed a commit to TadeKDev/Generative-AI-go that referenced this pull request Sep 23, 2024
Aligning with the Python samples per
google-gemini/generative-ai-python#459

Main change is in the way output of snippets is marked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants