@@ -73,3 +73,108 @@ func TestWithLegacyMaxTokensField(t *testing.T) {
7373 t .Error ("expected openai:use_legacy_max_tokens to be true" )
7474 }
7575}
76+
77+ func TestWithWebSearch (t * testing.T ) {
78+ // Test with nil options (default behavior)
79+ opts := & llms.CallOptions {}
80+ llms .WithWebSearch (nil )(opts )
81+ if opts .WebSearchOptions == nil {
82+ t .Fatal ("expected WebSearchOptions to be initialized" )
83+ }
84+
85+ // Test with custom search context size
86+ opts2 := & llms.CallOptions {}
87+ llms .WithWebSearch (& llms.WebSearchOptions {
88+ SearchContextSize : "high" ,
89+ })(opts2 )
90+ if opts2 .WebSearchOptions == nil {
91+ t .Fatal ("expected WebSearchOptions to be set" )
92+ }
93+ if opts2 .WebSearchOptions .SearchContextSize != "high" {
94+ t .Errorf ("expected SearchContextSize=high, got %s" , opts2 .WebSearchOptions .SearchContextSize )
95+ }
96+
97+ // Test with user location
98+ opts3 := & llms.CallOptions {}
99+ llms .WithWebSearch (& llms.WebSearchOptions {
100+ SearchContextSize : "medium" ,
101+ UserLocation : & llms.UserLocation {
102+ Type : "approximate" ,
103+ Approximate : & llms.ApproximateLocation {
104+ Country : "US" ,
105+ City : "San Francisco" ,
106+ Region : "California" ,
107+ },
108+ },
109+ })(opts3 )
110+ if opts3 .WebSearchOptions == nil {
111+ t .Fatal ("expected WebSearchOptions to be set" )
112+ }
113+ if opts3 .WebSearchOptions .UserLocation == nil {
114+ t .Fatal ("expected UserLocation to be set" )
115+ }
116+ if opts3 .WebSearchOptions .UserLocation .Type != "approximate" {
117+ t .Errorf ("expected Type=approximate, got %s" , opts3 .WebSearchOptions .UserLocation .Type )
118+ }
119+ if opts3 .WebSearchOptions .UserLocation .Approximate == nil {
120+ t .Fatal ("expected Approximate to be set" )
121+ }
122+ if opts3 .WebSearchOptions .UserLocation .Approximate .Country != "US" {
123+ t .Errorf ("expected Country=US, got %s" , opts3 .WebSearchOptions .UserLocation .Approximate .Country )
124+ }
125+ if opts3 .WebSearchOptions .UserLocation .Approximate .City != "San Francisco" {
126+ t .Errorf ("expected City=San Francisco, got %s" , opts3 .WebSearchOptions .UserLocation .Approximate .City )
127+ }
128+ if opts3 .WebSearchOptions .UserLocation .Approximate .Region != "California" {
129+ t .Errorf ("expected Region=California, got %s" , opts3 .WebSearchOptions .UserLocation .Approximate .Region )
130+ }
131+ }
132+
133+ func TestWebSearchOptionsConversion (t * testing.T ) {
134+ // Test nil conversion
135+ result := webSearchOptionsFromCallOptions (nil )
136+ if result != nil {
137+ t .Error ("expected nil result for nil input" )
138+ }
139+
140+ // Test basic conversion
141+ opts := & llms.WebSearchOptions {
142+ SearchContextSize : "high" ,
143+ }
144+ result = webSearchOptionsFromCallOptions (opts )
145+ if result == nil {
146+ t .Fatal ("expected non-nil result" )
147+ }
148+ if result .SearchContextSize != "high" {
149+ t .Errorf ("expected SearchContextSize=high, got %s" , result .SearchContextSize )
150+ }
151+
152+ // Test full conversion with user location
153+ opts2 := & llms.WebSearchOptions {
154+ SearchContextSize : "medium" ,
155+ UserLocation : & llms.UserLocation {
156+ Type : "approximate" ,
157+ Approximate : & llms.ApproximateLocation {
158+ Country : "GB" ,
159+ City : "London" ,
160+ Region : "London" ,
161+ },
162+ },
163+ }
164+ result2 := webSearchOptionsFromCallOptions (opts2 )
165+ if result2 == nil {
166+ t .Fatal ("expected non-nil result" )
167+ }
168+ if result2 .UserLocation == nil {
169+ t .Fatal ("expected UserLocation to be set" )
170+ }
171+ if result2 .UserLocation .Type != "approximate" {
172+ t .Errorf ("expected Type=approximate, got %s" , result2 .UserLocation .Type )
173+ }
174+ if result2 .UserLocation .Approximate == nil {
175+ t .Fatal ("expected Approximate to be set" )
176+ }
177+ if result2 .UserLocation .Approximate .Country != "GB" {
178+ t .Errorf ("expected Country=GB, got %s" , result2 .UserLocation .Approximate .Country )
179+ }
180+ }
0 commit comments