mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-13 16:38:26 +08:00
feat(go-cli): support batch model add/remove and optional embedding dimension (#15631)
## Summary This PR improves the Go CLI in two areas: 1. It adds batch model management support, allowing multiple models to be added or removed in a single command. 2. It makes the `dimension` argument optional for the `embed text` command. These changes keep the existing single-model and explicit-dimension behaviors compatible while making the CLI more convenient for common workflows. ## What Changed ### 1. Batch model add/remove support The CLI now supports operating on multiple model names provided in a single quoted string. Supported commands include: ``` add model 'x1 x2 x3' to provider 'vllm' instance 'test' with tokens 1024 chat think vision, token 2048 chat, token 1024 think vision; drop model 'x1 x2 x3' from 'vllm' 'test'; remove model 'x1 x2 x3' from 'vllm' 'test'; ``` For add model, each config segment after with is matched to the corresponding model name by position. Example mapping: - x1 -> tokens 1024, chat + vision, thinking=true - x2 -> tokens 2048, chat - x3 -> tokens 1024, vision, thinking=true The existing single-model syntax remains supported. ### 2. Optional embedding dimension Previously, the Go CLI required dimension to be explicitly provided for embed text. Before: embed text 'what is rag' 'who are you' with 'model@test@provider' dimension 8192; Now both forms are supported: embed text 'what is rag' 'who are you' with 'model@test@provider' dimension 8192; embed text 'what is rag' 'who are you' with 'model@test@provider'; When omitted, the CLI leaves dimension unset and relies on provider/backend behavior. ## Tests Added parser tests covering: - Multiple models with multiple config segments - Model type deduplication - Model/config count mismatch - Drop/remove multiple models - Optional embedding dimension parsing
This commit is contained in:
@@ -1442,7 +1442,8 @@ func (c *RAGFlowClient) DropProviderInstance(cmd *Command) (ResponseIf, error) {
|
||||
}
|
||||
|
||||
// DropInstanceModel deletes a provider instance, only works for local deployed model
|
||||
// DROP MODEL <name> FROM <provider_name> <instance_name>
|
||||
// DROP MODEL <name1 name2 name3> FROM <provider_name> <instance_name>
|
||||
// Remove MODEL <name1 name2 name3> FROM <provider_name> <instance_name>
|
||||
func (c *RAGFlowClient) DropInstanceModel(cmd *Command) (ResponseIf, error) {
|
||||
if c.ServerType != "user" {
|
||||
return nil, fmt.Errorf("this command is only allowed in USER mode")
|
||||
@@ -1458,13 +1459,13 @@ func (c *RAGFlowClient) DropInstanceModel(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("provider name not provided")
|
||||
}
|
||||
|
||||
modelName, ok := cmd.Params["model_name"].(string)
|
||||
modelNames, ok := cmd.Params["model_names"].([]string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model name not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"models": []string{modelName},
|
||||
"models": modelNames,
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName)
|
||||
@@ -2681,35 +2682,17 @@ func (c *RAGFlowClient) AddCustomModel(cmd *Command) (ResponseIf, error) {
|
||||
return nil, fmt.Errorf("instance name not provided")
|
||||
}
|
||||
|
||||
modelName, ok := cmd.Params["model_name"].(string)
|
||||
models, ok := cmd.Params["models"].([]map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model name not provided")
|
||||
}
|
||||
|
||||
// chat, vision, embedding, rerank, tts, asr, ocr
|
||||
modelTypes, ok := cmd.Params["model_types"].([]string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model type not provided")
|
||||
}
|
||||
|
||||
maxTokens, ok := cmd.Params["max_tokens"].(int)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("max tokens not provided")
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName)
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"provider_name": providerName,
|
||||
"instance_name": instanceName,
|
||||
"model_name": modelName,
|
||||
"model_types": modelTypes,
|
||||
"max_tokens": maxTokens,
|
||||
}
|
||||
|
||||
supportThink, ok := cmd.Params["support_think"].(bool)
|
||||
if ok {
|
||||
payload["thinking"] = supportThink
|
||||
"models": models,
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("POST", url, "web", nil, payload)
|
||||
|
||||
Reference in New Issue
Block a user