Skip to content

Commit 41d471e

Browse files
author
OutBot CI
committed
Merge main branch with ExtraFields support into ZAI provider branch
This combines: - PR #41: ZAI provider (and XAI, Groq, Cerebras, Huggingface providers) - ExtraFields support for OpenAI and OpenAI-compatible providers The ZAI provider uses openaicompat under the hood, so it will automatically benefit from ExtraFields for Z.AI GLM thinking mode.
2 parents 70e9b09 + 17cbc17 commit 41d471e

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

LICENSE

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,3 @@
175175
of your accepting any such warranty or additional liability.
176176

177177
END OF TERMS AND CONDITIONS
178-
179-
APPENDIX: How to apply the Apache License to your work.
180-
181-
To apply the Apache License to your work, attach the following
182-
boilerplate notice, with the fields enclosed by brackets "[]"
183-
replaced with your own identifying information. (Don't include
184-
the brackets!) The text should be enclosed in the appropriate
185-
comment syntax for the file format. We also recommend that a
186-
file or class name and description of purpose be included on the
187-
same "printed page" as the copyright notice for easier
188-
identification within third-party archives.
189-
190-
Copyright 2025 Charmbracelet, Inc.
191-
192-
Licensed under the Apache License, Version 2.0 (the "License");
193-
you may not use this file except in compliance with the License.
194-
You may obtain a copy of the License at
195-
196-
http://www.apache.org/licenses/LICENSE-2.0
197-
198-
Unless required by applicable law or agreed to in writing, software
199-
distributed under the License is distributed on an "AS IS" BASIS,
200-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201-
See the License for the specific language governing permissions and
202-
limitations under the License.

NOTICE

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
Fantasy
21
Copyright 2025 Charmbracelet, Inc.
32

4-
Part of the Charm open source ecosystem.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
56

6-
This product includes software developed by Charmbracelet, Inc.
7-
(http://charm.land)
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

providers/openai/language_model_hooks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ func DefaultPrepareCallFunc(model fantasy.LanguageModel, params *openai.ChatComp
9999
}
100100
params.Metadata = metadata
101101
}
102+
103+
// Apply extra fields for custom OpenAI-compatible APIs (e.g., Z.AI GLM thinking mode)
104+
if providerOptions.ExtraFields != nil && len(providerOptions.ExtraFields) > 0 {
105+
params.SetExtraFields(providerOptions.ExtraFields)
106+
}
102107
if providerOptions.PromptCacheKey != nil {
103108
params.PromptCacheKey = param.NewOpt(*providerOptions.PromptCacheKey)
104109
}

providers/openai/provider_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type ProviderOptions struct {
4747
SafetyIdentifier *string `json:"safety_identifier"`
4848
ServiceTier *string `json:"service_tier"`
4949
StructuredOutputs *bool `json:"structured_outputs"`
50+
// ExtraFields allows passing arbitrary additional parameters to OpenAI-compatible APIs
51+
// that require custom fields not part of the standard OpenAI API specification.
52+
ExtraFields map[string]any `json:"extra_fields,omitempty"`
5053
}
5154

5255
// Options implements the ProviderOptions interface.

providers/openaicompat/language_model_hooks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func PrepareCallFunc(_ fantasy.LanguageModel, params *openaisdk.ChatCompletionNe
4141
if providerOptions.User != nil {
4242
params.User = param.NewOpt(*providerOptions.User)
4343
}
44+
45+
// Apply extra fields for custom OpenAI-compatible APIs (e.g., Z.AI GLM thinking mode)
46+
if providerOptions.ExtraFields != nil && len(providerOptions.ExtraFields) > 0 {
47+
params.SetExtraFields(providerOptions.ExtraFields)
48+
}
49+
4450
return nil, nil
4551
}
4652

providers/openaicompat/provider_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
type ProviderOptions struct {
1111
User *string `json:"user"`
1212
ReasoningEffort *openai.ReasoningEffort `json:"reasoning_effort"`
13+
// ExtraFields allows passing arbitrary additional parameters to custom OpenAI-compatible APIs
14+
// that require custom fields not part of the standard OpenAI API specification.
15+
ExtraFields map[string]any `json:"extra_fields,omitempty"`
1316
}
1417

1518
// ReasoningData represents reasoning data for OpenAI-compatible provider.

0 commit comments

Comments
 (0)