mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-14 04:36:52 +08:00
fix: unable to pass Temperature and MaxTokens in agent (#18223)
### Summary As title
This commit is contained in:
@@ -82,7 +82,9 @@ type AgentParam struct {
|
||||
SystemPrompt string
|
||||
UserPrompt string
|
||||
Thinking string
|
||||
MaxTokens *int
|
||||
TopP *float64
|
||||
Temperature *float64
|
||||
Tools []string // Agent-visible tool names resolved into Eino BaseTool instances
|
||||
ToolParams map[string]map[string]any // node-level tool constructor params keyed by tool name
|
||||
SubAgents []SubAgentTool
|
||||
@@ -1041,15 +1043,14 @@ func buildAgentChatModel(ctx context.Context, p AgentParam) (*models.EinoChatMod
|
||||
apiKey := p.APIKey
|
||||
cfg := &models.APIConfig{ApiKey: &apiKey}
|
||||
cm := models.NewChatModel(d, &modelID, cfg)
|
||||
// ChatConfig construction is conditional on TopP being set, unlike
|
||||
// the LLM path which always builds a ChatConfig (Temperature/MaxTokens
|
||||
// pass-through). The asymmetry is intentional: AgentParam has no
|
||||
// Temperature/MaxTokens yet, so building a zero-config ChatConfig
|
||||
// would be dead weight. When AgentParam grows Temperature/
|
||||
// MaxTokens, switch to always-build.
|
||||
// Build ChatConfig when a generation parameter or Thinking is set.
|
||||
var chatCfg *models.ChatConfig
|
||||
if p.TopP != nil || p.Thinking != "" {
|
||||
chatCfg = &models.ChatConfig{TopP: p.TopP}
|
||||
if p.TopP != nil || p.Thinking != "" || p.MaxTokens != nil || p.Temperature != nil {
|
||||
chatCfg = &models.ChatConfig{
|
||||
TopP: p.TopP,
|
||||
MaxTokens: p.MaxTokens,
|
||||
Temperature: p.Temperature,
|
||||
}
|
||||
switch p.Thinking {
|
||||
case "enabled":
|
||||
t := true
|
||||
@@ -1370,6 +1371,14 @@ func mergeAgentParam(base AgentParam, inputs map[string]any) AgentParam {
|
||||
f := v
|
||||
p.TopP = &f
|
||||
}
|
||||
if v, ok := intFrom(inputs, "max_tokens"); ok {
|
||||
f := v
|
||||
p.MaxTokens = &f
|
||||
}
|
||||
if v, ok := floatFrom(inputs, "temperature"); ok {
|
||||
f := v
|
||||
p.Temperature = &f
|
||||
}
|
||||
if v, ok := stringFrom(inputs, "thinking"); ok && v != "" && v != "default" {
|
||||
p.Thinking = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user