mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-14 20:54:30 +08:00
Go: set and list default models (#14191)
### What problem does this PR solve? ``` RAGFlow(user)> set default vlm "zhipu-ai" "ccc" "glm-4.6v-flash"; SUCCESS RAGFlow(user)> list default models; +--------+----------------+----------------+----------------+------------+ | enable | model_instance | model_name | model_provider | model_type | +--------+----------------+----------------+----------------+------------+ | true | ccc | glm-4.6v-flash | zhipu-ai | llm | | true | ccc | glm-4.6v-flash | zhipu-ai | image2text | +--------+----------------+----------------+----------------+------------+ ``` ### 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:
@@ -373,6 +373,75 @@ func (c *RAGFlowClient) ShowModel(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) SetDefaultModel(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
modeType, ok := cmd.Params["model_type"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_type not provided")
|
||||
}
|
||||
modelProvider, ok := cmd.Params["model_provider"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_provider not provided")
|
||||
}
|
||||
modelInstance, ok := cmd.Params["model_instance"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_instance not provided")
|
||||
}
|
||||
modelName, ok := cmd.Params["model_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_name not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"model_type": modeType,
|
||||
"model_provider": modelProvider,
|
||||
"model_instance": modelInstance,
|
||||
"model_name": modelName,
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("PATCH", "/models", true, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to set default model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to set default model: 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("failed to set default model: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) ListDefaultModels(cmd *Command) (ResponseIf, error) {
|
||||
resp, err := c.HTTPClient.Request("GET", "/models", true, "web", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list default models: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to list default models: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
|
||||
}
|
||||
|
||||
var result CommonResponse
|
||||
if err = json.Unmarshal(resp.Body, &result); err != nil {
|
||||
return nil, fmt.Errorf("failed to list default models: invalid JSON (%w)", err)
|
||||
}
|
||||
|
||||
if result.Code != 0 {
|
||||
return nil, fmt.Errorf("%s", result.Message)
|
||||
}
|
||||
result.Duration = resp.Duration
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// readPassword reads password from terminal without echoing
|
||||
func ReadPassword() (string, error) {
|
||||
if !term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
|
||||
Reference in New Issue
Block a user