mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 11:48:10 +08:00
Go: fix gitee balance api (#15554)
``` RAGFlow(user)> create provider 'gitee' instance 'intl' key 'api-token' url 'https://ai.gitee.com/v1' region 'intl'; SUCCESS ``` --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -80,7 +80,14 @@ func (r *CommonDataResponse) SetOutputFormat(format OutputFormat) {
|
||||
func (r *CommonDataResponse) PrintOut() {
|
||||
if r.Code == 0 {
|
||||
table := make([]map[string]interface{}, 0)
|
||||
table = append(table, r.Data)
|
||||
for key, value := range r.Data {
|
||||
elem := map[string]interface{}{
|
||||
"field": key,
|
||||
"value": value,
|
||||
}
|
||||
table = append(table, elem)
|
||||
}
|
||||
//table = append(table, r.Data)
|
||||
PrintTableSimpleByFormat(table, r.OutputFormat)
|
||||
} else {
|
||||
fmt.Println("ERROR")
|
||||
@@ -156,9 +163,9 @@ func (r *ChunkResponse) PrintOut() {
|
||||
}
|
||||
|
||||
type MetadataResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Code int `json:"code"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Duration float64
|
||||
OutputFormat OutputFormat
|
||||
}
|
||||
@@ -213,8 +220,8 @@ func printFlattenedMetadata(data map[string]interface{}, format OutputFormat) {
|
||||
docIDStr = fmt.Sprintf("%v", docIDs)
|
||||
}
|
||||
tableData = append(tableData, map[string]interface{}{
|
||||
"field": field,
|
||||
"value": value,
|
||||
"field": field,
|
||||
"value": value,
|
||||
"document_ids": docIDStr,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1166,7 +1166,7 @@ func (c *RAGFlowClient) DeleteProvider(cmd *Command) (ResponseIf, error) {
|
||||
}
|
||||
|
||||
// CreateProviderInstance creates a new provider instance
|
||||
// CREATE PROVIDER <name> INSTANCE <instance_name> <api_key>
|
||||
// CREATE PROVIDER <name> INSTANCE <instance_name> KEY <api_key> URL <base_url> REGION <region>
|
||||
func (c *RAGFlowClient) CreateProviderInstance(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "user" {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
|
||||
@@ -1435,7 +1435,7 @@ func (p *Parser) parseAlterProvider() (*Command, error) {
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// parseCreateProviderInstance parses CREATE PROVIDER <name> INSTANCE <instance_name> KEY <api_key> URL <base_url> command
|
||||
// parseCreateProviderInstance parses CREATE PROVIDER <name> INSTANCE <instance_name> KEY <api_key> URL <base_url> REGION <region> command
|
||||
// instance_name cannot be "default"
|
||||
func (p *Parser) parseCreateProviderInstance() (*Command, error) {
|
||||
p.nextToken() // consume PROVIDER
|
||||
@@ -1444,8 +1444,8 @@ func (p *Parser) parseCreateProviderInstance() (*Command, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected provider name: %w", err)
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
|
||||
if p.curToken.Type != TokenInstance {
|
||||
return nil, fmt.Errorf("expected INSTANCE after provider name")
|
||||
}
|
||||
@@ -1455,7 +1455,6 @@ func (p *Parser) parseCreateProviderInstance() (*Command, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected instance name: %w", err)
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
|
||||
if p.curToken.Type != TokenKey {
|
||||
@@ -1470,23 +1469,27 @@ func (p *Parser) parseCreateProviderInstance() (*Command, error) {
|
||||
p.nextToken()
|
||||
|
||||
baseURL := ""
|
||||
if p.curToken.Type == TokenURL {
|
||||
p.nextToken()
|
||||
baseURL, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected base URL: %w", err)
|
||||
}
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
region := ""
|
||||
if p.curToken.Type == TokenRegion {
|
||||
p.nextToken()
|
||||
region, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected base URL: %w", err)
|
||||
optionsLoop:
|
||||
for {
|
||||
switch p.curToken.Type {
|
||||
case TokenRegion:
|
||||
p.nextToken()
|
||||
region, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected region: %w", err)
|
||||
}
|
||||
p.nextToken()
|
||||
case TokenURL:
|
||||
p.nextToken()
|
||||
baseURL, err = p.parseQuotedString()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected base URL: %w", err)
|
||||
}
|
||||
p.nextToken()
|
||||
default:
|
||||
break optionsLoop
|
||||
}
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
cmd := NewCommand("create_provider_instance")
|
||||
@@ -1496,9 +1499,6 @@ func (p *Parser) parseCreateProviderInstance() (*Command, error) {
|
||||
if baseURL != "" {
|
||||
// Only local model provider need to set URL
|
||||
cmd.Params["base_url"] = baseURL
|
||||
if region == "" {
|
||||
region = instanceName
|
||||
}
|
||||
}
|
||||
|
||||
if region != "" {
|
||||
|
||||
Reference in New Issue
Block a user