-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[Feature] Add /tokenize and /detokenize OpenAI-compatible endpoints #5711
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test case?
Done @merrymercy |
Possible updates on this PR? Test failures don't seem to be related to this issue, and the added test cases are successful - i think it's due for a review. This feature would be really helpful. |
@zhyncs @merrymercy @zhaochenyang20 please review |
Is this PR still under review? It would be helpful to have it merged. |
Unfortunately there have been a few breaking changes to the OAI code so I've had to downgrade to 0.4.6-post5 to use this (and a tokenize endpoint is really useful!) |
Yeah the entire openai api interface has been refactored. I'll try implementing these endpoints for the new refractor ASAP and soon close this PR |
Thanks - your patch is the main reason I've been able to use sglang for my usecase! |
Thanks for your work, this will be really helpful! Is there an estimated timeline for merge or release? |
cc @thigger @Zyann7 @FeliceSchena @halaction apologies for the delay. opened a new PR with this feature compatible with the new openai interface. Hoping to have it merged soon hence i'll be closing this |
Thanks! I've been holding off upgrading sglang for this reason and will pull your new patch |
Motivation
requested in: #5653
Adds
/tokenize
and/detokenize
endpoints to the OpenAI-compatible API server.allows users to directly access the server's tokenizer for encoding text into token IDs and decoding token IDs back into text.
TokenizeRequest
/Response
andDetokenizeRequest
/Response
Pydantic models.adapter.py
utilizing theTokenizerManager
.http_server.py
.add_special_tokens
/skip_special_tokens
./v1/
path aliases.works like this:

Checklist