diff --git a/aisdk/ai/options.go b/aisdk/ai/options.go index d9ce3089..d96f8842 100644 --- a/aisdk/ai/options.go +++ b/aisdk/ai/options.go @@ -127,6 +127,14 @@ func WithProviderMetadata(providerName string, metadata any) GenerateOption { } } +// WithCallOptions sets the entire CallOptions struct. +// This allows passing a pre-configured CallOptions instance. +func WithCallOptions(callOptions api.CallOptions) GenerateOption { + return func(o *GenerateOptions) { + o.CallOptions = callOptions + } +} + // buildGenerateConfig combines multiple generate options into a single GenerateConfig struct. func buildGenerateConfig(opts []GenerateOption) GenerateOptions { config := GenerateOptions{ diff --git a/aisdk/ai/options_test.go b/aisdk/ai/options_test.go index 8cc81e4d..b2c4f735 100644 --- a/aisdk/ai/options_test.go +++ b/aisdk/ai/options_test.go @@ -154,6 +154,29 @@ func TestCallOptionBuilders(t *testing.T) { Model: &mockLanguageModel{name: "test-model"}, }, }, + { + name: "WithCallOptions", + option: WithCallOptions(api.CallOptions{ + MaxOutputTokens: 500, + Temperature: pointer.Float64(0.5), + TopP: 0.8, + StopSequences: []string{"END"}, + Seed: 123, + PresencePenalty: 0.1, + FrequencyPenalty: 0.2, + }), + expected: GenerateOptions{ + CallOptions: api.CallOptions{ + MaxOutputTokens: 500, + Temperature: pointer.Float64(0.5), + TopP: 0.8, + StopSequences: []string{"END"}, + Seed: 123, + PresencePenalty: 0.1, + FrequencyPenalty: 0.2, + }, + }, + }, } for _, tt := range tests {