Skip to content

Commit 9841151

Browse files
committed
chore: fix new google options
1 parent 6070a37 commit 9841151

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

providers/google/provider_options.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99

1010
// Global type identifiers for Google-specific provider data.
1111
const (
12-
TypeProviderOptions = Name + ".options"
12+
TypeProviderOptions = Name + ".options"
13+
TypeReasoningMetadata = Name + ".reasoning_metadata"
1314
)
1415

1516
// ThinkingConfig represents thinking configuration for the Google provider.
@@ -26,6 +27,34 @@ type ReasoningMetadata struct {
2627
// Options implements the ProviderOptionsData interface for ReasoningMetadata.
2728
func (m *ReasoningMetadata) Options() {}
2829

30+
// MarshalJSON implements custom JSON marshaling with type info for ReasoningMetadata.
31+
func (m ReasoningMetadata) MarshalJSON() ([]byte, error) {
32+
type plain ReasoningMetadata
33+
raw, err := json.Marshal(plain(m))
34+
if err != nil {
35+
return nil, err
36+
}
37+
return json.Marshal(struct {
38+
Type string `json:"type"`
39+
Data json.RawMessage `json:"data"`
40+
}{
41+
Type: TypeReasoningMetadata,
42+
Data: raw,
43+
})
44+
}
45+
46+
// UnmarshalJSON implements custom JSON unmarshaling with type info for ReasoningMetadata.
47+
func (m *ReasoningMetadata) UnmarshalJSON(data []byte) error {
48+
type plain ReasoningMetadata
49+
var rm plain
50+
err := json.Unmarshal(data, &rm)
51+
if err != nil {
52+
return err
53+
}
54+
*m = ReasoningMetadata(rm)
55+
return nil
56+
}
57+
2958
// SafetySetting represents safety settings for the Google provider.
3059
type SafetySetting struct {
3160
// 'HARM_CATEGORY_UNSPECIFIED',
@@ -114,4 +143,11 @@ func init() {
114143
}
115144
return &v, nil
116145
})
146+
fantasy.RegisterProviderType(TypeReasoningMetadata, func(data []byte) (fantasy.ProviderOptionsData, error) {
147+
var v ReasoningMetadata
148+
if err := json.Unmarshal(data, &v); err != nil {
149+
return nil, err
150+
}
151+
return &v, nil
152+
})
117153
}

0 commit comments

Comments
 (0)