mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
Go: show model and list all models (#16272)
### What problem does this PR solve? ``` RAGFlow(admin)> show model 'abc'; +------------+----------------------------------------------------------------+ | field | value | +------------+----------------------------------------------------------------+ | command | get_model_by_model_name | | error | 'get model by model name' is implemented in enterprise edition | | model_name | abc | +------------+----------------------------------------------------------------+ RAGFlow(admin)> list models; +-----------------+--------------------------------------------------------+ | command | error | +-----------------+--------------------------------------------------------+ | list_all_models | 'list all models' is implemented in enterprise edition | +-----------------+--------------------------------------------------------+ ``` ### Type of change - [x] Refactoring Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -306,7 +306,7 @@ func (c *CLI) AdminGrantUserAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, nil)
|
||||
@@ -342,7 +342,7 @@ func (c *CLI) AdminRevokeUserAdminCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
@@ -567,7 +567,7 @@ func (c *CLI) AdminCreateUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
@@ -622,7 +622,7 @@ func (c *CLI) AdminActivateUser(cmd *Command) (ResponseIf, error) {
|
||||
"activate_status": activateStatus,
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/activate", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
|
||||
@@ -678,7 +678,7 @@ func (c *CLI) AdminAlterUserPassword(cmd *Command) (ResponseIf, error) {
|
||||
"new_password": encryptedPassword,
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/password", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
|
||||
@@ -1226,7 +1226,7 @@ func (c *CLI) AdminDropUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
@@ -1267,7 +1267,7 @@ func (c *CLI) AdminDropUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("api_key not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys/%s", encodedUserName, apiKey)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
|
||||
@@ -1310,7 +1310,7 @@ func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
|
||||
iterations = val
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
|
||||
|
||||
if iterations > 1 {
|
||||
@@ -1361,7 +1361,7 @@ func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -1815,7 +1815,7 @@ func (c *CLI) AdminShowUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -1925,7 +1925,7 @@ func (c *CLI) AdminShowUserActivityCommand(cmd *Command) (ResponseIf, error) {
|
||||
"email": email,
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/activity", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
|
||||
@@ -1960,7 +1960,7 @@ func (c *CLI) AdminShowUserSummaryCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/summary", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2005,7 +2005,7 @@ func (c *CLI) AdminShowUserDatasetCommand(cmd *Command) (ResponseIf, error) {
|
||||
"dataset": dataset,
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/dataset", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
|
||||
@@ -2041,7 +2041,7 @@ func (c *CLI) AdminShowUserStorageCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/storage", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2077,7 +2077,7 @@ func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/quota", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2113,7 +2113,7 @@ func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/index", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2149,7 +2149,7 @@ func (c *CLI) AdminShowUserPermissionCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(email)
|
||||
encodedUserName := common.EncodeToBase64(email)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2600,7 +2600,7 @@ func (c *CLI) AdminPurgeUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
"preview": preview,
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/data", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
|
||||
@@ -2745,7 +2745,7 @@ func (c *CLI) AdminListUserDatasetsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2780,7 +2780,7 @@ func (c *CLI) AdminListUserAgentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/agents", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2815,7 +2815,7 @@ func (c *CLI) AdminListUserChatsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/chats", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2850,7 +2850,7 @@ func (c *CLI) AdminListUserSearchesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/searches", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2885,7 +2885,7 @@ func (c *CLI) AdminListUserModelsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/models", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2920,7 +2920,7 @@ func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/files", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -2956,7 +2956,7 @@ func (c *CLI) AdminListUserKeysCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -3001,7 +3001,7 @@ func (c *CLI) AdminListUserProvidersCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/providers", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -3042,7 +3042,7 @@ func (c *CLI) AdminListUserProviderInstancesCommand(cmd *Command) (ResponseIf, e
|
||||
return nil, fmt.Errorf("provider_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/providers/%s/instances", encodedUserName, providerName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -3086,7 +3086,7 @@ func (c *CLI) AdminListUserProviderInstanceModelsCommand(cmd *Command) (Response
|
||||
return nil, fmt.Errorf("instance_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/providers/%s/instances/%s/models", encodedUserName, providerName, instanceName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
@@ -3122,7 +3122,7 @@ func (c *CLI) AdminListUserDefaultModelsCommand(cmd *Command) (ResponseIf, error
|
||||
return nil, fmt.Errorf("user_name not provided")
|
||||
}
|
||||
|
||||
encodedUserName := common.EncodeEmail(userName)
|
||||
encodedUserName := common.EncodeToBase64(userName)
|
||||
apiURL := fmt.Sprintf("/admin/users/%s/default-models", encodedUserName)
|
||||
|
||||
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
|
||||
|
||||
@@ -1429,20 +1429,20 @@ func (c *CLI) CommonShowModel(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("model_name not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"model_name": modelName,
|
||||
}
|
||||
encodedModelName := common.EncodeToBase64(modelName)
|
||||
|
||||
var resp *Response
|
||||
var err error
|
||||
var httpClient *HTTPClient
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
baseURL := fmt.Sprintf("/admin/all-models/%s", encodedModelName)
|
||||
httpClient = c.AdminServerClient
|
||||
resp, err = httpClient.Request("GET", "/admin/all-models", "web", nil, payload)
|
||||
resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)
|
||||
case APIMode:
|
||||
baseURL := fmt.Sprintf("/all-models/%s", encodedModelName)
|
||||
httpClient = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
|
||||
resp, err = httpClient.Request("GET", "/all-models", "web", nil, payload)
|
||||
resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid server type")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user