Detailed changes
@@ -255,7 +255,7 @@ func (g languageModel) prepareParams(call fantasy.Call) (*genai.GenerateContentC
Type: fantasy.CallWarningTypeOther,
Message: "The 'thinking_budget' option can not be under 128 and will be set to 128 by default",
})
- providerOptions.ThinkingConfig.ThinkingBudget = fantasy.Opt(int64(128))
+ providerOptions.ThinkingConfig.ThinkingBudget = new(int64(128))
}
if providerOptions.ThinkingConfig.ThinkingLevel != nil &&
@@ -947,7 +947,7 @@ func TestDoGenerate(t *testing.T) {
result, err := model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- LogProbs: fantasy.Opt(true),
+ LogProbs: new(true),
}),
})
@@ -1068,8 +1068,8 @@ func TestDoGenerate(t *testing.T) {
LogitBias: map[string]int64{
"50256": -100,
},
- ParallelToolCalls: fantasy.Opt(false),
- User: fantasy.Opt("test-user-id"),
+ ParallelToolCalls: new(false),
+ User: new("test-user-id"),
}),
})
@@ -1109,7 +1109,7 @@ func TestDoGenerate(t *testing.T) {
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(
&ProviderOptions{
- ReasoningEffort: ReasoningEffortOption(ReasoningEffortLow),
+ ReasoningEffort: new(ReasoningEffortLow),
},
),
})
@@ -1149,7 +1149,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- TextVerbosity: fantasy.Opt("low"),
+ TextVerbosity: new("low"),
}),
})
@@ -1610,7 +1610,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- MaxCompletionTokens: fantasy.Opt(int64(255)),
+ MaxCompletionTokens: new(int64(255)),
}),
})
@@ -1694,7 +1694,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- Store: fantasy.Opt(true),
+ Store: new(true),
}),
})
@@ -1776,7 +1776,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- PromptCacheKey: fantasy.Opt("test-cache-key-123"),
+ PromptCacheKey: new("test-cache-key-123"),
}),
})
@@ -1815,7 +1815,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- SafetyIdentifier: fantasy.Opt("test-safety-identifier-123"),
+ SafetyIdentifier: new("test-safety-identifier-123"),
}),
})
@@ -1887,7 +1887,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("flex"),
+ ServiceTier: new("flex"),
}),
})
@@ -1924,7 +1924,7 @@ func TestDoGenerate(t *testing.T) {
result, err := model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("flex"),
+ ServiceTier: new("flex"),
}),
})
@@ -1958,7 +1958,7 @@ func TestDoGenerate(t *testing.T) {
_, err = model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("priority"),
+ ServiceTier: new("priority"),
}),
})
@@ -1995,7 +1995,7 @@ func TestDoGenerate(t *testing.T) {
result, err := model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("priority"),
+ ServiceTier: new("priority"),
}),
})
@@ -2752,7 +2752,7 @@ func TestDoStream(t *testing.T) {
_, err = model.Stream(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- Store: fantasy.Opt(true),
+ Store: new(true),
}),
})
@@ -2842,7 +2842,7 @@ func TestDoStream(t *testing.T) {
_, err = model.Stream(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("flex"),
+ ServiceTier: new("flex"),
}),
})
@@ -2885,7 +2885,7 @@ func TestDoStream(t *testing.T) {
_, err = model.Stream(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: NewProviderOptions(&ProviderOptions{
- ServiceTier: fantasy.Opt("priority"),
+ ServiceTier: new("priority"),
}),
})
@@ -3686,7 +3686,7 @@ func TestResponsesGenerate_StoreOption(t *testing.T) {
Prompt: testPrompt,
ProviderOptions: fantasy.ProviderOptions{
Name: &ResponsesProviderOptions{
- Store: fantasy.Opt(true),
+ Store: new(true),
},
},
})
@@ -3710,8 +3710,8 @@ func TestResponsesGenerate_PreviousResponseIDOption(t *testing.T) {
Prompt: testPrompt,
ProviderOptions: fantasy.ProviderOptions{
Name: &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_prev_123"),
- Store: fantasy.Opt(true),
+ PreviousResponseID: new("resp_prev_123"),
+ Store: new(true),
},
},
})
@@ -3758,7 +3758,7 @@ func TestResponsesGenerate_StateChainingAcrossTurns(t *testing.T) {
first, err := model.Generate(context.Background(), fantasy.Call{
Prompt: testPrompt,
ProviderOptions: fantasy.ProviderOptions{
- Name: &ResponsesProviderOptions{Store: fantasy.Opt(true)},
+ Name: &ResponsesProviderOptions{Store: new(true)},
},
})
require.NoError(t, err)
@@ -3799,7 +3799,7 @@ func TestResponsesGenerate_StateChainingAcrossTurns(t *testing.T) {
},
ProviderOptions: fantasy.ProviderOptions{
Name: &ResponsesProviderOptions{
- Store: fantasy.Opt(true),
+ Store: new(true),
PreviousResponseID: &meta.ResponseID,
},
},
@@ -4164,7 +4164,7 @@ func TestResponsesStream_StoreOption(t *testing.T) {
Prompt: testPrompt,
ProviderOptions: fantasy.ProviderOptions{
Name: &ResponsesProviderOptions{
- Store: fantasy.Opt(true),
+ Store: new(true),
},
},
})
@@ -4197,8 +4197,8 @@ func TestResponsesStream_PreviousResponseIDOption(t *testing.T) {
Prompt: testPrompt,
ProviderOptions: fantasy.ProviderOptions{
Name: &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_prev_456"),
- Store: fantasy.Opt(true),
+ PreviousResponseID: new("resp_prev_456"),
+ Store: new(true),
},
},
})
@@ -146,8 +146,10 @@ func (o *ProviderFileOptions) UnmarshalJSON(data []byte) error {
}
// ReasoningEffortOption creates a pointer to a ReasoningEffort value.
+//
+//go:fix inline
func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort {
- return &e
+ return new(e)
}
// NewProviderOptions creates new provider options for OpenAI.
@@ -1090,8 +1090,8 @@ func (o responsesLanguageModel) Stream(ctx context.Context, call fantasy.Call) (
case "response.output_text.annotation.added":
added := event.AsResponseOutputTextAnnotationAdded()
// The Annotation field is typed as `any` in the SDK;
- // it deserializes as map[string]interface{} from JSON.
- annotationMap, ok := added.Annotation.(map[string]interface{})
+ // it deserializes as map[string]any from JSON.
+ annotationMap, ok := added.Annotation.(map[string]any)
if !ok {
break
}
@@ -21,12 +21,12 @@ func TestPrepareParams_Store(t *testing.T) {
}{
{
name: "store true",
- opts: &ResponsesProviderOptions{Store: fantasy.Opt(true)},
+ opts: &ResponsesProviderOptions{Store: new(true)},
wantStore: true,
},
{
name: "store false",
- opts: &ResponsesProviderOptions{Store: fantasy.Opt(false)},
+ opts: &ResponsesProviderOptions{Store: new(false)},
wantStore: false,
},
{
@@ -42,7 +42,6 @@ func TestPrepareParams_Store(t *testing.T) {
}
for _, tt := range tests {
- tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -65,8 +64,8 @@ func TestPrepareParams_PreviousResponseID(t *testing.T) {
t.Parallel()
params, warnings, err := lm.prepareParams(testCall(prompt, &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_abc123"),
- Store: fantasy.Opt(true),
+ PreviousResponseID: new("resp_abc123"),
+ Store: new(true),
}))
require.NoError(t, err)
require.Empty(t, warnings)
@@ -87,7 +86,7 @@ func TestPrepareParams_PreviousResponseID(t *testing.T) {
t.Parallel()
params, warnings, err := lm.prepareParams(testCall(prompt, &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt(""),
+ PreviousResponseID: new(""),
}))
require.NoError(t, err)
require.Empty(t, warnings)
@@ -100,8 +99,8 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) {
lm := testResponsesLM()
opts := &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_abc123"),
- Store: fantasy.Opt(true),
+ PreviousResponseID: new("resp_abc123"),
+ Store: new(true),
}
t.Run("rejects with assistant messages", func(t *testing.T) {
@@ -152,7 +151,7 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) {
_, _, err := lm.prepareParams(testCall(fantasy.Prompt{
testTextMessage(fantasy.MessageRoleUser, "hello"),
}, &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_abc123"),
+ PreviousResponseID: new("resp_abc123"),
}))
require.EqualError(t, err, previousResponseIDStoreError)
})
@@ -163,8 +162,8 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) {
_, _, err := lm.prepareParams(testCall(fantasy.Prompt{
testTextMessage(fantasy.MessageRoleUser, "hello"),
}, &ResponsesProviderOptions{
- PreviousResponseID: fantasy.Opt("resp_abc123"),
- Store: fantasy.Opt(false),
+ PreviousResponseID: new("resp_abc123"),
+ Store: new(false),
}))
require.EqualError(t, err, previousResponseIDStoreError)
})
@@ -223,7 +222,6 @@ func TestValidatePreviousResponseIDPrompt(t *testing.T) {
}
for _, tt := range tests {
- tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@@ -189,8 +189,10 @@ type ReasoningData struct {
}
// ReasoningEffortOption creates a pointer to a ReasoningEffort value for OpenRouter.
+//
+//go:fix inline
func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort {
- return &e
+ return new(e)
}
// NewProviderOptions creates new provider options for OpenRouter.
@@ -170,8 +170,10 @@ type ReasoningData struct {
}
// ReasoningEffortOption creates a pointer to a ReasoningEffort value.
+//
+//go:fix inline
func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort {
- return &e
+ return new(e)
}
// NewProviderOptions creates new provider options for Vercel.
@@ -177,7 +177,7 @@ func TestAnthropicWebSearch(t *testing.T) {
result, err := agent.Generate(t.Context(), fantasy.AgentCall{
Prompt: "What is the current population of Tokyo? Cite your source.",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
@@ -222,7 +222,7 @@ func TestAnthropicWebSearch(t *testing.T) {
// Turn 1: initial query triggers web search.
result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Prompt: "What is the current population of Tokyo? Cite your source.",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
@@ -266,7 +266,7 @@ func TestAnthropicWebSearch(t *testing.T) {
result2, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Messages: history,
Prompt: "How does that compare to Osaka?",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
@@ -47,7 +47,7 @@ func TestAzureResponsesWithSummaryThinking(t *testing.T) {
openai.IncludeReasoningEncryptedContent,
},
ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortHigh),
- ReasoningSummary: fantasy.Opt("auto"),
+ ReasoningSummary: new("auto"),
},
}
var pairs []builderPair
@@ -70,7 +70,7 @@ func testSimple(t *testing.T, pair builderPair) {
result, err := agent.Generate(t.Context(), fantasy.AgentCall{
Prompt: "Say hi in Portuguese",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -90,7 +90,7 @@ func testSimple(t *testing.T, pair builderPair) {
result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Prompt: "Say hi in Portuguese",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -149,7 +149,7 @@ func testTool(t *testing.T, pair builderPair) {
result, err := agent.Generate(t.Context(), fantasy.AgentCall{
Prompt: "What's the weather in Florence,Italy?",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -170,7 +170,7 @@ func testTool(t *testing.T, pair builderPair) {
result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Prompt: "What's the weather in Florence,Italy?",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -255,7 +255,7 @@ func testMultiTool(t *testing.T, pair builderPair) {
result, err := agent.Generate(t.Context(), fantasy.AgentCall{
Prompt: "Add and multiply the number 2 and 3",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -277,7 +277,7 @@ func testMultiTool(t *testing.T, pair builderPair) {
result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Prompt: "Add and multiply the number 2 and 3",
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
PrepareStep: pair.prepareStep,
})
require.NoError(t, err, "failed to generate")
@@ -41,8 +41,8 @@ func TestGoogleThinking(t *testing.T) {
gemini2Opts := fantasy.ProviderOptions{
google.Name: &google.ProviderOptions{
ThinkingConfig: &google.ThinkingConfig{
- ThinkingBudget: fantasy.Opt(int64(100)),
- IncludeThoughts: fantasy.Opt(true),
+ ThinkingBudget: new(int64(100)),
+ IncludeThoughts: new(true),
},
},
}
@@ -50,7 +50,7 @@ func TestGoogleThinking(t *testing.T) {
google.Name: &google.ProviderOptions{
ThinkingConfig: &google.ThinkingConfig{
ThinkingLevel: fantasy.Opt(google.ThinkingLevelHigh),
- IncludeThoughts: fantasy.Opt(true),
+ IncludeThoughts: new(true),
},
},
}
@@ -90,7 +90,7 @@ func TestImageUploadAgent(t *testing.T) {
Prompt: "Describe the image briefly in English.",
Files: []fantasy.FilePart{file},
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
got := result.Response.Content.Text()
@@ -136,7 +136,7 @@ func TestImageUploadAgentStreaming(t *testing.T) {
Prompt: "Describe the image briefly in English.",
Files: []fantasy.FilePart{file},
ProviderOptions: pair.providerOptions,
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
got := result.Response.Content.Text()
@@ -104,7 +104,7 @@ func testSimpleObject(t *testing.T, pair builderPair) {
Schema: schema,
SchemaName: "Person",
SchemaDescription: "A person with name, age, and city",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
ProviderOptions: pair.providerOptions,
})
require.NoError(t, err, "failed to generate object")
@@ -127,7 +127,7 @@ func testSimpleObject(t *testing.T, pair builderPair) {
Schema: schema,
SchemaName: "Person",
SchemaDescription: "A person with name, age, and city",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
ProviderOptions: pair.providerOptions,
})
require.NoError(t, err, "failed to create object stream")
@@ -277,7 +277,7 @@ func testComplexObject(t *testing.T, pair builderPair) {
Schema: schema,
SchemaName: "Book",
SchemaDescription: "A book with title, author, genres, and publication year",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
ProviderOptions: pair.providerOptions,
})
require.NoError(t, err, "failed to generate object")
@@ -300,7 +300,7 @@ func testComplexObject(t *testing.T, pair builderPair) {
Schema: schema,
SchemaName: "Book",
SchemaDescription: "A book with title, author, genres, and publication year",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
ProviderOptions: pair.providerOptions,
})
require.NoError(t, err, "failed to create object stream")
@@ -40,7 +40,7 @@ func TestOpenAIResponsesWithSummaryThinking(t *testing.T) {
openai.IncludeReasoningEncryptedContent,
},
ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortHigh),
- ReasoningSummary: fantasy.Opt("auto"),
+ ReasoningSummary: new("auto"),
},
}
var pairs []builderPair
@@ -47,7 +47,7 @@ func TestOpenAIWebSearch(t *testing.T) {
result, err := agent.Generate(t.Context(), fantasy.AgentCall{
Prompt: "What is the current population of Tokyo? Cite your source.",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
@@ -96,7 +96,7 @@ func TestOpenAIWebSearch(t *testing.T) {
// Turn 1: initial query triggers web search.
result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{
Prompt: "What is the current population of Tokyo? Cite your source.",
- MaxOutputTokens: fantasy.Opt(int64(4000)),
+ MaxOutputTokens: new(int64(4000)),
})
require.NoError(t, err)
@@ -20,7 +20,7 @@ func TestProviderRegistry_Serialization_OpenAIOptions(t *testing.T) {
fantasy.TextPart{Text: "hi"},
},
ProviderOptions: fantasy.ProviderOptions{
- openai.Name: &openai.ProviderOptions{User: fantasy.Opt("tester")},
+ openai.Name: &openai.ProviderOptions{User: new("tester")},
},
}
@@ -60,8 +60,8 @@ func TestProviderRegistry_Serialization_OpenAIResponses(t *testing.T) {
},
ProviderOptions: fantasy.ProviderOptions{
openai.Name: &openai.ResponsesProviderOptions{
- PromptCacheKey: fantasy.Opt("cache-key-1"),
- ParallelToolCalls: fantasy.Opt(true),
+ PromptCacheKey: new("cache-key-1"),
+ ParallelToolCalls: new(true),
},
},
}
@@ -215,7 +215,7 @@ func TestProviderRegistry_Serialization_OpenRouterOptions(t *testing.T) {
ProviderOptions: fantasy.ProviderOptions{
openrouter.Name: &openrouter.ProviderOptions{
IncludeUsage: &includeUsage,
- User: fantasy.Opt("test-user"),
+ User: new("test-user"),
},
},
}
@@ -245,7 +245,7 @@ func TestProviderRegistry_Serialization_OpenAICompatOptions(t *testing.T) {
},
ProviderOptions: fantasy.ProviderOptions{
openaicompat.Name: &openaicompat.ProviderOptions{
- User: fantasy.Opt("test-user"),
+ User: new("test-user"),
ReasoningEffort: &effort,
},
},
@@ -276,7 +276,7 @@ func TestProviderRegistry_MultiProvider(t *testing.T) {
fantasy.TextPart{Text: "test"},
},
ProviderOptions: fantasy.ProviderOptions{
- openai.Name: &openai.ProviderOptions{User: fantasy.Opt("user1")},
+ openai.Name: &openai.ProviderOptions{User: new("user1")},
anthropic.Name: &anthropic.ProviderOptions{
SendReasoning: &sendReasoning,
},
@@ -122,8 +122,8 @@ func generateSchemaRecursive(t reflect.Type, visited map[reflect.Type]bool) Sche
Type: "object",
Properties: make(map[string]*Schema),
}
- for i := range t.NumField() {
- field := t.Field(i)
+ for field := range t.Fields() {
+ field := field
if !field.IsExported() {
continue
@@ -3,8 +3,10 @@ package fantasy
import "github.com/go-viper/mapstructure/v2"
// Opt creates a pointer to the given value.
+//
+//go:fix inline
func Opt[T any](v T) *T {
- return &v
+ return new(v)
}
// ParseOptions parses the given options map into the provided struct.