22
33namespace Devlooped . Extensions . AI . OpenAI ;
44
5- /// <summary>
6- /// Controls how much context is retrieved from the web to help the tool formulate a response.
7- /// </summary>
8- public enum WebSearchContextSize
9- {
10- /// <summary>
11- /// Least context, lowest cost, fastest response, but potentially lower answer quality.
12- /// </summary>
13- Low ,
14- /// <summary>
15- /// (default): Balanced context, cost, and latency.
16- /// </summary>
17- Medium ,
18- /// <summary>
19- /// Most comprehensive context, highest cost, slower response.
20- /// </summary>
21- High
22- }
23-
245public static class OpenAIWebSearchToolExtensions
256{
267 extension ( WebSearchTool web )
@@ -35,7 +16,7 @@ public string? Region
3516 set
3617 {
3718 web . Properties [ "Region" ] = value ;
38- web . Location = WebSearchToolLocation . CreateApproximateLocation ( web . Country , value , web . City , web . TimeZone ) ;
19+ web . Location = WebSearchUserLocation . CreateApproximateLocation ( web . Country , value , web . City , web . TimeZone ) ;
3920 }
4021 }
4122
@@ -49,7 +30,7 @@ public string? City
4930 set
5031 {
5132 web . Properties [ "City" ] = value ;
52- web . Location = WebSearchToolLocation . CreateApproximateLocation ( web . Country , web . Region , value , web . TimeZone ) ;
33+ web . Location = WebSearchUserLocation . CreateApproximateLocation ( web . Country , web . Region , value , web . TimeZone ) ;
5334 }
5435 }
5536
@@ -63,7 +44,7 @@ public string? TimeZone
6344 set
6445 {
6546 web . Properties [ "TimeZone" ] = value ;
66- web . Location = WebSearchToolLocation . CreateApproximateLocation ( web . Country , web . Region , web . City , value ) ;
47+ web . Location = WebSearchUserLocation . CreateApproximateLocation ( web . Country , web . Region , web . City , value ) ;
6748 }
6849 }
6950
@@ -72,20 +53,14 @@ public string? TimeZone
7253 /// </summary>
7354 public WebSearchContextSize ? ContextSize
7455 {
75- get => web . Properties . TryGetValue ( "ContextSize" , out var size ) && size is WebSearchContextSize contextSize
56+ get => web . Properties . TryGetValue ( nameof ( WebSearchContextSize ) , out var size ) && size is WebSearchContextSize contextSize
7657 ? contextSize : null ;
7758 set
7859 {
79- web . Properties [ "ContextSize" ] = value ;
80- if ( value != null )
81- {
82- web. ContextSize = value . Value switch
83- {
84- WebSearchContextSize . Low => WebSearchToolContextSize . Low ,
85- WebSearchContextSize . High => WebSearchToolContextSize . High ,
86- _ => WebSearchToolContextSize . Medium
87- } ;
88- }
60+ if ( value . HasValue )
61+ web. ContextSize = value . Value ;
62+ else
63+ web. Properties . Remove ( nameof ( WebSearchContextSize ) ) ;
8964 }
9065 }
9166 }
0 commit comments