mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-31 21:13:49 +08:00
GOCli check provider region (#15474)
## Summary - add CLI command `CHECK PROVIDER 'provider_name' REGION 'region_name' KEY 'api_key';` - route the command through CLI parser and command dispatcher - call `GET /api/v1/providers/:provider_name/connection` with `region` and `api_key` ## Testing - `go test ./internal/cli/...` - manually verified CLI command parsing and request flow
This commit is contained in:
@@ -2551,6 +2551,64 @@ func (c *RAGFlowClient) CheckProviderConnection(cmd *Command) (ResponseIf, error
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) CheckProviderWithKey(cmd *Command) (ResponseIf, error) {
|
||||
if c.HTTPClient.APIToken == "" && c.HTTPClient.LoginToken == "" {
|
||||
return nil, fmt.Errorf("API token not set. Please login first")
|
||||
}
|
||||
if c.ServerType != "user" {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
}
|
||||
|
||||
providerName, ok := cmd.Params["provider_name"].(string)
|
||||
if !ok || providerName == "" {
|
||||
return nil, fmt.Errorf("provider name not provided")
|
||||
}
|
||||
region, ok := cmd.Params["region"].(string)
|
||||
if !ok || region == "" {
|
||||
return nil, fmt.Errorf("region not provided")
|
||||
}
|
||||
apiKey, ok := cmd.Params["api_key"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("api_key not provided")
|
||||
}
|
||||
baseURL, _ := cmd.Params["base_url"].(string)
|
||||
|
||||
var apiKeyValue interface{}
|
||||
if apiKey != "" {
|
||||
apiKeyValue = apiKey
|
||||
} else {
|
||||
apiKeyValue = nil
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/providers/%s/connection", providerName)
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"region": region,
|
||||
"api_key": apiKeyValue,
|
||||
}
|
||||
if baseURL != "" {
|
||||
payload["base_url"] = baseURL
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("GET", url, "api", nil, payload)
|
||||
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))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// UseModel sets the current model for chat
|
||||
func (c *RAGFlowClient) UseModel(cmd *Command) (ResponseIf, error) {
|
||||
if c.HTTPClient.APIToken == "" && c.HTTPClient.LoginToken == "" {
|
||||
|
||||
Reference in New Issue
Block a user