Go: add drop instance models (#14485)

### What problem does this PR solve?

1. drop instance model
2. Fix issue of drop instance but not drop models.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-04-29 19:18:49 +08:00
committed by GitHub
parent 0e1477eb23
commit 261be81127
9 changed files with 237 additions and 74 deletions

View File

@@ -682,7 +682,7 @@ func (h *ProviderHandler) AddCustomModel(c *gin.Context) {
return
}
if req.ModelType == "" {
if req.ModelTypes == nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Model type is required",
@@ -707,6 +707,54 @@ func (h *ProviderHandler) AddCustomModel(c *gin.Context) {
}
type DropInstanceModelRequest struct {
Models []string `json:"models" binding:"required"`
}
func (h *ProviderHandler) DropInstanceModels(c *gin.Context) {
providerName := c.Param("provider_name")
if providerName == "" {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Provider name is required",
})
return
}
instanceName := c.Param("instance_name")
if instanceName == "" {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Instance name is required",
})
return
}
var req DropInstanceModelRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeBadRequest,
"message": err.Error(),
})
return
}
userID := c.GetString("user_id")
_, err := h.modelProviderService.DropInstanceModels(providerName, instanceName, userID, req.Models)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeServerError,
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
})
}
type ChatToModelRequest struct {
ProviderName *string `json:"provider_name"`
InstanceName *string `json:"instance_name"`
@@ -768,6 +816,7 @@ func (h *ProviderHandler) ChatToModel(c *gin.Context) {
chatConfig := models.ChatConfig{
Thinking: &req.Thinking,
Stream: &req.Stream,
Vision: nil,
Stop: &[]string{},
DoSample: nil,
MaxTokens: nil,