Commit 17cbc17
feat: Add ExtraFields support to OpenAI providers for custom parameters (#1)
Adds support for arbitrary extra fields in OpenAI and OpenAI-compatible
providers to enable custom parameters required by OpenAI-compatible APIs
like Z.AI GLM.
The OpenAI Go SDK's ChatCompletionNewParams provides a SetExtraFields()
method, but Fantasy had no way to utilize it. This change adds an
ExtraFields field to ProviderOptions and calls SetExtraFields() when
extra fields are present.
Use case:
Custom OpenAI-compatible APIs (like Z.AI GLM) require additional parameters
such as thinking mode configuration that aren't part of OpenAI's API spec:
```json
{
"extra_fields": {
"thinking": {
"budget_tokens": 26214,
"type": "enabled"
}
}
}
```
Changes:
- Add \`ExtraFields map[string]any\` field to ProviderOptions in both
openai and openaicompat providers
- Call \`params.SetExtraFields()\` in PrepareCallFunc when ExtraFields present
- Minimal, non-breaking change using omitempty JSON tag
This enables Crush (charmbracelet/crush#1171) and other Fantasy consumers
to pass custom parameters to OpenAI-compatible APIs without modifying
Fantasy for each specific API's custom fields.
Tested: Build successful, no breaking changes to existing functionality.
Co-authored-by: OutBot CI <[email protected]>1 parent 38c3539 commit 17cbc17
File tree
4 files changed
+17
-0
lines changed- providers
- openaicompat
- openai
4 files changed
+17
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
0 commit comments