Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go: add thinking features to zhipu-ai (#14234)

Jin Haif269ee9739ae
diff --git a/conf/models/zhipu-ai.json b/conf/models/zhipu-ai.json
index f41166acae..910c675fae 100644
--- a/conf/models/zhipu-ai.json
+++ b/conf/models/zhipu-ai.json
@@ -209,5 +209,23 @@
],
"features": {}
}
- ]
+ ],
+ "features": {
+ "thinking": {
+ "default_value": true,
+ "supported_models": [
+ "glm-5.1",
+ "glm-5",
+ "glm-5v-turbo",
+ "glm-4.7",
+ "glm-4.6",
+ "glm-4.6v",
+ "glm-4.5",
+ "glm-4.5v"
+ ],
+ "clear": {
+ "default_value": true
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/internal/entity/model.go b/internal/entity/model.go
index 93125807a4..e60af28a58 100644
--- a/internal/entity/model.go
+++ b/internal/entity/model.go
@@ -59,6 +59,18 @@ type Reasoning struct {
RawType string `json:"type"`
}
+// Reasoning represents the reasoning capability (can be one of three types)
+type ClearReasoningContent struct {
+ DefaultValue bool `json:"default_value"`
+}
+
+// Reasoning represents the reasoning capability (can be one of three types)
+type Thinking struct {
+ DefaultValue bool `json:"default_value"`
+ SupportedModels []string `json:"supported_models"`
+ Clear ClearReasoningContent `json:"clear"`
+}
+
// UnmarshalJSON custom unmarshal for Reasoning
func (r *Reasoning) UnmarshalJSON(data []byte) error {
var temp map[string]interface{}
@@ -132,14 +144,20 @@ type Multimodal struct {
type Features struct {
Multimodal *Multimodal `json:"multimodal,omitempty"`
Reasoning *Reasoning `json:"reasoning,omitempty"`
+ Thinking *Thinking `json:"thinking,omitempty"`
+}
+
+type ModelThinking struct {
+ DefaultValue bool `json:"default_value"`
+ ClearContent bool `json:"clear_content"`
}
// Model represents a single LLM model
type Model struct {
- Name string `json:"name"`
- MaxTokens int `json:"max_tokens"`
- ModelTypes []string `json:"model_types"`
- Features Features `json:"features"`
+ Name string `json:"name"`
+ MaxTokens int `json:"max_tokens"`
+ ModelTypes []string `json:"model_types"`
+ Thinking *ModelThinking `json:"thinking"`
ModelTypeMap map[string]bool
}
@@ -149,6 +167,7 @@ type Provider struct {
URL map[string]string `json:"url"`
URLSuffix models.URLSuffix `json:"url_suffix"`
Models []*Model `json:"models"`
+ Features Features `json:"features"`
ModelDriver models.ModelDriver
}
@@ -204,7 +223,24 @@ func NewProviderManager(dirPath string) (*ProviderManager, error) {
return nil, fmt.Errorf("error parsing JSON from file %s: %w", filePath, err)
}
+ // Get support thinking models
+ modelSupportThinking := make(map[string]bool)
+ if provider.Features.Thinking != nil {
+ for _, modelName := range provider.Features.Thinking.SupportedModels {
+ modelSupportThinking[modelName] = true
+ }
+ }
+
for _, model := range provider.Models {
+ // if the prefix of mode.Name is matched with keys of modelSupportThinking
+ for modelPrefix, _ := range modelSupportThinking {
+ if strings.HasPrefix(model.Name, modelPrefix) {
+ model.Thinking = &ModelThinking{
+ DefaultValue: provider.Features.Thinking.DefaultValue,
+ ClearContent: provider.Features.Thinking.Clear.DefaultValue,
+ }
+ }
+ }
model.ModelTypeMap = make(map[string]bool)
for _, modelType := range model.ModelTypes {
model.ModelTypeMap[modelType] = true
@@ -294,7 +330,7 @@ func (pm *ProviderManager) ListModels(providerName string) ([]map[string]interfa
"name": model.Name,
"max_tokens": model.MaxTokens,
"model_types": model.ModelTypes,
- "features": getFeaturesMap(model.Features),
+ "features": GetFeatures(model),
}
models = append(models, modelData)
}
@@ -402,7 +438,7 @@ func (pm *ProviderManager) SearchModelInfo(providerName, modelName string, filte
"name": model.Name,
"max_tokens": model.MaxTokens,
"model_types": model.ModelTypes,
- "features": getFeaturesMap(model.Features),
+ //"features": getFeaturesMap(model.Features),
}
if filterBy != "" && filterValue != nil {
@@ -426,20 +462,20 @@ func (pm *ProviderManager) SearchByFeature(featureType string) ModelResponse {
Message: "success",
}
- for _, provider := range pm.Providers {
- for _, model := range provider.Models {
- if modelHasFeature(model.Features, featureType) {
- modelData := map[string]interface{}{
- "provider": provider.Name,
- "name": model.Name,
- "max_tokens": model.MaxTokens,
- "model_types": model.ModelTypes,
- "features": getFeaturesMap(model.Features),
- }
- resp.Data = append(resp.Data, modelData)
- }
- }
- }
+ //for _, provider := range pm.Providers {
+ // for _, model := range provider.Models {
+ // if modelHasFeature(model.Features, featureType) {
+ // modelData := map[string]interface{}{
+ // "provider": provider.Name,
+ // "name": model.Name,
+ // "max_tokens": model.MaxTokens,
+ // "model_types": model.ModelTypes,
+ // "features": getFeaturesMap(model.Features),
+ // }
+ // resp.Data = append(resp.Data, modelData)
+ // }
+ // }
+ //}
if len(resp.Data) == 0 {
resp.Code = 404
@@ -465,7 +501,7 @@ func (pm *ProviderManager) SearchByType(modelType string) ModelResponse {
"name": model.Name,
"max_tokens": model.MaxTokens,
"model_types": model.ModelTypes,
- "features": getFeaturesMap(model.Features),
+ //"features": getFeaturesMap(model.Features),
}
resp.Data = append(resp.Data, modelData)
}
@@ -480,6 +516,26 @@ func (pm *ProviderManager) SearchByType(modelType string) ModelResponse {
return resp
}
+func GetFeatures(model *Model) []string {
+ var features []string
+ if model.Thinking != nil {
+ features = append(features, "thinking")
+ }
+ return features
+}
+
+func ConvertToFeaturesMap(model *Model) map[string]interface{} {
+ featuresMap := make(map[string]interface{})
+ if model.Thinking != nil {
+ thinkingMap := map[string]interface{}{
+ "default_value": model.Thinking.DefaultValue,
+ "clear_reasoning": model.Thinking.ClearContent,
+ }
+ featuresMap["thinking"] = thinkingMap
+ }
+ return featuresMap
+}
+
// Helper: Get features map for response
func getFeaturesMap(features Features) map[string]interface{} {
featuresMap := make(map[string]interface{})