feat: add /tokenize endpoint for openai-compatible backend#2371
Conversation
Adds the /tokenize endpoint with the OpenAI-compatible (vLLM) backend: tokenize request/response schema, passthrough translator, endpoint spec wiring, tracing/metrics support, and docs. Model is required on the request union. Provider-specific backends follow in stacked PRs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: yxia216 <yxia216@bloomberg.net>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2371 +/- ##
==========================================
+ Coverage 84.82% 84.84% +0.02%
==========================================
Files 148 151 +3
Lines 21878 22086 +208
==========================================
+ Hits 18558 18739 +181
- Misses 2198 2215 +17
- Partials 1122 1132 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for a new /tokenize endpoint compatible with the vLLM tokenize API, including request/response schemas, endpoint parsing, translation, metrics, tracing, and documentation. The reviewer feedback highlights a critical issue where boolean fields that default to true (such as AddSpecialTokens and AddGenerationPrompt) are defined as plain bool with omitzero tags, which would cause explicit false values to be omitted during marshaling. The reviewer recommends changing these fields to *bool pointers and provides the necessary updates for validation, tracing, and unit tests to safely handle the pointer dereferencing.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: hustxiayang <yangxiast@gmail.com>
Signed-off-by: yxia216 <yxia216@bloomberg.net>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for a new /tokenize endpoint compatible with the vLLM tokenize API, allowing users to count tokens for both chat and completion requests. It adds the necessary API schemas, endpoint parsing, metrics, OpenInference tracing, and translation logic, along with comprehensive tests and documentation. The review feedback highlights several key improvement opportunities, including strengthening request validation to handle default values for conflicting fields, adding nil checks to prevent potential panics, avoiding implicit struct field promotion in tracing attributes, and ensuring robust error translation when the Content-Type header is missing.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: yxia216 <yxia216@bloomberg.net>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for a new /tokenize endpoint compatible with the vLLM tokenize API, including request/response schemas, endpoint specifications, OpenInference tracing, and translation logic. The review feedback highlights several improvement opportunities: optimizing JSON parsing in ParseBody by using a lightweight detector struct to avoid double unmarshaling, ensuring RequestUnion.Validate() triggers underlying ChatRequest validation, consistently accessing ChatRequest fields explicitly to prevent potential panics, and populating tokenUsage in ResponseBody to correctly track token usage metrics as documented.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: yxia216 <yxia216@bloomberg.net>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for a new /tokenize endpoint compatible with the vLLM tokenize API, allowing token counting for both chat messages and completion prompts. The changes span endpoint registration, API schema definitions, translation logic, metrics, tracing, and documentation. The review feedback highlights several opportunities to improve robustness by adding defensive nil checks for request, response, and body readers, as well as explicitly accessing embedded struct fields to avoid ambiguity.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: yxia216 <yxia216@bloomberg.net>
10d68b4 to
1bd275a
Compare
|
/retest |
aabchoo
left a comment
There was a problem hiding this comment.
Overall looks good to me!
Description
This is split from #1650. Specifically this is to support tokenization for openai-compatible backend.