Conversation
Contributor
There was a problem hiding this comment.
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
estimateImageTokensutil 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
billableoption inestimateImageTokensto verify that billed token counts (withbillable: 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
modelhere fromstringtoVisionModel(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 }, |
There was a problem hiding this comment.
[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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.