Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions aisdk/ai/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
23 changes: 23 additions & 0 deletions aisdk/ai/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading