Skip to content

Conversation

@ultmaster
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 11, 2025 06:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds image token counting functionality and integrates token counts into the LSP server and VSCode panel, along with corresponding UI updates.

  • Introduce estimateImageTokens util to compute image token usage for OpenAI vision models
  • Integrate token computation in the LSP server (computeTokens) and return counts in preview responses
  • Update VSCode panel UI and types to display per-message and total token counts

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/poml/util/tokenCounterImage.ts New helper to estimate image tokens for vision models
packages/poml/util/image.ts Utility to extract image dimensions using sharp
packages/poml/tests/tokenCounterImage.test.ts Tests for image token estimator (patch & detail modes)
packages/poml-vscode/panel/types.ts Extend preview types with returnTokenCounts
packages/poml-vscode/panel/panel.ts Populate returnTokenCounts based on language model
packages/poml-vscode/panel/content.tsx Render per-message and total token counts in UI
packages/poml-vscode/lsp/server.ts Compute and cache token counts for text/image content
package.json Add js-tiktoken dependency for token encoding
media/style.css Styles for token count display
Comments suppressed due to low confidence (2)

packages/poml/tests/tokenCounterImage.test.ts:5

  • Add test cases for the billable option in estimateImageTokens to verify that billed token counts (with billable: true) produce the correct rounded values.
  const cases: { w: number; h: number; model: VisionModel; detail?: DetailLevel; expected: number }[] = [

packages/poml-vscode/panel/types.ts:57

  • Consider tightening the type of model here from string to VisionModel (or a union of supported model names) to prevent invalid model names at compile time.
  returnTokenCounts?: { model: string };

const languageModelSettings = this.getLanguageModelSettings(resource);
const requestParams: PreviewParams = {
uri: resource.toString(),
returnTokenCounts: { model: languageModelSettings.model },
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

[nitpick] The returnTokenCounts assignment is duplicated in two methods; extracting it into a helper (e.g. buildPreviewParams) would reduce repetition and simplify future updates.

Suggested change
returnTokenCounts: { model: languageModelSettings.model },
...this.buildPreviewParams(languageModelSettings),

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster merged commit 6a88160 into main Jul 11, 2025
4 checks passed
@ultmaster ultmaster deleted the token-counter branch August 27, 2025 00:52
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