Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

server delete model api #398

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions nexa/gguf/server/nexa_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
NanoLlavaChatHandler,
)
from nexa.gguf.llama._utils_transformers import suppress_stdout_stderr
from nexa.general import add_model_to_list, default_use_processes, download_file_with_progress, get_model_info, is_model_exists, pull_model
from nexa.general import add_model_to_list, default_use_processes, download_file_with_progress, get_model_info, is_model_exists, pull_model, remove_model
from nexa.gguf.llama.llama import Llama
from faster_whisper import WhisperModel
import numpy as np
Expand Down Expand Up @@ -102,7 +102,6 @@
projector_path = None
SAMPLING_RATE = 16000


# Request Classes
class GenerationRequest(BaseModel):
prompt: str = "Tell me a story"
Expand Down Expand Up @@ -272,6 +271,8 @@ class DownloadModelRequest(BaseModel):
"protected_namespaces": ()
}

class DeleteModelRequest(BaseModel):
model_path: str

class ActionRequest(BaseModel):
prompt: str = ""
Expand Down Expand Up @@ -1228,6 +1229,13 @@ async def list_models():
logging.error(f"Error listing models: {e}")
raise HTTPException(status_code=500, detail=str(e))

@app.delete("/v1/delete_model", tags=["Model"])
async def delete_model(request: DeleteModelRequest):
"""Delete a model from local model list"""
deleted_model_path = remove_model(request.model_path)
if not deleted_model_path:
raise HTTPException(status_code=404, detail=f"Model not found: {request.model_path}")
return JSONResponse(content={"status": "success", "message": f"Successfully deleted model: {request.model_path}"})

@app.post("/v1/completions", tags=["NLP"])
async def generate_text(request: GenerationRequest):
Expand Down