mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-07 12:00:44 +08:00
Add extra field to model instance (#14203)
### What problem does this PR solve? Now each model support region with different URL ### 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:
@@ -375,27 +375,29 @@ func (c *RAGFlowClient) ShowModel(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
func (c *RAGFlowClient) SetDefaultModel(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
modeType, ok := cmd.Params["model_type"].(string)
|
||||
modelType, 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)
|
||||
|
||||
compositeModelName, ok := cmd.Params["composite_model_name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_name not provided")
|
||||
}
|
||||
|
||||
var providerName, instanceName, modelName string
|
||||
names := strings.Split(compositeModelName, "/")
|
||||
if len(names) != 3 {
|
||||
return nil, fmt.Errorf("model name must be in format 'provider/instance/model'")
|
||||
}
|
||||
providerName = names[0]
|
||||
instanceName = names[1]
|
||||
modelName = names[2]
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"model_type": modeType,
|
||||
"model_provider": modelProvider,
|
||||
"model_instance": modelInstance,
|
||||
"model_type": modelType,
|
||||
"model_provider": providerName,
|
||||
"model_instance": instanceName,
|
||||
"model_name": modelName,
|
||||
}
|
||||
|
||||
@@ -420,6 +422,38 @@ func (c *RAGFlowClient) SetDefaultModel(cmd *Command) (ResponseIf, error) {
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *RAGFlowClient) ResetDefaultModel(cmd *Command) (ResponseIf, error) {
|
||||
|
||||
modelType, ok := cmd.Params["model_type"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("model_type not provided")
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"model_type": modelType,
|
||||
}
|
||||
|
||||
resp, err := c.HTTPClient.Request("PATCH", "/models", true, "web", nil, payload)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to reset default model: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("failed to reset 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 reset 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 {
|
||||
|
||||
Reference in New Issue
Block a user