Skip to content

Commit 12c94ea

Browse files
committed
feat: Add ExtraBody/ExtraFields support for custom OpenAI-compatible API parameters
- Modified getProviderOptions() to accept extraBody parameter - Map provider config extra_body to Fantasy's extra_fields - Updated all call sites in coordinator.go and agent_tool.go - Enables Z.AI GLM thinking mode and other custom parameters This works with the Fantasy fork that has ExtraFields support.
1 parent 3b2985f commit 12c94ea

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/agent/coordinator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func getProviderOptions(model Model, providerCfg config.ProviderConfig) fantasy.
142142
cfgOpts := []byte("{}")
143143
providerCfgOpts := []byte("{}")
144144
catwalkOpts := []byte("{}")
145+
extraBodyOpts := []byte("{}")
145146

146147
if model.ModelCfg.ProviderOptions != nil {
147148
data, err := json.Marshal(model.ModelCfg.ProviderOptions)
@@ -164,9 +165,24 @@ func getProviderOptions(model Model, providerCfg config.ProviderConfig) fantasy.
164165
}
165166
}
166167

168+
// Merge extra_body from provider config (for Z.AI GLM thinking mode, etc.)
169+
// Map it to extra_fields which Fantasy's ExtraFields expects
170+
if providerCfg.ExtraBody != nil && len(providerCfg.ExtraBody) > 0 {
171+
extraBodyData := map[string]any{
172+
"extra_fields": providerCfg.ExtraBody,
173+
}
174+
data, err := json.Marshal(extraBodyData)
175+
if err == nil {
176+
extraBodyOpts = data
177+
} else {
178+
slog.Warn("Failed to marshal extra_body from provider config", "error", err)
179+
}
180+
}
181+
167182
readers := []io.Reader{
168183
bytes.NewReader(catwalkOpts),
169184
bytes.NewReader(providerCfgOpts),
185+
bytes.NewReader(extraBodyOpts),
170186
bytes.NewReader(cfgOpts),
171187
}
172188

0 commit comments

Comments
 (0)