mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-01 00:05:43 +08:00
Go CLI: merge function (#16458)
### Summary 1. remove unused code. --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -444,7 +444,7 @@ func (c *CLI) ExecuteUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
case "api_list_default_models":
|
||||
return c.APIListDefaultModelsCommand(cmd)
|
||||
case "api_parse_documents":
|
||||
return c.APIParseDocumentsUserCommand(cmd)
|
||||
return c.APIParseDocumentsCommand(cmd)
|
||||
case "api_start_ingestion":
|
||||
return c.APIStartIngestionCommand(cmd)
|
||||
case "api_stop_ingestion":
|
||||
|
||||
@@ -318,20 +318,7 @@ func (c *CLI) CommonShowProviderCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to show provider: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show provider: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to show provider: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "show provider")
|
||||
}
|
||||
|
||||
// CommonShowProviderInstanceCommand shows details of a specific instance
|
||||
@@ -364,21 +351,7 @@ func (c *CLI) CommonShowProviderInstanceCommand(cmd *Command) (ResponseIf, error
|
||||
return nil, fmt.Errorf("failed to show instance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show instance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to show instance: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "show instance")
|
||||
}
|
||||
|
||||
// CommonShowProviderInstanceBalanceCommand shows balance of a specific instance
|
||||
@@ -412,21 +385,7 @@ func (c *CLI) CommonShowProviderInstanceBalanceCommand(cmd *Command) (ResponseIf
|
||||
return nil, fmt.Errorf("failed to show instance balance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show instance balance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to show instance balance: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "show instance balance")
|
||||
}
|
||||
|
||||
// CommonListProviderInstancesCommand lists all instances of a provider
|
||||
@@ -631,20 +590,7 @@ func (c *CLI) CommonShowProviderModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to show model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to show model: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "show model")
|
||||
}
|
||||
|
||||
func (c *CLI) CommonCheckProviderWithKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -695,31 +641,12 @@ func (c *CLI) CommonCheckProviderWithKeyCommand(cmd *Command) (ResponseIf, error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check provider connection with key: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to check provider connection: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "check provider connection with key")
|
||||
case APIMode:
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "check provider connection with key")
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid server type")
|
||||
}
|
||||
@@ -754,31 +681,12 @@ func (c *CLI) CommonCheckProviderConnectionCommand(cmd *Command) (ResponseIf, er
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check provider connection: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to check provider connection: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "check provider connection")
|
||||
case APIMode:
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "check provider connection")
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid server type")
|
||||
}
|
||||
@@ -827,31 +735,11 @@ func (c *CLI) CommonAlterProviderInstanceCommand(cmd *Command) (ResponseIf, erro
|
||||
return nil, fmt.Errorf("failed to alter instance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to alter instance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "alter instance")
|
||||
case APIMode:
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "alter instance")
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid server type")
|
||||
}
|
||||
@@ -895,31 +783,12 @@ func (c *CLI) CommonEnableOrDisableModelCommand(cmd *Command, status string) (Re
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to enable/disable model: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to enable/disable model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "enable/disable model")
|
||||
case APIMode:
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("check provider connection failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "enable/disable model")
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid server type")
|
||||
}
|
||||
@@ -965,20 +834,7 @@ func (c *CLI) APISetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to set default model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to set default model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to set default model: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "set default model")
|
||||
}
|
||||
|
||||
func (c *CLI) APIResetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -1007,20 +863,7 @@ func (c *CLI) APIResetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to reset default model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to reset default model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to reset default model: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "reset default model")
|
||||
}
|
||||
|
||||
func (c *CLI) APIListDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -1469,20 +1312,7 @@ func (c *CLI) CommonShowModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to show model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to show model: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "show model")
|
||||
}
|
||||
|
||||
// readPassword reads password from terminal without echoing
|
||||
|
||||
@@ -58,6 +58,24 @@ func (r *CommonResponse) PrintOut() {
|
||||
}
|
||||
}
|
||||
|
||||
func HandleCommonResponse(response *Response, command string) (ResponseIf, error) {
|
||||
if response.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to %s: HTTP %d, body: %s", command, response.StatusCode, string(response.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err := json.Unmarshal(response.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("%s failed: invalid JSON (%w)", command, err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = response.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
type ModelsResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string][]map[string]interface{} `json:"data"`
|
||||
@@ -144,6 +162,24 @@ func (r *CommonDataResponse) PrintOut() {
|
||||
}
|
||||
}
|
||||
|
||||
func HandleCommonDataResponse(response *Response, command string) (ResponseIf, error) {
|
||||
if response.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to %s: HTTP %d, body: %s", command, response.StatusCode, string(response.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err := json.Unmarshal(response.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("%s failed: invalid JSON (%w)", command, err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = response.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
type ListDocumentsResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
@@ -451,6 +487,10 @@ func (r *SimpleResponse) PrintOut() {
|
||||
}
|
||||
|
||||
func HandleSimpleResponse(response *Response, command string) (ResponseIf, error) {
|
||||
if response.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to %s: HTTP %d, body: %s", command, response.StatusCode, string(response.Body))
|
||||
}
|
||||
|
||||
var result SimpleResponse
|
||||
if err := json.Unmarshal(response.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("%s failed: invalid JSON (%w)", command, err)
|
||||
@@ -912,7 +952,7 @@ func printReferenceChunks(raw json.RawMessage) {
|
||||
|
||||
fmt.Println("Reference:")
|
||||
for i, chunk := range chunks {
|
||||
id := chunkID(chunk)
|
||||
id := getChunkID(chunk)
|
||||
content := chunkContent(chunk)
|
||||
docName := chunkDocName(chunk)
|
||||
fmt.Printf(" [ID:%d] id=%s content=%q", i, id, truncateStr(content, 120))
|
||||
@@ -930,7 +970,7 @@ func printReferenceChunks(raw json.RawMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
func chunkID(c map[string]interface{}) string {
|
||||
func getChunkID(c map[string]interface{}) string {
|
||||
for _, key := range []string{"chunk_id", "id"} {
|
||||
if v, ok := c[key]; ok {
|
||||
return fmt.Sprint(v)
|
||||
|
||||
@@ -247,10 +247,6 @@ func (c *CLI) APISetLogLevelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to change log level: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to change log level: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "change log level")
|
||||
}
|
||||
|
||||
@@ -353,21 +349,7 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list datasets: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list datasets: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list datasets failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list datasets")
|
||||
}
|
||||
|
||||
func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -1052,10 +1034,6 @@ func (c *CLI) APICreateDatasetCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to create dataset: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create dataset: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "create dataset")
|
||||
}
|
||||
|
||||
@@ -1237,20 +1215,7 @@ func (c *CLI) APIListAPIKeysCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list keys: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list keys: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list keys failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list keys")
|
||||
}
|
||||
|
||||
// APIDeleteAPIKeyCommand deletes an API key
|
||||
@@ -1269,10 +1234,6 @@ func (c *CLI) APIDeleteAPIKeyCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to delete key: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to delete key: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete key")
|
||||
}
|
||||
|
||||
@@ -1672,10 +1633,6 @@ func (c *CLI) APIAddProviderCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to add provider: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to add provider: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "add provider")
|
||||
}
|
||||
|
||||
@@ -1690,21 +1647,7 @@ func (c *CLI) APIListProvidersCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list providers: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list providers: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list providers failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list providers")
|
||||
}
|
||||
|
||||
// APIDeleteProviderCommand deletes a provider
|
||||
@@ -1731,10 +1674,6 @@ func (c *CLI) APIDeleteProviderCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to delete provider: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to delete provider: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete provider")
|
||||
}
|
||||
|
||||
@@ -1767,14 +1706,10 @@ func (c *CLI) APIDropDatasetCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("DELETE", "/datasets", "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create dataset: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop dataset: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create dataset: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "create provider instance")
|
||||
return HandleSimpleResponse(resp, "drop dataset")
|
||||
}
|
||||
|
||||
// APIDropAgentCommand DROP AGENT 'agent_name'
|
||||
@@ -1806,14 +1741,10 @@ func (c *CLI) APIDropAgentCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("DELETE", "/agents", "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create agent: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop agent: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create agent: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete agent")
|
||||
return HandleSimpleResponse(resp, "drop agent")
|
||||
}
|
||||
|
||||
// APIDropChatCommand DROP CHAT 'chat_name'
|
||||
@@ -1845,14 +1776,10 @@ func (c *CLI) APIDropChatCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("DELETE", "/chats", "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create chat: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop chat: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create chat: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete chat")
|
||||
return HandleSimpleResponse(resp, "drop chat")
|
||||
}
|
||||
|
||||
// APIDropSearchCommand DROP SEARCH 'search_name'
|
||||
@@ -1881,14 +1808,10 @@ func (c *CLI) APIDropSearchCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("DELETE", endPoint, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to delete search: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop search: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to delete search: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete search")
|
||||
return HandleSimpleResponse(resp, "drop search")
|
||||
}
|
||||
|
||||
// APIDropMemoryCommand DROP MEMORY 'memory_name'
|
||||
@@ -1917,14 +1840,10 @@ func (c *CLI) APIDropMemoryCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("DELETE", endPoint, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to delete memory: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop memory: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to delete memory: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "delete memory")
|
||||
return HandleSimpleResponse(resp, "drop memory")
|
||||
}
|
||||
|
||||
// APIAddProviderInstanceCommand creates a new provider instance
|
||||
@@ -1975,55 +1894,10 @@ func (c *CLI) APIAddProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := httpClient.Request("POST", url, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create provider instance: %w", err)
|
||||
return nil, fmt.Errorf("failed to add provider instance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to create provider instance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "create provider instance")
|
||||
}
|
||||
|
||||
// ShowInstanceBalance shows balance of a specific instance
|
||||
// SHOW BALANCE FROM PROVIDER <provider_name> <instance_name>
|
||||
func (c *CLI) ShowInstanceBalance(cmd *Command) (ResponseIf, error) {
|
||||
if c.Config.CLIMode != APIMode {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
}
|
||||
|
||||
instanceName, ok := cmd.Params["instance_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("instance name not provided")
|
||||
}
|
||||
|
||||
providerName, ok := cmd.Params["provider_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("provider name not provided")
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/providers/%s/instances/%s/balance", providerName, instanceName)
|
||||
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", url, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to show instance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to show instance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("show instance failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleSimpleResponse(resp, "add provider instance")
|
||||
}
|
||||
|
||||
// DELETE PROVIDER <name> INSTANCE <name>
|
||||
@@ -2050,14 +1924,10 @@ func (c *CLI) APIDeleteProviderInstanceCommand(cmd *Command) (ResponseIf, error)
|
||||
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", url, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to drop instance: %w", err)
|
||||
return nil, fmt.Errorf("failed to drop provider instance: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to drop instance: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "drop instance")
|
||||
return HandleSimpleResponse(resp, "drop provider instance")
|
||||
}
|
||||
|
||||
// DELETE PROVIDER <name> INSTANCE <instance_name> MODELS <name1 name2 name3>
|
||||
@@ -2089,14 +1959,10 @@ func (c *CLI) APIDeleteProviderInstanceModelCommand(cmd *Command) (ResponseIf, e
|
||||
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", url, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to drop model: %w", err)
|
||||
return nil, fmt.Errorf("failed to delete model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to drop model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "drop model")
|
||||
return HandleSimpleResponse(resp, "delete model")
|
||||
}
|
||||
|
||||
func isValidURL(str string) bool {
|
||||
@@ -2533,18 +2399,8 @@ func (c *CLI) APIRerankUserDocumentCommand(cmd *Command) (ResponseIf, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to rerank document: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to rerank document: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("rerank document failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
|
||||
return HandleCommonResponse(resp, "rerank document")
|
||||
}
|
||||
|
||||
func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -2940,19 +2796,7 @@ func (c *CLI) APIOCRUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to OCR document: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to OCR document: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("OCR document failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "OCR document")
|
||||
}
|
||||
|
||||
func (c *CLI) APIModelParseFileCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -3042,19 +2886,8 @@ func (c *CLI) APIModelParseFileCommand(cmd *Command) (ResponseIf, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to PARSE document: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to PARSE document: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("PARSE document failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "PARSE document")
|
||||
}
|
||||
|
||||
func (c *CLI) APIListModelInstanceTasksCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -3080,20 +2913,10 @@ func (c *CLI) APIListModelInstanceTasksCommand(cmd *Command) (ResponseIf, error)
|
||||
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", url, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list tasks: %w", err)
|
||||
return nil, fmt.Errorf("failed to list model parsing tasks: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list tasks: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list tasks failed: invalid JSON (%w)", err)
|
||||
}
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
|
||||
return HandleCommonResponse(resp, "list model parsing tasks")
|
||||
}
|
||||
|
||||
// APIShowProviderInstanceTaskCommand shows the details of a task
|
||||
@@ -3220,9 +3043,6 @@ func (c *CLI) APIAddCustomModelCommand(cmd *Command) (ResponseIf, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to add custom model: %w", err)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to add custom model: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "add custom model")
|
||||
}
|
||||
@@ -3647,7 +3467,8 @@ func (c *CLI) DevRemoveChunksCommand(cmd *Command) (ResponseIf, error) {
|
||||
case float64:
|
||||
deletedCount = int64(data)
|
||||
case map[string]interface{}:
|
||||
if count, ok := data["deleted_count"].(float64); ok {
|
||||
var count float64
|
||||
if count, ok = data["deleted_count"].(float64); ok {
|
||||
deletedCount = int64(count)
|
||||
}
|
||||
}
|
||||
@@ -3659,7 +3480,7 @@ func (c *CLI) DevRemoveChunksCommand(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *CLI) APIParseDocumentsUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
func (c *CLI) APIParseDocumentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
|
||||
return nil, fmt.Errorf("API key not set. Please login first")
|
||||
}
|
||||
@@ -3687,14 +3508,10 @@ func (c *CLI) APIParseDocumentsUserCommand(cmd *Command) (ResponseIf, error) {
|
||||
// Normal mode
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list documents: %w", err)
|
||||
return nil, fmt.Errorf("failed to parse documents: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list documents: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
return HandleSimpleResponse(resp, "list documents")
|
||||
return HandleSimpleResponse(resp, "parse documents")
|
||||
}
|
||||
|
||||
func (c *CLI) APIParseLocalFileCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -3802,21 +3619,7 @@ func (c *CLI) APIListIngestionTasks(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list ingestion tasks: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list ingestion tasks:: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list ingestion tasks: failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list ingestion tasks")
|
||||
}
|
||||
|
||||
// APIShowLogLevelCommand sets the log level for the system.
|
||||
@@ -3830,21 +3633,7 @@ func (c *CLI) APIShowLogLevelCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to get log level config: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to get log level config: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonDataResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("get log level config failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonDataResponse(resp, "get log level config")
|
||||
|
||||
}
|
||||
|
||||
@@ -3863,21 +3652,7 @@ func (c *CLI) APIListEnvironmentsCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list environments: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list environments: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list environments failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list environments")
|
||||
}
|
||||
|
||||
// APIListVariablesCommand lists all system variables (api mode only).
|
||||
@@ -3895,21 +3670,7 @@ func (c *CLI) APIListVariablesCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to list variables: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list variables: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("list environments failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "list variables")
|
||||
}
|
||||
|
||||
func (c *CLI) APIStartIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -3943,21 +3704,7 @@ func (c *CLI) APIStartIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to ingest file: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to ingest file: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("ingest file failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "ingest file")
|
||||
}
|
||||
|
||||
func (c *CLI) APIStopIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -3979,24 +3726,10 @@ func (c *CLI) APIStopIngestionCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PUT", "/datasets/ingestion/tasks", "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to ingest file: %w", err)
|
||||
return nil, fmt.Errorf("failed to stop ingestion: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to ingest file: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("ingest file failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "stop ingestion")
|
||||
}
|
||||
|
||||
func (c *CLI) APIRemoveTaskCommand(cmd *Command) (ResponseIf, error) {
|
||||
@@ -4026,17 +3759,7 @@ func (c *CLI) APIRemoveTaskCommand(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("failed to remove tasks: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("remove tasks failed: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
return HandleCommonResponse(resp, "remove tasks")
|
||||
}
|
||||
|
||||
func (c *CLI) DevChunkCommand(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
Reference in New Issue
Block a user