-
Notifications
You must be signed in to change notification settings - Fork 360
feat(router): add initial support for anthropic messages endpoint #775
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Copyright 2024-2025 The vLLM Production Stack Authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from fastapi import APIRouter, BackgroundTasks, Request | ||
|
|
||
| from vllm_router.log import init_logger | ||
| from vllm_router.services.request_service.request import route_general_request | ||
|
|
||
| logger = init_logger(__name__) | ||
| anthropic_router = APIRouter() | ||
|
|
||
|
|
||
| @anthropic_router.post("/v1/messages") | ||
| async def route_anthropic_messages(request: Request, background_tasks: BackgroundTasks): | ||
| """Route Anthropic-compatible messages requests to the backend.""" | ||
| return await route_general_request(request, "/v1/messages", background_tasks) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ class ModelType(enum.Enum): | |
| score = "score" | ||
| transcription = "transcription" | ||
| vision = "vision" | ||
| messages = "messages" | ||
|
|
||
| @staticmethod | ||
| def get_url(model_type: str): | ||
|
|
@@ -89,6 +90,8 @@ def get_url(model_type: str): | |
| return "/v1/score" | ||
| case ModelType.transcription: | ||
| return "/v1/audio/transcriptions" | ||
| case ModelType.messages: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly cosmetics at the moment, since compatible models presumably have |
||
| return "/v1/messages" | ||
|
|
||
| @staticmethod | ||
| def get_test_payload(model_type: str): | ||
|
|
@@ -112,6 +115,17 @@ def get_test_payload(model_type: str): | |
| return {"query": "Hello", "documents": ["Test"]} | ||
| case ModelType.score: | ||
| return {"encoding_format": "float", "text_1": "Test", "test_2": "Test2"} | ||
| case ModelType.messages: | ||
| return { | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": "Hello", | ||
| } | ||
| ], | ||
| "temperature": 0.0, | ||
| "max_tokens": 3, | ||
| } | ||
|
Comment on lines
+118
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this makes sense as we're actually inside |
||
| case ModelType.transcription: | ||
| if _SILENT_WAV_BYTES is not None: | ||
| logger.debug("=====Silent WAV Bytes is being used=====") | ||
|
|
||
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.
I'm adding a separate module just in case, so we can add future Anthropic-compatible endpoints here if needed.
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.
Is there a risk that adding this endpoint to the main router module?
Uh oh!
There was an error while loading. Please reload this page.
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.
@zerofishnoodles it just made sense to me to split this up logically since it's not part of the OpenAI OpenAPI spec. And we can later add more anthropic endpoints here.
But if you prefer I can put it into the main one, I just thought different providers might make sense in separate routers.
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.
I see. Can you put it into the main one for now? Since this router module is not the same level of abstract as the other existing one. If there is more anthropic ep that may have contention with the existing one, we can do refactoring at that time.