1package providertests
2
3import (
4 "cmp"
5 "net/http"
6 "os"
7 "testing"
8
9 "charm.land/fantasy"
10 "charm.land/fantasy/azure"
11 "charm.land/fantasy/openai"
12 "github.com/stretchr/testify/require"
13 "gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
14)
15
16const defaultBaseURL = "https://fantasy-playground-resource.services.ai.azure.com/"
17
18func TestAzureCommon(t *testing.T) {
19 testCommon(t, []builderPair{
20 {"azure-o4-mini", builderAzureO4Mini, nil},
21 {"azure-gpt-5-mini", builderAzureGpt5Mini, nil},
22 {"azure-grok-3-mini", builderAzureGrok3Mini, nil},
23 })
24}
25
26func TestAzureThinking(t *testing.T) {
27 opts := fantasy.ProviderOptions{
28 openai.Name: &openai.ProviderOptions{
29 ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortLow),
30 },
31 }
32 testThinking(t, []builderPair{
33 {"azure-gpt-5-mini", builderAzureGpt5Mini, opts},
34 {"azure-grok-3-mini", builderAzureGrok3Mini, opts},
35 }, testAzureThinking)
36}
37
38func testAzureThinking(t *testing.T, result *fantasy.AgentResult) {
39 require.Greater(t, result.Response.Usage.ReasoningTokens, int64(0), "expected reasoning tokens, got none")
40}
41
42func builderAzureO4Mini(r *recorder.Recorder) (fantasy.LanguageModel, error) {
43 provider := azure.New(
44 azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
45 azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
46 azure.WithHTTPClient(&http.Client{Transport: r}),
47 )
48 return provider.LanguageModel("o4-mini")
49}
50
51func builderAzureGpt5Mini(r *recorder.Recorder) (fantasy.LanguageModel, error) {
52 provider := azure.New(
53 azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
54 azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
55 azure.WithHTTPClient(&http.Client{Transport: r}),
56 )
57 return provider.LanguageModel("gpt-5-mini")
58}
59
60func builderAzureGrok3Mini(r *recorder.Recorder) (fantasy.LanguageModel, error) {
61 provider := azure.New(
62 azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
63 azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
64 azure.WithHTTPClient(&http.Client{Transport: r}),
65 )
66 return provider.LanguageModel("grok-3-mini")
67}