-
Notifications
You must be signed in to change notification settings - Fork 756
FEAT: [UI] add model feature in Launch Model list. #4102
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
Open
yiboyasss
wants to merge
25
commits into
xorbitsai:main
Choose a base branch
from
yiboyasss:FEAT/add-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
80e60a5
feat: Add model feature in Launch Model list
yiboyasss 0eab739
fix: detail
yiboyasss 3f859be
fix: login dialog
yiboyasss 542abc5
fix: detail
yiboyasss 668502f
FEAT:add model backend
OliverBryant 3cc4aa1
FEAT:add model backend
OliverBryant 79ad0d0
remove model_specs verify
OliverBryant 424ec5e
model_size_in_billions
OliverBryant 05a7b06
fix: frontend
yiboyasss 43bfd12
fix: detail
yiboyasss 6dd1dcd
Function 1: Add a specific model from ModelHub
OliverBryant 52d61e6
Function 1: Add a specific model from ModelHub
OliverBryant bb029ad
Function 2: One-Click Model Update
OliverBryant d332f4b
fix: frontend
yiboyasss 05b1804
fix: request bug
yiboyasss 77b7e90
Function 2: One-Click Model Update
OliverBryant 43bf76e
Function 2: One-Click Model Update
OliverBryant 60e6aba
flake8 black isort
OliverBryant 5c40285
mypy
OliverBryant 9b56f30
single json
OliverBryant 071fcfd
remove builtin.py
OliverBryant 57285ae
add model and update model type to worker
OliverBryant 37d0b77
add model and update model type to worker
OliverBryant 04e7e50
remove unregister_model
OliverBryant 8df104a
num1
OliverBryant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,15 @@ class RegisterModelRequest(BaseModel): | |
| persist: bool | ||
|
|
||
|
|
||
| class AddModelRequest(BaseModel): | ||
| model_type: str | ||
| model_json: Dict[str, Any] | ||
|
|
||
|
|
||
| class UpdateModelRequest(BaseModel): | ||
| model_type: str | ||
|
|
||
|
|
||
| class BuildGradioInterfaceRequest(BaseModel): | ||
| model_type: str | ||
| model_name: str | ||
|
|
@@ -900,6 +909,26 @@ async def internal_exception_handler(request: Request, exc: Exception): | |
| else None | ||
| ), | ||
| ) | ||
| self._router.add_api_route( | ||
| "/v1/models/add", | ||
| self.add_model, | ||
| methods=["POST"], | ||
| dependencies=( | ||
| [Security(self._auth_service, scopes=["models:add"])] | ||
| if self.is_authenticated() | ||
| else None | ||
| ), | ||
| ) | ||
| self._router.add_api_route( | ||
| "/v1/models/update_type", | ||
| self.update_model_type, | ||
| methods=["POST"], | ||
| dependencies=( | ||
| [Security(self._auth_service, scopes=["models:add"])] | ||
| if self.is_authenticated() | ||
| else None | ||
| ), | ||
| ) | ||
| self._router.add_api_route( | ||
| "/v1/cache/models", | ||
| self.list_cached_models, | ||
|
|
@@ -3123,25 +3152,114 @@ async def unregister_model(self, model_type: str, model_name: str) -> JSONRespon | |
| raise HTTPException(status_code=500, detail=str(e)) | ||
| return JSONResponse(content=None) | ||
|
|
||
| async def add_model(self, request: Request) -> JSONResponse: | ||
| try: | ||
|
|
||
| # Parse request | ||
| raw_json = await request.json() | ||
|
|
||
| if "model_type" in raw_json and "model_json" in raw_json: | ||
| body = AddModelRequest.parse_obj(raw_json) | ||
| model_type = body.model_type | ||
| model_json = body.model_json | ||
| else: | ||
| model_json = raw_json | ||
|
|
||
| # Priority 1: Check if model_type is explicitly provided in the JSON | ||
| if "model_type" in model_json: | ||
| model_type = model_json["model_type"] | ||
| logger.info( | ||
| f"[DEBUG] Using explicit model_type from JSON: {model_type}" | ||
| ) | ||
| else: | ||
| # model_type is required in the JSON when using unwrapped format | ||
| logger.error( | ||
| f"[DEBUG] model_type not provided in JSON, this is required" | ||
| ) | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="model_type is required in the model JSON. Supported types: LLM, embedding, audio, image, video, rerank", | ||
| ) | ||
|
|
||
| supervisor_ref = await self._get_supervisor_ref() | ||
|
|
||
| # Call supervisor | ||
| await supervisor_ref.add_model(model_type, model_json) | ||
|
|
||
| except ValueError as re: | ||
| logger.error(f"ValueError in add_model API: {re}", exc_info=True) | ||
| logger.error(f"ValueError details: {type(re).__name__}: {re}") | ||
| raise HTTPException(status_code=400, detail=str(re)) | ||
| except Exception as e: | ||
| logger.error(f"Unexpected error in add_model API: {e}", exc_info=True) | ||
| logger.error(f"Error details: {type(e).__name__}: {e}") | ||
| import traceback | ||
|
|
||
| logger.error(f"Full traceback: {traceback.format_exc()}") | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
| return JSONResponse( | ||
| content={"message": f"Model added successfully for type: {model_type}"} | ||
| ) | ||
|
|
||
| async def update_model_type(self, request: Request) -> JSONResponse: | ||
| try: | ||
| # Parse request | ||
| raw_json = await request.json() | ||
|
|
||
| body = UpdateModelRequest.parse_obj(raw_json) | ||
| model_type = body.model_type | ||
|
|
||
| # Get supervisor reference | ||
| supervisor_ref = await self._get_supervisor_ref() | ||
|
|
||
| await supervisor_ref.update_model_type(model_type) | ||
|
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. Ditto. |
||
|
|
||
| except ValueError as re: | ||
| logger.error(f"ValueError in update_model_type API: {re}", exc_info=True) | ||
| raise HTTPException(status_code=400, detail=str(re)) | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Unexpected error in update_model_type API: {e}", exc_info=True | ||
| ) | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
| return JSONResponse( | ||
| content={ | ||
| "message": f"Model configurations updated successfully for type: {model_type}" | ||
| } | ||
| ) | ||
|
|
||
| async def list_model_registrations( | ||
| self, model_type: str, detailed: bool = Query(False) | ||
| ) -> JSONResponse: | ||
| try: | ||
|
|
||
| data = await (await self._get_supervisor_ref()).list_model_registrations( | ||
| model_type, detailed=detailed | ||
| ) | ||
|
|
||
| # Remove duplicate model names. | ||
| model_names = set() | ||
| final_data = [] | ||
| for item in data: | ||
| if item["model_name"] not in model_names: | ||
| model_names.add(item["model_name"]) | ||
| final_data.append(item) | ||
|
|
||
| return JSONResponse(content=final_data) | ||
| except ValueError as re: | ||
| logger.error( | ||
| f"ValueError in list_model_registrations: {re}", | ||
| exc_info=True, | ||
| ) | ||
| logger.error(re, exc_info=True) | ||
| raise HTTPException(status_code=400, detail=str(re)) | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Unexpected error in list_model_registrations: {e}", | ||
| exc_info=True, | ||
| ) | ||
| logger.error(e, exc_info=True) | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.