Skip to content

Bundle: Added "count-tokens" procedure to inform about the size#59

Merged
amotl merged 1 commit into
mainfrom
bundle-count-tokens
Jul 28, 2025
Merged

Bundle: Added "count-tokens" procedure to inform about the size#59
amotl merged 1 commit into
mainfrom
bundle-count-tokens

Conversation

@amotl
Copy link
Copy Markdown
Member

@amotl amotl commented Jul 27, 2025

... of the outcome. Sonnet and Opus are limited to 200_000 input tokens.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 27, 2025

Walkthrough

The changes introduce a new utility function to count tokens in output files using both GPT-4o and Anthropic Claude tokenizers. This function is integrated into the bundle process, and relevant documentation and dependencies are updated to reflect the new capability and model token limitations.

Changes

Cohort / File(s) Change Summary
Documentation
CHANGES.md
Updated changelog to document the addition of the "count-tokens" procedure and model token limitations.
Project Configuration
pyproject.toml
Added tiktoken and anthropic dependencies for token counting and LLM support; adjusted version constraints.
Token Counting Utility
src/cratedb_about/bundle/util.py
Introduced count_tokens function to compute and log token counts using GPT-4o and Anthropic APIs.
Bundle Integration
src/cratedb_about/bundle/llmstxt.py
Integrated count_tokens call after generating the LLM output file in the bundle process.

Sequence Diagram(s)

sequenceDiagram
    participant Builder as LllmsTxtBuilder
    participant Util as util.count_tokens
    participant GPT as tiktoken
    participant Anthropic as Anthropic API

    Builder->>Builder: Write llms-full.txt
    Builder->>Util: count_tokens(llms-full.txt)
    Util->>GPT: Encode file content
    GPT-->>Util: Return GPT token count
    alt If ANTHROPIC_API_KEY set
        Util->>Anthropic: count_tokens(system prompt, user message)
        Anthropic-->>Util: Return Anthropic token count
    end
    Util->>Util: Log token counts and warnings if necessary
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • bmunkholm
  • surister
  • hammerhead

Poem

A hop and a skip, I count every byte,
Tokens in files, from morning till night.
GPT and Claude, I tally with care,
If limits are breached, I’ll send out a flare!
With dependencies fresh and the changelog in sight,
This bunny ensures your bundles are light.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7b8426 and 73004d5.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • pyproject.toml (2 hunks)
  • src/cratedb_about/bundle/llmstxt.py (2 hunks)
  • src/cratedb_about/bundle/util.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • CHANGES.md
  • src/cratedb_about/bundle/llmstxt.py
  • pyproject.toml
  • src/cratedb_about/bundle/util.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bundle-count-tokens

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c46b3b2 and a7b8426.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • pyproject.toml (2 hunks)
  • src/cratedb_about/bundle/llmstxt.py (2 hunks)
  • src/cratedb_about/bundle/util.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
CHANGES.md (3)

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:16:33.171Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

src/cratedb_about/bundle/llmstxt.py (4)

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:20:35.508Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

Learnt from: amotl
PR: crate/about#0
File: :0-0
Timestamp: 2025-04-16T14:16:33.171Z
Learning: When creating content for an llms.txt file (following the llmstxt.org specification), consistent and straightforward language takes precedence over stylistic variation since the primary audience is language models rather than human readers.

Learnt from: amotl
PR: #32
File: src/cratedb_about/outline/cratedb-outline.yaml:321-329
Timestamp: 2025-05-15T21:25:54.870Z
Learning: In the CrateDB outline YAML, content organization prioritizes thematic grouping (keeping related topics together) over content type grouping (separating tutorials from reference docs), as demonstrated by placing the multi-tenancy tutorial alongside user management and privileges documentation in the API section.

🧬 Code Graph Analysis (1)
src/cratedb_about/bundle/llmstxt.py (1)
src/cratedb_about/bundle/util.py (1)
  • count_tokens (11-43)
🔇 Additional comments (7)
src/cratedb_about/bundle/util.py (2)

6-6: LGTM - Clean import organization.

The tiktoken import is properly placed with other third-party imports.


24-24: Model Name Verification Complete

The model identifier claude-sonnet-4-20250514 is confirmed as current and valid per Anthropic’s July 2025 API documentation. No changes are needed.

CHANGES.md (1)

5-6: LGTM - Clear and informative changelog entry.

The changelog entry clearly documents the new functionality and provides important context about the token limitations for Sonnet and Opus models.

src/cratedb_about/bundle/llmstxt.py (2)

11-11: LGTM - Proper import placement.

The import is correctly placed with other project-specific imports and follows the established import organization.


54-54: LGTM - Well-positioned token counting integration.

The token counting call is appropriately placed after the llms-full.txt file is generated, providing immediate feedback about the file size constraints.

pyproject.toml (2)

82-82: LGTM - Appropriate tiktoken dependency addition.

The tiktoken dependency is correctly added to the main dependencies since it's used unconditionally for GPT token counting, with a reasonable version constraint.


95-95: LGTM - Logical placement of anthropic dependency.

The anthropic dependency is appropriately placed in the optional LLM dependencies group since it's only used when the API key is available.

Comment thread src/cratedb_about/bundle/util.py
Comment thread src/cratedb_about/bundle/util.py
Comment thread src/cratedb_about/bundle/util.py
@amotl amotl force-pushed the shrink-llms-txt branch from c46b3b2 to e8d773f Compare July 27, 2025 23:12
@amotl amotl force-pushed the bundle-count-tokens branch from a7b8426 to 6f1b28a Compare July 27, 2025 23:14
@amotl amotl requested review from WalBeh and hammerhead July 27, 2025 23:39
@amotl amotl force-pushed the bundle-count-tokens branch from 6f1b28a to 3a01872 Compare July 27, 2025 23:40
@amotl amotl marked this pull request as ready for review July 27, 2025 23:40
@amotl amotl force-pushed the bundle-count-tokens branch from 3a01872 to 6cd40db Compare July 27, 2025 23:51
@amotl amotl force-pushed the shrink-llms-txt branch 3 times, most recently from 173220a to 16bc361 Compare July 28, 2025 01:44
@amotl amotl force-pushed the bundle-count-tokens branch from 6cd40db to be7459f Compare July 28, 2025 01:47
@amotl amotl force-pushed the bundle-count-tokens branch from be7459f to 18dc78e Compare July 28, 2025 01:48
Base automatically changed from shrink-llms-txt to main July 28, 2025 08:26
... of the outcome. Sonnet and Opus are limited to 200_000 input tokens.
@amotl amotl force-pushed the bundle-count-tokens branch from 18dc78e to 73004d5 Compare July 28, 2025 08:27
@amotl amotl merged commit 7e89205 into main Jul 28, 2025
6 checks passed
@amotl amotl deleted the bundle-count-tokens branch July 28, 2025 09:20
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.

2 participants