mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-19 22:21:04 +08:00
Go: add balance command (#14262)
### What problem does this PR solve? ``` RAGFlow(user)> list supported models from 'moonshot' 'test'; +---------------------------------+ | model_name | +---------------------------------+ | moonshot-v1-32k-vision-preview | | kimi-k2.6 | | moonshot-v1-8k | | moonshot-v1-auto | | moonshot-v1-128k | | moonshot-v1-32k | | kimi-k2.5 | | moonshot-v1-8k-vision-preview | | moonshot-v1-128k-vision-preview | +---------------------------------+ RAGFlow(user)> show balance from 'moonshot' 'test'; +---------+----------+ | balance | currency | +---------+----------+ | 0 | CNY | +---------+----------+ ``` ### 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:
@@ -1234,6 +1234,47 @@ func (c *RAGFlowClient) ShowProviderInstance(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ShowInstanceBalance shows balance of a specific instance
|
||||
// SHOW BALANCE FROM PROVIDER <provider_name> <instance_name>
|
||||
func (c *RAGFlowClient) ShowInstanceBalance(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "user" {
|
||||
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.HTTPClient.Request("GET", url, true, "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
|
||||
}
|
||||
|
||||
// AlterProviderInstance renames a provider instance
|
||||
// ALTER INSTANCE <name> NAME <new_name> FROM PROVIDER <name>
|
||||
func (c *RAGFlowClient) AlterProviderInstance(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
Reference in New Issue
Block a user