Repository navigation
Expand file tree
/
Copy pathoptions.go
More file actions
721 lines (642 loc) · 24.2 KB
/
Copy pathoptions.go
File metadata and controls
721 lines (642 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
// Copyright (c) 2026 Matthew Winter
//
// This source code is licensed under the MIT license found in the LICENSE file
// in the root directory of this source tree.
package sigma
import (
"net/http"
"strings"
"time"
"github.com/wintermi/sigma/internal/headerutil"
)
const (
// ErrorInvalidOptions indicates request options failed local validation.
ErrorInvalidOptions ErrorCode = "invalid-options"
)
// ToolChoice identifies provider-neutral tool selection behavior.
type ToolChoice string
const (
// ToolChoiceAuto lets the provider choose whether to call a tool.
ToolChoiceAuto ToolChoice = "auto"
// ToolChoiceNone prevents the provider from calling tools.
ToolChoiceNone ToolChoice = "none"
)
// OpenAIOptions carries OpenAI-specific request options known to the root
// package without importing provider adapters.
type OpenAIOptions struct {
ReasoningEffort ThinkingLevel
ReasoningSummary string
ServiceTier string
ToolChoice any
ResponseFormat any
TopLogprobs int
SamplingParameters map[string]any
PromptCacheRetention string
ParallelToolCalls *bool
EnableGrammarTools *bool
TextVerbosity string
CodexWebSocketConnectTimeout *time.Duration
}
// AnthropicOptions carries Anthropic-specific request options known to the root
// package without importing provider adapters.
type AnthropicOptions struct {
ThinkingBudgetTokens *int
ToolChoice *AnthropicToolChoice
ThinkingDisplay AnthropicThinkingDisplay
InterleavedThinking *bool
OutputFormat any
DisableParallelToolUse *bool
EnableRefusalFallbacks bool
}
// AnthropicToolChoiceType identifies Anthropic Messages tool selection behavior.
type AnthropicToolChoiceType string
const (
// AnthropicToolChoiceAuto lets Anthropic choose whether to call a tool.
AnthropicToolChoiceAuto AnthropicToolChoiceType = "auto"
// AnthropicToolChoiceAny requires Anthropic to call one of the supplied tools.
AnthropicToolChoiceAny AnthropicToolChoiceType = "any"
// AnthropicToolChoiceNone prevents Anthropic from calling tools.
AnthropicToolChoiceNone AnthropicToolChoiceType = "none"
// AnthropicToolChoiceTool requires Anthropic to call the named tool.
AnthropicToolChoiceTool AnthropicToolChoiceType = "tool"
)
// AnthropicToolChoice carries Anthropic Messages tool choice controls.
type AnthropicToolChoice struct {
Type AnthropicToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
// AnthropicThinkingDisplay controls how Claude thinking content is returned
// when the model supports the display field.
type AnthropicThinkingDisplay string
const (
// AnthropicThinkingDisplaySummarized requests summarized thinking text.
AnthropicThinkingDisplaySummarized AnthropicThinkingDisplay = "summarized"
// AnthropicThinkingDisplayOmitted asks Anthropic to omit thinking text while
// preserving signatures for replay.
AnthropicThinkingDisplayOmitted AnthropicThinkingDisplay = "omitted"
)
// GoogleOptions carries Google-specific request options known to the root
// package without importing provider adapters.
type GoogleOptions struct {
ThinkingBudgetTokens *int
ToolChoice string
DisableThinking *bool
}
// MistralOptions carries Mistral-specific request options known to the root
// package without importing the provider adapter.
type MistralOptions struct {
ToolChoice *MistralToolChoice
}
// MistralToolChoiceType identifies Mistral Conversations tool selection behavior.
type MistralToolChoiceType string
const (
// MistralToolChoiceAuto lets Mistral choose whether to call a tool.
MistralToolChoiceAuto MistralToolChoiceType = "auto"
// MistralToolChoiceAny asks Mistral to call one of the supplied tools.
MistralToolChoiceAny MistralToolChoiceType = "any"
// MistralToolChoiceNone prevents Mistral from calling tools.
MistralToolChoiceNone MistralToolChoiceType = "none"
// MistralToolChoiceRequired requires Mistral to call one of the supplied tools.
MistralToolChoiceRequired MistralToolChoiceType = "required"
// MistralToolChoiceTool requires Mistral to call the named function.
MistralToolChoiceTool MistralToolChoiceType = "function"
)
// MistralToolChoice carries Mistral Conversations tool choice controls.
type MistralToolChoice struct {
Type MistralToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
// BedrockToolChoiceType identifies Bedrock Converse tool selection behavior.
type BedrockToolChoiceType string
const (
// BedrockToolChoiceAuto lets Bedrock choose whether to call a tool.
BedrockToolChoiceAuto BedrockToolChoiceType = "auto"
// BedrockToolChoiceAny requires Bedrock to call one of the supplied tools.
BedrockToolChoiceAny BedrockToolChoiceType = "any"
// BedrockToolChoiceNone omits tools from the Bedrock request.
BedrockToolChoiceNone BedrockToolChoiceType = "none"
// BedrockToolChoiceTool requires Bedrock to call the named tool.
BedrockToolChoiceTool BedrockToolChoiceType = "tool"
)
// BedrockToolChoice carries Bedrock Converse tool choice controls.
type BedrockToolChoice struct {
Type BedrockToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
// BedrockThinkingDisplay controls how Claude thinking content is returned by
// Bedrock when the model supports the display field.
type BedrockThinkingDisplay string
const (
// BedrockThinkingDisplaySummarized requests summarized thinking text.
BedrockThinkingDisplaySummarized BedrockThinkingDisplay = "summarized"
// BedrockThinkingDisplayOmitted asks Bedrock to omit thinking text while
// preserving signatures for replay.
BedrockThinkingDisplayOmitted BedrockThinkingDisplay = "omitted"
)
// BedrockOptions carries Bedrock-specific request options known to the root
// package without importing the provider adapter.
type BedrockOptions struct {
ToolChoice *BedrockToolChoice
BearerToken string
ThinkingDisplay BedrockThinkingDisplay
InterleavedThinking *bool
StopSequences []string
TopP *float64
ResponseFormat any
RequestMetadata map[string]string
AdditionalModelRequestFields map[string]any
AdditionalModelResponseFieldPaths []string
}
// StructuredOutputType identifies provider-neutral structured-output modes.
type StructuredOutputType string
const (
// StructuredOutputJSONObject asks the provider to return any JSON object.
StructuredOutputJSONObject StructuredOutputType = "json_object"
// StructuredOutputJSONSchema asks the provider to return an object matching
// the supplied JSON Schema-compatible schema.
StructuredOutputJSONSchema StructuredOutputType = "json_schema"
)
// StructuredOutput describes a provider-neutral structured-output request.
type StructuredOutput struct {
Type StructuredOutputType
Name string
Schema any
Strict bool
}
// Options configures a single provider request.
//
// Client.Stream merges options in this order: client defaults, defaults from
// the selected model metadata, call options, then provider-specific extension
// values inside ProviderOptions. Provider packages may define their own helper
// option functions that populate ProviderOptions without changing this root
// package.
type Options struct {
Temperature *float64
MaxTokens *int
AutomaticMaxTokensForContext *bool
APIKey string
OAuthMinimumValidity *time.Duration
HTTPClient *http.Client
AuthResolver AuthResolver
Transport Transport
CacheRetention CacheRetention
SessionID string
Headers map[string]string
SuppressedHeaders []string
Timeout *time.Duration
MaxRetries *int
MaxRetryDelay *time.Duration
Metadata map[string]any
ReasoningLevel ThinkingLevel
ThinkingBudgetTokens *int
ToolChoice ToolChoice
StructuredOutput *StructuredOutput
TopLogprobs int
ProviderOptions map[ProviderID]map[string]any
ProviderAuthResolvers map[ProviderID]AuthResolver
TextPayloadDebugHooks []TextPayloadDebugHook
TextResponseDebugHooks []TextResponseDebugHook
ImagePayloadDebugHooks []ImagePayloadDebugHook
ImageResponseDebugHooks []ImageResponseDebugHook
EmbeddingPayloadDebugHooks []EmbeddingPayloadDebugHook
EmbeddingResponseDebugHooks []EmbeddingResponseDebugHook
OpenAIOptions *OpenAIOptions
AnthropicOptions *AnthropicOptions
GoogleOptions *GoogleOptions
MistralOptions *MistralOptions
BedrockOptions *BedrockOptions
}
// Option configures a single provider request.
type Option func(*Options)
// WithTemperature configures sampling temperature for a request.
func WithTemperature(temperature float64) Option {
return func(options *Options) {
options.Temperature = float64Ptr(temperature)
}
}
// WithMaxTokens configures the maximum output tokens for a request.
func WithMaxTokens(maxTokens int) Option {
return func(options *Options) {
options.MaxTokens = intPtr(maxTokens)
}
}
// WithAutomaticMaxTokensForContext configures dispatch-time max token
// budgeting from model context metadata and EstimateRequestTokens.
func WithAutomaticMaxTokensForContext(enabled bool) Option {
return func(options *Options) {
options.AutomaticMaxTokensForContext = boolPtr(enabled)
}
}
// WithAPIKey configures a request-scoped API key override.
//
// API key overrides are intentionally not retained by WithDefaultOptions.
func WithAPIKey(apiKey string) Option {
return func(options *Options) {
options.APIKey = apiKey
}
}
// WithOAuthMinimumValidity requires an OAuth credential to retain at least the
// requested lifetime before dispatch. It may trigger an early refresh but does
// not shorten provider-configured refresh windows.
func WithOAuthMinimumValidity(minimumValidity time.Duration) Option {
return func(options *Options) {
options.OAuthMinimumValidity = durationPtr(minimumValidity)
}
}
// WithRequestHTTPClient configures an HTTP client for a text request.
//
// A non-nil request client takes precedence over configured client and provider
// fallback clients. A nil client retains the existing fallback behavior. This
// option applies to HTTP and SSE dispatch; WebSocket transports keep their
// existing dialing behavior.
func WithRequestHTTPClient(httpClient *http.Client) Option {
return func(options *Options) {
options.HTTPClient = httpClient
}
}
// WithTransport configures the provider transport for a request.
func WithTransport(transport Transport) Option {
return func(options *Options) {
options.Transport = transport
}
}
// WithCacheRetention configures provider-side prompt cache retention.
func WithCacheRetention(retention CacheRetention) Option {
return func(options *Options) {
options.CacheRetention = retention
}
}
// WithSessionID configures a provider conversation or response session id.
func WithSessionID(sessionID string) Option {
return func(options *Options) {
options.SessionID = sessionID
}
}
// WithHeader adds or replaces a request header.
func WithHeader(key, value string) Option {
return func(options *Options) {
options.Headers = headerutil.Merge(options.Headers, map[string]string{key: value})
}
}
// WithHeaders adds or replaces request headers.
func WithHeaders(headers map[string]string) Option {
return func(options *Options) {
if len(headers) == 0 {
return
}
options.Headers = headerutil.Merge(options.Headers, headers)
}
}
// WithSuppressedHeader removes a final outgoing request header by name.
//
// Suppression applies after provider, model, and caller headers are merged.
// Credential-bearing auth headers are not suppressed.
func WithSuppressedHeader(key string) Option {
return WithSuppressedHeaders(key)
}
// WithSuppressedHeaders removes final outgoing request headers by name.
//
// Header names are matched case-insensitively. Empty names are ignored.
func WithSuppressedHeaders(keys ...string) Option {
return func(options *Options) {
for _, key := range keys {
trimmed := strings.TrimSpace(key)
if trimmed == "" {
continue
}
options.SuppressedHeaders = append(options.SuppressedHeaders, trimmed)
}
}
}
// WithTimeout configures the per-request provider timeout. Zero disables the
// request timeout; cancellation still follows the parent context.
func WithTimeout(timeout time.Duration) Option {
return func(options *Options) {
options.Timeout = durationPtr(timeout)
}
}
// WithMaxRetries configures the maximum HTTP provider retry attempts after the
// first request. The default is DefaultMaxRetries.
func WithMaxRetries(maxRetries int) Option {
return func(options *Options) {
options.MaxRetries = intPtr(maxRetries)
}
}
// WithMaxRetryDelay configures the maximum delay between HTTP provider retries,
// including provider Retry-After values. The default is DefaultMaxRetryDelay.
// Zero retries without backoff and fails any response that asks to wait.
func WithMaxRetryDelay(maxRetryDelay time.Duration) Option {
return func(options *Options) {
options.MaxRetryDelay = durationPtr(maxRetryDelay)
}
}
// WithMetadata adds or replaces provider-neutral request metadata.
func WithMetadata(metadata map[string]any) Option {
return func(options *Options) {
if len(metadata) == 0 {
return
}
if options.Metadata == nil {
options.Metadata = make(map[string]any, len(metadata))
}
for key, value := range metadata {
options.Metadata[key] = value
}
}
}
// WithMetadataValue adds or replaces one provider-neutral metadata value.
func WithMetadataValue(key string, value any) Option {
return func(options *Options) {
if options.Metadata == nil {
options.Metadata = make(map[string]any)
}
options.Metadata[key] = value
}
}
// WithReasoningLevel configures a provider-neutral reasoning level.
func WithReasoningLevel(level ThinkingLevel) Option {
return func(options *Options) {
options.ReasoningLevel = level
}
}
// WithThinkingBudgetTokens configures a provider-neutral thinking budget.
func WithThinkingBudgetTokens(tokens int) Option {
return func(options *Options) {
options.ThinkingBudgetTokens = intPtr(tokens)
}
}
// WithToolChoice configures provider-neutral tool selection for a request.
func WithToolChoice(choice ToolChoice) Option {
return func(options *Options) {
options.ToolChoice = choice
}
}
// WithStructuredOutput requests provider-neutral structured output.
func WithStructuredOutput(output StructuredOutput) Option {
return func(options *Options) {
options.StructuredOutput = cloneStructuredOutput(&output)
}
}
// WithJSONOutput asks the provider to return any JSON object.
func WithJSONOutput() Option {
return WithStructuredOutput(StructuredOutput{Type: StructuredOutputJSONObject})
}
// WithJSONSchemaOutput asks the provider to return JSON matching schema.
func WithJSONSchemaOutput(name string, schema any, strict bool) Option {
return WithStructuredOutput(StructuredOutput{
Type: StructuredOutputJSONSchema,
Name: name,
Schema: schema,
Strict: strict,
})
}
// WithTopLogprobs requests top token log probabilities when the provider API
// supports them.
func WithTopLogprobs(top int) Option {
return func(options *Options) {
options.TopLogprobs = top
}
}
// WithProviderOptions adds or replaces advanced provider-specific values.
func WithProviderOptions(provider ProviderID, values map[string]any) Option {
return func(options *Options) {
if len(values) == 0 {
return
}
if options.ProviderOptions == nil {
options.ProviderOptions = make(map[ProviderID]map[string]any)
}
if options.ProviderOptions[provider] == nil {
options.ProviderOptions[provider] = make(map[string]any, len(values))
}
for key, value := range values {
options.ProviderOptions[provider][key] = value
}
}
}
// WithProviderOption adds or replaces one advanced provider-specific value.
func WithProviderOption(provider ProviderID, key string, value any) Option {
return func(options *Options) {
if options.ProviderOptions == nil {
options.ProviderOptions = make(map[ProviderID]map[string]any)
}
if options.ProviderOptions[provider] == nil {
options.ProviderOptions[provider] = make(map[string]any)
}
options.ProviderOptions[provider][key] = value
}
}
// WithProviderAuthResolver configures a provider-specific credential callback.
func WithProviderAuthResolver(provider ProviderID, resolver AuthResolver) Option {
return func(options *Options) {
if resolver == nil {
return
}
if options.ProviderAuthResolvers == nil {
options.ProviderAuthResolvers = make(map[ProviderID]AuthResolver)
}
options.ProviderAuthResolvers[provider] = resolver
}
}
// WithOpenAIOptions configures known OpenAI-specific request options.
func WithOpenAIOptions(openAIOptions OpenAIOptions) Option {
return func(options *Options) {
options.OpenAIOptions = cloneOpenAIOptions(&openAIOptions)
}
}
// WithAnthropicOptions configures known Anthropic-specific request options.
func WithAnthropicOptions(anthropicOptions AnthropicOptions) Option {
return func(options *Options) {
options.AnthropicOptions = cloneAnthropicOptions(&anthropicOptions)
}
}
// WithGoogleOptions configures known Google-specific request options.
func WithGoogleOptions(googleOptions GoogleOptions) Option {
return func(options *Options) {
options.GoogleOptions = cloneGoogleOptions(&googleOptions)
}
}
// WithMistralOptions configures known Mistral-specific request options.
func WithMistralOptions(mistralOptions MistralOptions) Option {
return func(options *Options) {
options.MistralOptions = cloneMistralOptions(&mistralOptions)
}
}
// WithBedrockOptions configures known Bedrock-specific request options.
func WithBedrockOptions(bedrockOptions BedrockOptions) Option {
return func(options *Options) {
options.BedrockOptions = cloneBedrockOptions(&bedrockOptions)
}
}
func applyOptions(options Options, opts []Option) Options {
applied := cloneOptions(options)
for _, opt := range opts {
if opt != nil {
opt(&applied)
}
}
return applied
}
func cloneOptions(options Options) Options {
return Options{
Temperature: cloneFloat64Ptr(options.Temperature),
MaxTokens: cloneIntPtr(options.MaxTokens),
AutomaticMaxTokensForContext: cloneBoolPtr(options.AutomaticMaxTokensForContext),
APIKey: options.APIKey,
OAuthMinimumValidity: cloneDurationPtr(options.OAuthMinimumValidity),
HTTPClient: options.HTTPClient,
AuthResolver: options.AuthResolver,
Transport: options.Transport,
CacheRetention: options.CacheRetention,
SessionID: options.SessionID,
Headers: headerutil.Merge(nil, options.Headers),
SuppressedHeaders: append([]string(nil), options.SuppressedHeaders...),
Timeout: cloneDurationPtr(options.Timeout),
MaxRetries: cloneIntPtr(options.MaxRetries),
MaxRetryDelay: cloneDurationPtr(options.MaxRetryDelay),
Metadata: copyStringAnyMap(options.Metadata),
ReasoningLevel: options.ReasoningLevel,
ThinkingBudgetTokens: cloneIntPtr(options.ThinkingBudgetTokens),
ToolChoice: options.ToolChoice,
StructuredOutput: cloneStructuredOutput(options.StructuredOutput),
TopLogprobs: options.TopLogprobs,
ProviderOptions: copyProviderOptions(options.ProviderOptions),
ProviderAuthResolvers: copyProviderAuthResolvers(options.ProviderAuthResolvers),
TextPayloadDebugHooks: append([]TextPayloadDebugHook(nil), options.TextPayloadDebugHooks...),
TextResponseDebugHooks: append([]TextResponseDebugHook(nil), options.TextResponseDebugHooks...),
ImagePayloadDebugHooks: append([]ImagePayloadDebugHook(nil), options.ImagePayloadDebugHooks...),
ImageResponseDebugHooks: append([]ImageResponseDebugHook(nil), options.ImageResponseDebugHooks...),
EmbeddingPayloadDebugHooks: append([]EmbeddingPayloadDebugHook(nil), options.EmbeddingPayloadDebugHooks...),
EmbeddingResponseDebugHooks: append([]EmbeddingResponseDebugHook(nil), options.EmbeddingResponseDebugHooks...),
OpenAIOptions: cloneOpenAIOptions(options.OpenAIOptions),
AnthropicOptions: cloneAnthropicOptions(options.AnthropicOptions),
GoogleOptions: cloneGoogleOptions(options.GoogleOptions),
MistralOptions: cloneMistralOptions(options.MistralOptions),
BedrockOptions: cloneBedrockOptions(options.BedrockOptions),
}
}
func copyProviderOptions(values map[ProviderID]map[string]any) map[ProviderID]map[string]any {
if len(values) == 0 {
return nil
}
copied := make(map[ProviderID]map[string]any, len(values))
for provider, providerValues := range values {
copied[provider] = copyStringAnyMap(providerValues)
}
return copied
}
func copyProviderAuthResolvers(values map[ProviderID]AuthResolver) map[ProviderID]AuthResolver {
if len(values) == 0 {
return nil
}
copied := make(map[ProviderID]AuthResolver, len(values))
for provider, resolver := range values {
copied[provider] = resolver
}
return copied
}
func cloneOpenAIOptions(options *OpenAIOptions) *OpenAIOptions {
if options == nil {
return nil
}
copied := *options
copied.ParallelToolCalls = cloneBoolPtr(options.ParallelToolCalls)
copied.EnableGrammarTools = cloneBoolPtr(options.EnableGrammarTools)
copied.CodexWebSocketConnectTimeout = cloneDurationPtr(options.CodexWebSocketConnectTimeout)
copied.SamplingParameters = copyStringAnyMap(options.SamplingParameters)
return &copied
}
func cloneAnthropicOptions(options *AnthropicOptions) *AnthropicOptions {
if options == nil {
return nil
}
copied := *options
copied.ThinkingBudgetTokens = cloneIntPtr(options.ThinkingBudgetTokens)
if options.ToolChoice != nil {
toolChoice := *options.ToolChoice
copied.ToolChoice = &toolChoice
}
copied.InterleavedThinking = cloneBoolPtr(options.InterleavedThinking)
copied.OutputFormat = cloneAnyValue(options.OutputFormat)
copied.DisableParallelToolUse = cloneBoolPtr(options.DisableParallelToolUse)
return &copied
}
func cloneStructuredOutput(output *StructuredOutput) *StructuredOutput {
if output == nil {
return nil
}
copied := *output
copied.Schema = cloneAnyValue(output.Schema)
return &copied
}
func cloneGoogleOptions(options *GoogleOptions) *GoogleOptions {
if options == nil {
return nil
}
copied := *options
copied.ThinkingBudgetTokens = cloneIntPtr(options.ThinkingBudgetTokens)
copied.DisableThinking = cloneBoolPtr(options.DisableThinking)
return &copied
}
func cloneMistralOptions(options *MistralOptions) *MistralOptions {
if options == nil {
return nil
}
copied := *options
if options.ToolChoice != nil {
toolChoice := *options.ToolChoice
copied.ToolChoice = &toolChoice
}
return &copied
}
func cloneBedrockOptions(options *BedrockOptions) *BedrockOptions {
if options == nil {
return nil
}
copied := *options
if options.ToolChoice != nil {
toolChoice := *options.ToolChoice
copied.ToolChoice = &toolChoice
}
copied.InterleavedThinking = cloneBoolPtr(options.InterleavedThinking)
copied.StopSequences = append([]string(nil), options.StopSequences...)
copied.TopP = cloneFloat64Ptr(options.TopP)
copied.ResponseFormat = cloneAnyValue(options.ResponseFormat)
copied.RequestMetadata = copyStringStringMap(options.RequestMetadata)
copied.AdditionalModelRequestFields = copyStringAnyMap(options.AdditionalModelRequestFields)
copied.AdditionalModelResponseFieldPaths = append([]string(nil), options.AdditionalModelResponseFieldPaths...)
return &copied
}
func intPtr(value int) *int {
return &value
}
func float64Ptr(value float64) *float64 {
return &value
}
func durationPtr(value time.Duration) *time.Duration {
return &value
}
func boolPtr(value bool) *bool {
return &value
}
func cloneIntPtr(value *int) *int {
if value == nil {
return nil
}
copied := *value
return &copied
}
func cloneFloat64Ptr(value *float64) *float64 {
if value == nil {
return nil
}
copied := *value
return &copied
}
func cloneDurationPtr(value *time.Duration) *time.Duration {
if value == nil {
return nil
}
copied := *value
return &copied
}