ModelRun godoc @Security ApiKey @Summary run model as inference @Tags Model @Accept json @Produce json @Param namespace path string true "namespace" @Param name path string true "name" @Param current_user query string true "current_user" @Param
(ctx *gin.Context)
| 430 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 431 | // @Router /models/{namespace}/{name}/run [post] |
| 432 | func (h *ModelHandler) DeployDedicated(ctx *gin.Context) { |
| 433 | currentUser := httpbase.GetCurrentUser(ctx) |
| 434 | if currentUser == "" { |
| 435 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 436 | return |
| 437 | } |
| 438 | |
| 439 | namespace, name, err := common.GetNamespaceAndNameFromContext(ctx) |
| 440 | if err != nil { |
| 441 | slog.Error("failed to get namespace from context", "error", err) |
| 442 | httpbase.BadRequest(ctx, err.Error()) |
| 443 | return |
| 444 | } |
| 445 | allow, err := h.c.AllowReadAccess(ctx, types.ModelRepo, namespace, name, currentUser) |
| 446 | if err != nil { |
| 447 | slog.Error("failed to check user permission", "error", err) |
| 448 | httpbase.ServerError(ctx, errors.New("failed to check user permission")) |
| 449 | return |
| 450 | } |
| 451 | if !allow { |
| 452 | slog.Info("user not allowed to run model", slog.String("namespace", namespace), |
| 453 | slog.String("name", name), slog.Any("username", currentUser)) |
| 454 | httpbase.UnauthorizedError(ctx, errors.New("user not allowed to run model")) |
| 455 | return |
| 456 | } |
| 457 | |
| 458 | var req types.ModelRunReq |
| 459 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 460 | slog.Error("Bad request format", "error", err) |
| 461 | httpbase.BadRequest(ctx, err.Error()) |
| 462 | return |
| 463 | } |
| 464 | |
| 465 | if req.Revision == "" { |
| 466 | req.Revision = "main" // default repo branch |
| 467 | } |
| 468 | |
| 469 | if req.MinReplica < 0 || req.MaxReplica < 0 || req.MinReplica > req.MaxReplica { |
| 470 | slog.Error("Bad request setting for replica", slog.Any("MinReplica", req.MinReplica), slog.Any("MaxReplica", req.MaxReplica)) |
| 471 | httpbase.BadRequest(ctx, "Bad request setting for replica") |
| 472 | return |
| 473 | } |
| 474 | |
| 475 | _, err = h.sc.CheckRequest(ctx, &req) |
| 476 | if err != nil { |
| 477 | slog.Error("failed to check sensitive request", slog.Any("error", err)) |
| 478 | httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) |
| 479 | return |
| 480 | } |
| 481 | |
| 482 | epReq := types.DeployActReq{ |
| 483 | Namespace: namespace, |
| 484 | Name: name, |
| 485 | CurrentUser: currentUser, |
| 486 | DeployType: types.InferenceType, |
| 487 | } |
| 488 | deployID, err := h.c.Deploy(ctx, epReq, req) |
| 489 | if err != nil { |
nothing calls this directly
no test coverage detected