Skip to content

Added count_tokens implementation for Go #37

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cestercian
Copy link

This PR adds token counting functionality to the Go API examples, following the structure of the JavaScript and Python implementations. It demonstrates token counting for various content types using the Gemini API.

Changes

  • Added count_tokens.go with implementations for:
    • Text-only token counting
    • Chat history token counting
    • Multimodal content (images, video, PDFs)
    • System instruction token counting
  • Added count_tokens_test.go with test cases

Implementation Details

  • Follows the same structure and documentation style as JS and Python examples
  • Maintains region markers for documentation generation
  • Includes proper error handling and Go best practices
  • Ensures correct copyright headers and license information

Testing

  • Validates token counts are greater than zero
  • Confirms usage metadata contains valid values
  • Checks combined token counts exceed individual counts where applicable

This provides a reference for developers using the Go SDK to understand token usage with the Gemini API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant