Update create model instance command (#14441)

### What problem does this PR solve?

1. support command:

```
RAGFlow(user)> create provider 'vllm' instance 'test' key 'test-key' url 'base-url' region 'abc';
SUCCESS
RAGFlow(user)> list instances from 'vllm';
+----------+----------------------------------------+----------------------------------+--------------+----------------------------------+--------+
| apiKey   | extra                                  | id                               | instanceName | providerID                       | status |
+----------+----------------------------------------+----------------------------------+--------------+----------------------------------+--------+
| test-key | {"base_url":"base-url","region":"abc"} | 40213c89430311f1a7cf38a74640adcc | test         | b4d40e6142d311f1a4f938a74640adcc | enable |
+----------+----------------------------------------+----------------------------------+--------------+----------------------------------+--------+
```
2. support add vllm model
```
RAGFlow(user)> add model 'Qwen/Qwen2-0.5B' to provider 'vllm' instance 'test' with tokens 131072 chat;
SUCCESS
```
3. add vllm chat

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
- [x] Refactoring

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-04-29 17:05:08 +08:00
committed by GitHub
parent 486ca463aa
commit bb05a8bd7e
24 changed files with 754 additions and 22 deletions

View File

@@ -1129,11 +1129,23 @@ func (c *RAGFlowClient) CreateProviderInstance(cmd *Command) (ResponseIf, error)
return nil, fmt.Errorf("API key not provided")
}
baseUrl, ok := cmd.Params["base_url"].(string)
if !ok {
baseUrl = ""
}
region, ok := cmd.Params["region"].(string)
if !ok {
region = ""
}
url := fmt.Sprintf("/providers/%s/instances", providerName)
payload := map[string]interface{}{
"instance_name": instanceName,
"api_key": apiKey,
"base_url": baseUrl,
"region": region,
}
resp, err := c.HTTPClient.Request("POST", url, true, "web", nil, payload)
@@ -1685,6 +1697,75 @@ func (c *RAGFlowClient) ShowCurrentModel(cmd *Command) (ResponseIf, error) {
return &result, nil
}
func (c *RAGFlowClient) AddCustomModel(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 {
return nil, fmt.Errorf("provider name not provided")
}
instanceName, ok := cmd.Params["instance_name"].(string)
if !ok {
return nil, fmt.Errorf("instance name not provided")
}
modelName, ok := cmd.Params["model_name"].(string)
if !ok {
return nil, fmt.Errorf("model name not provided")
}
// chat, vision, embedding, rerank, tts, asr, ocr
modelType, ok := cmd.Params["model_type"].(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_type": modelType,
"max_tokens": maxTokens,
}
supportThink, ok := cmd.Params["support_think"].(bool)
if ok {
payload["thinking"] = supportThink
}
resp, err := c.HTTPClient.Request("POST", url, true, "web", nil, payload)
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))
}
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
}
// Context related commands
// CEList handles the ls command - lists nodes using Context Engine