Skip to content

Commit b5b804f

Browse files
committed
Bump AI dependencies
Adapt renamed types in OpenAI 2.2.0 stable.
1 parent 110711f commit b5b804f

File tree

6 files changed

+28
-50
lines changed

6 files changed

+28
-50
lines changed

src/AI.Tests/AI.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="coverlet.collector" Version="6.0.4" />
12-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.6.0-preview.1.25310.2" />
12+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.7.0-preview.1.25356.2" />
1313
<PackageReference Include="xunit" Version="2.9.3" />
1414
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1" PrivateAssets="all" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />

src/AI.Tests/OpenAITests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public async Task WebSearchCountryHighContext()
117117
Assert.NotEmpty(content.OutputTextAnnotations);
118118
Assert.Contains(content.OutputTextAnnotations,
119119
x => x.Kind == ResponseMessageAnnotationKind.UriCitation &&
120-
x.UriCitationUri.StartsWith("https://catedralaltapatagonia.com/tarifas/"));
120+
x.UriCitationUri.AbsoluteUri.StartsWith("https://catedralaltapatagonia.com/tarifas/"));
121121

122122
}
123123
}

src/AI/AI.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
<LangVersion>Preview</LangVersion>
66
<PackageId>Devlooped.Extensions.AI</PackageId>
77
<Description>Extensions for Microsoft.Extensions.AI</Description>
8+
<NoWarn>$(NoWarn);OPENAI001</NoWarn>
89
</PropertyGroup>
910

1011
<ItemGroup>
1112
<PackageReference Include="NuGetizer" Version="1.2.4" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.6.0" />
13-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.6.0-preview.1.25310.2" />
13+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.7.0" />
14+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.7.0-preview.1.25356.2" />
1415
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.6" />
15-
<PackageReference Include="OpenAI" Version="2.2.0-beta.4" />
16+
<PackageReference Include="OpenAI" Version="2.2.0" />
1617
<PackageReference Include="Spectre.Console" Version="0.50.0" />
1718
<PackageReference Include="Spectre.Console.Json" Version="0.50.0" />
1819
</ItemGroup>

src/AI/OpenAI/OpenAIChatClient.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,22 @@ IChatClient GetChatClient(string modelId) => clients.GetOrAdd(modelId, model
5050
{
5151
options.RawRepresentationFactory = _ => new ResponseCreationOptions
5252
{
53-
ReasoningOptions = new ResponseReasoningOptions(effort switch
53+
ReasoningOptions = new ResponseReasoningOptions()
5454
{
55-
ReasoningEffort.High => ResponseReasoningEffortLevel.High,
56-
ReasoningEffort.Medium => ResponseReasoningEffortLevel.Medium,
57-
_ => ResponseReasoningEffortLevel.Low
58-
})
55+
ReasoningEffortLevel = effort switch
56+
{
57+
ReasoningEffort.High => ResponseReasoningEffortLevel.High,
58+
ReasoningEffort.Medium => ResponseReasoningEffortLevel.Medium,
59+
_ => ResponseReasoningEffortLevel.Low
60+
},
61+
}
5962
};
6063
}
6164

6265
return options;
6366
}
6467

65-
void IDisposable.Dispose() { }
68+
void IDisposable.Dispose() => GC.SuppressFinalize(this);
6669

6770
public object? GetService(Type serviceType, object? serviceKey = null) => null;
6871

src/AI/OpenAI/WebSearchToolExtensions.cs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,6 @@
22

33
namespace 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-
245
public 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
}

src/AI/WebSearchTool.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Devlooped.Extensions.AI;
99
public class WebSearchTool : HostedWebSearchTool
1010
{
1111
Dictionary<string, object?> additionalProperties;
12-
string? region;
1312

1413
/// <summary>
1514
/// Initializes a new instance of the <see cref="WebSearchTool"/> class with the specified country.
@@ -20,7 +19,7 @@ public WebSearchTool(string country)
2019
Country = country;
2120
additionalProperties = new Dictionary<string, object?>
2221
{
23-
{ nameof(WebSearchToolLocation), WebSearchToolLocation.CreateApproximateLocation(country) }
22+
{ nameof(WebSearchUserLocation), WebSearchUserLocation.CreateApproximateLocation(country) }
2423
};
2524
}
2625

@@ -29,14 +28,14 @@ public WebSearchTool(string country)
2928
/// </summary>
3029
public string Country { get; }
3130

32-
internal WebSearchToolLocation Location
31+
internal WebSearchUserLocation Location
3332
{
34-
set => additionalProperties[nameof(WebSearchToolLocation)] = value;
33+
set => additionalProperties[nameof(WebSearchUserLocation)] = value;
3534
}
3635

37-
internal WebSearchToolContextSize ContextSize
36+
internal WebSearchContextSize ContextSize
3837
{
39-
set => additionalProperties[nameof(WebSearchToolContextSize)] = value;
38+
set => additionalProperties[nameof(WebSearchContextSize)] = value;
4039
}
4140

4241
internal IDictionary<string, object?> Properties => additionalProperties;

0 commit comments

Comments
 (0)