MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / FinetuneCreate

Method FinetuneCreate

api/handler/model.go:519–585  ·  view source on GitHub ↗

FinetuneCreate godoc @Security ApiKey @Summary create a finetune instance @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

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

517// @Failure 500 {object} types.APIInternalServerError "Internal server error"
518// @Router /models/{namespace}/{name}/finetune [post]
519func (h *ModelHandler) FinetuneCreate(ctx *gin.Context) {
520 currentUser := httpbase.GetCurrentUser(ctx)
521 if currentUser == "" {
522 httpbase.UnauthorizedError(ctx, component.ErrUserNotFound)
523 return
524 }
525
526 namespace, name, err := common.GetNamespaceAndNameFromContext(ctx)
527 if err != nil {
528 slog.Error("failed to get namespace from context", "error", err)
529 httpbase.BadRequest(ctx, err.Error())
530 return
531 }
532 allow, err := h.c.AllowAdminAccess(ctx, types.ModelRepo, namespace, name, currentUser)
533 if err != nil {
534 slog.Error("failed to check user permission", "error", err)
535 httpbase.ServerError(ctx, errors.New("failed to check user permission"))
536 return
537 }
538 if !allow {
539 slog.Info("user is not allowed to run model", slog.String("namespace", namespace),
540 slog.String("name", name), slog.Any("username", currentUser))
541 httpbase.UnauthorizedError(ctx, errors.New("user not allowed to run model"))
542 return
543 }
544
545 var req types.InstanceRunReq
546 if err := ctx.ShouldBindJSON(&req); err != nil {
547 slog.Error("Bad request format", "error", err)
548 httpbase.BadRequest(ctx, err.Error())
549 return
550 }
551
552 modelReq := &types.ModelRunReq{
553 DeployName: req.DeployName,
554 ClusterID: req.ClusterID,
555 ResourceID: req.ResourceID,
556 RuntimeFrameworkID: req.RuntimeFrameworkID,
557 MinReplica: 1,
558 MaxReplica: 1,
559 SecureLevel: 2,
560 Revision: req.Revision,
561 }
562
563 ftReq := types.DeployActReq{
564 Namespace: namespace,
565 Name: name,
566 CurrentUser: currentUser,
567 DeployType: types.FinetuneType,
568 }
569
570 deployID, err := h.c.Deploy(ctx, ftReq, *modelReq)
571 if err != nil {
572 slog.Error("failed to deploy model as notebook instance", slog.String("namespace", namespace),
573 slog.String("name", name), slog.Any("error", err))
574 httpbase.ServerError(ctx, err)
575 return
576 }

Callers

nothing calls this directly

Calls 9

GetCurrentUserFunction · 0.92
UnauthorizedErrorFunction · 0.92
BadRequestFunction · 0.92
ServerErrorFunction · 0.92
OKFunction · 0.92
ErrorMethod · 0.80
AllowAdminAccessMethod · 0.80
DeployMethod · 0.65

Tested by

no test coverage detected