Go CLI: admin list providers (#16243)

### What problem does this PR solve?

```
RAGFlow(admin)> list providers;
+----------------------+-------------------------------------------------------------+
| command              | error                                                       |
+----------------------+-------------------------------------------------------------+
| list_model_providers | 'list model providers' is implemented in enterprise edition |
+----------------------+-------------------------------------------------------------+

RAGFlow(admin)> add provider 'zhipu-ai';
+-------------+-----------------------------------------------------------+
| field       | value                                                     |
+-------------+-----------------------------------------------------------+
| command     | add_model_provider                                        |
| error       | 'add model provider' is implemented in enterprise edition |
| provider_id | admin                                                     |
| user_id     | zhipu-ai                                                  |
+-------------+-----------------------------------------------------------+

RAGFlow(admin)> delete provider 'zhipu-ai';
+-------------+--------------------------------------------------------------+
| field       | value                                                        |
+-------------+--------------------------------------------------------------+
| command     | delete_model_provider                                        |
| error       | 'delete model provider' is implemented in enterprise edition |
| provider_id | admin                                                        |
| user_id     | zhipu-ai                                                     |
+-------------+--------------------------------------------------------------+

RAGFlow(admin)> add provider 'zhipu-ai' instance 'instance1';
+---------------+-----------------------------------------------------------+
| field         | value                                                     |
+---------------+-----------------------------------------------------------+
| command       | add_model_instance                                        |
| error         | 'add model instance' is implemented in enterprise edition |
| instance_name | instance1                                                 |
| provider_id   | zhipu-ai                                                  |
| user_id       | admin                                                     |
+---------------+-----------------------------------------------------------+

RAGFlow(admin)> delete provider 'zhipu-ai' instance 'test'
+-------------+--------------------------------------------------------------+
| field       | value                                                        |
+-------------+--------------------------------------------------------------+
| instances   | [test]                                                       |
| provider_id | zhipu-ai                                                     |
| user_id     | admin                                                        |
| command     | delete_model_provider                                        |
| error       | 'delete model instance' is implemented in enterprise edition |
+-------------+--------------------------------------------------------------+

RAGFlow(admin)> add provider 'zhipu-ai' instance 'instance1' model 'xxx';
+---------------+--------------------------------------------------+
| field         | value                                            |
+---------------+--------------------------------------------------+
| command       | add_model                                        |
| error         | 'add model' is implemented in enterprise edition |
| instance_name | instance1                                        |
| model_names   | [xxx]                                            |
| provider_id   | zhipu-ai                                         |
| user_id       | admin                                            |
+---------------+--------------------------------------------------+

RAGFlow(admin)> delete provider 'zhipu-ai' instance 'test' model 'xxx';
+---------------+------------------------------------------------------+
| field         | value                                                |
+---------------+------------------------------------------------------+
| command       | delete_model_provider                                |
| error         | 'delete models' is implemented in enterprise edition |
| instance_name | test                                                 |
| models        | [xxx]                                                |
| provider_id   | zhipu-ai                                             |
| user_id       | admin                                                |
+---------------+------------------------------------------------------+

```

### 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-06-23 10:26:31 +08:00
committed by GitHub
parent 06ededb26a
commit b661e9c19e
11 changed files with 790 additions and 65 deletions

View File

@@ -291,7 +291,7 @@ func (h *Handler) ResetRoleDefaultModel(c *gin.Context) {
success(c, result, "Role default model set successfully")
}
func (h *Handler) ListProviders(c *gin.Context) {
func (h *Handler) ListModelProviders(c *gin.Context) {
keywords := ""
if queryKeywords := c.Query("available"); queryKeywords != "" {
@@ -300,23 +300,40 @@ func (h *Handler) ListProviders(c *gin.Context) {
// convert keywords to small case
keywords = strings.ToLower(keywords)
if keywords == "true" {
// list pool providers
providers, err := dao.GetModelProviderManager().ListProviders()
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeNotFound,
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
"data": providers,
})
result, err := h.service.ListModelProviders()
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "List model providers successfully")
}
type AddProviderRequest struct {
ProviderName string `json:"provider_name" binding:"required"`
}
func (h *Handler) AddModelProvider(c *gin.Context) {
var req AddProviderRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeBadRequest,
"message": err.Error(),
"data": false,
})
return
}
userID := c.GetString("user_id")
result, err := h.service.AddModelProvider(req.ProviderName, userID)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Model provider added successfully")
}
func (h *Handler) ShowProvider(c *gin.Context) {
@@ -344,6 +361,31 @@ func (h *Handler) ShowProvider(c *gin.Context) {
})
}
type DeleteProviderRequest struct {
ProviderNames []string `json:"provider_names" binding:"required"`
}
func (h *Handler) DeleteModelProvider(c *gin.Context) {
var req DeleteProviderRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Provider name is required",
})
return
}
userID := c.GetString("user_id")
result, err := h.service.DeleteModelProviders(userID, req.ProviderNames)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Model provider deleted successfully")
}
func (h *Handler) ListModels(c *gin.Context) {
providerName := c.Param("provider_name")
if providerName == "" {
@@ -400,6 +442,162 @@ func (h *Handler) ShowModel(c *gin.Context) {
})
}
type AddModelInstanceRequest struct {
InstanceName string `json:"instance_name" binding:"required"`
}
func (h *Handler) AddModelInstance(c *gin.Context) {
var req AddModelInstanceRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeBadRequest,
"message": err.Error(),
"data": false,
})
return
}
providerName := c.Param("provider_name")
if providerName == "" {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Provider name is required",
})
return
}
userID := c.GetString("user_id")
result, err := h.service.AddModelInstance(userID, providerName, req.InstanceName)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Model instance added successfully")
}
type DropModelInstanceRequest struct {
InstanceNames []string `json:"instance_names" binding:"required"`
}
func (h *Handler) DeleteModelInstance(c *gin.Context) {
providerName := c.Param("provider_name")
if providerName == "" {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "Provider name is required",
})
return
}
var req DropModelInstanceRequest
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")
result, err := h.service.DeleteModelInstances(userID, providerName, req.InstanceNames)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Model provider added successfully")
}
type AddModelsRequest struct {
ModelNames []string `json:"model_names" binding:"required"`
}
func (h *Handler) AddModels(c *gin.Context) {
var req AddModelsRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeBadRequest,
"message": err.Error(),
"data": false,
})
return
}
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
}
userID := c.GetString("user_id")
result, err := h.service.AddModels(userID, providerName, instanceName, req.ModelNames)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Models added successfully")
}
type DropModelsRequest struct {
ModelNames []string `json:"model_names" binding:"required"`
}
func (h *Handler) DeleteModels(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 DropModelsRequest
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")
result, err := h.service.DeleteModels(userID, providerName, instanceName, req.ModelNames)
if err != nil {
errorResponse(c, err.Error(), 500)
return
}
success(c, result, "Model deleted successfully")
}
type ListModelsOrShowModelRequest struct {
ModelName string `json:"model_name"`
}