Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AI.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="src/AI.CodeAnalysis/AI.CodeAnalysis.csproj" />
<Project Path="src/AI.Tests/AI.Tests.csproj" />
<Project Path="src/AI/AI.csproj" />
<Project Path="src/Agents/Agents.csproj" Id="90827430-b415-47d6-aac9-2dbe4911b348" />
<Project Path="src/Extensions.CodeAnalysis/Extensions.CodeAnalysis.csproj" />
<Project Path="src/Extensions/Extensions.csproj" />
<Project Path="src/Tests/Tests.csproj" />
</Solution>
28 changes: 28 additions & 0 deletions src/Agents/Agents.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0</TargetFrameworks>
<LangVersion>Preview</LangVersion>
<PackageId>Devlooped.Agents.AI</PackageId>
<Description>Extensions for Microsoft.Agents.AI</Description>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>OSMFEULA.txt</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
<PackageReference Include="NuGetizer" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.251009.1" />
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.251009.1" />
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.251009.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\osmfeula.txt" Link="osmfeula.txt" PackagePath="OSMFEULA.txt" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/Directory.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<RestoreSources>https://api.nuget.org/v3/index.json;https://pkg.kzu.app/index.json</RestoreSources>
<PackageProjectUrl>https://github.com/devlooped/Extensions.AI</PackageProjectUrl>

<SuppressNETCoreSdkPreviewMessage>false</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/AI/AI.csproj → src/Extensions/Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<LangVersion>Preview</LangVersion>
<NoWarn>$(NoWarn);OPENAI001</NoWarn>
<AssemblyName>Devlooped.Extensions.AI</AssemblyName>
<PackageId>Devlooped.Extensions.AI</PackageId>
<Description>Extensions for Microsoft.Extensions.AI</Description>
<NoWarn>$(NoWarn);OPENAI001</NoWarn>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>OSMFEULA.txt</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand All @@ -16,16 +17,15 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
<PackageReference Include="NuGetizer" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.8.0-preview.1.25412.6" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
<PackageReference Include="OpenAI" Version="2.3.0" />
<PackageReference Include="Spectre.Console" Version="0.51.1" />
<PackageReference Include="Spectre.Console.Json" Version="0.51.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AI.CodeAnalysis\AI.CodeAnalysis.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Extensions.CodeAnalysis\Extensions.CodeAnalysis.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public string? Region
set
{
web.Properties["Region"] = value;
web.Location = WebSearchUserLocation.CreateApproximateLocation(web.Country, value, web.City, web.TimeZone);
web.Location = WebSearchToolLocation.CreateApproximateLocation(web.Country, value, web.City, web.TimeZone);
}
}

Expand All @@ -30,7 +30,7 @@ public string? City
set
{
web.Properties["City"] = value;
web.Location = WebSearchUserLocation.CreateApproximateLocation(web.Country, web.Region, value, web.TimeZone);
web.Location = WebSearchToolLocation.CreateApproximateLocation(web.Country, web.Region, value, web.TimeZone);
}
}

Expand All @@ -44,23 +44,23 @@ public string? TimeZone
set
{
web.Properties["TimeZone"] = value;
web.Location = WebSearchUserLocation.CreateApproximateLocation(web.Country, web.Region, web.City, value);
web.Location = WebSearchToolLocation.CreateApproximateLocation(web.Country, web.Region, web.City, value);
}
}

/// <summary>
/// Controls how much context is retrieved from the web to help the tool formulate a response.
/// </summary>
public WebSearchContextSize? ContextSize
public WebSearchToolContextSize? ContextSize
{
get => web.Properties.TryGetValue(nameof(WebSearchContextSize), out var size) && size is WebSearchContextSize contextSize
get => web.Properties.TryGetValue(nameof(WebSearchToolContextSize), out var size) && size is WebSearchToolContextSize contextSize
? contextSize : null;
set
{
if (value.HasValue)
web.ContextSize = value.Value;
else
web.Properties.Remove(nameof(WebSearchContextSize));
web.Properties.Remove(nameof(WebSearchToolContextSize));
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/AI/WebSearchTool.cs → src/Extensions/WebSearchTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public WebSearchTool(string country)
Country = country;
additionalProperties = new Dictionary<string, object?>
{
{ nameof(WebSearchUserLocation), WebSearchUserLocation.CreateApproximateLocation(country) }
{ nameof(WebSearchToolLocation), WebSearchToolLocation.CreateApproximateLocation(country) }
};
}

Expand All @@ -28,14 +28,14 @@ public WebSearchTool(string country)
/// </summary>
public string Country { get; }

internal WebSearchUserLocation Location
internal WebSearchToolLocation Location
{
set => additionalProperties[nameof(WebSearchUserLocation)] = value;
set => additionalProperties[nameof(WebSearchToolLocation)] = value;
}

internal WebSearchContextSize ContextSize
internal WebSearchToolContextSize ContextSize
{
set => additionalProperties[nameof(WebSearchContextSize)] = value;
set => additionalProperties[nameof(WebSearchToolContextSize)] = value;
}

internal IDictionary<string, object?> Properties => additionalProperties;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions src/AI.Tests/OpenAITests.cs → src/Tests/OpenAITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public async Task WebSearchCountryHighContext()
{
Region = "Bariloche",
TimeZone = "America/Argentina/Buenos_Aires",
ContextSize = WebSearchContextSize.High
ContextSize = WebSearchToolContextSize.High
}]
};

Expand All @@ -255,9 +255,8 @@ public async Task WebSearchCountryHighContext()

var content = Assert.Single(assistant.Content);
Assert.NotEmpty(content.OutputTextAnnotations);
Assert.Contains(content.OutputTextAnnotations,
x => x.Kind == ResponseMessageAnnotationKind.UriCitation &&
x.UriCitationUri.AbsoluteUri.StartsWith("https://catedralaltapatagonia.com/tarifas/"));

//Assert.Contains(content.OutputTextAnnotations,
// x => x.Kind == ResponseMessageAnnotationKind.UriCitation &&
// x.UriCitationUri.AbsoluteUri.StartsWith("https://catedralaltapatagonia.com/tarifas/"));
}
}
31 changes: 20 additions & 11 deletions src/AI.Tests/RetrievalTests.cs → src/Tests/RetrievalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,41 @@ public class RetrievalTests(ITestOutputHelper output)
public async Task CanRetrieveContent(string model, string question, bool empty = false)
{
var client = new global::OpenAI.OpenAIClient(Configuration["OPENAI_API_KEY"]);
var store = client.GetVectorStoreClient().CreateVectorStore(true);
var store = client.GetVectorStoreClient().CreateVectorStore();
try
{
var file = client.GetOpenAIFileClient().UploadFile("Content/LNS0004592.md", global::OpenAI.Files.FileUploadPurpose.Assistants);
try
{
client.GetVectorStoreClient().AddFileToVectorStore(store.VectorStoreId, file.Value.Id, true);
client.GetVectorStoreClient().AddFileToVectorStore(store.Value.Id, file.Value.Id);

var responses = new OpenAIResponseClient(model, Configuration["OPENAI_API_KEY"]);

var chat = responses.AsIChatClient(
ResponseTool.CreateFileSearchTool([store.VectorStoreId]))
var options = new ChatOptions();
options.Tools ??= [];
options.Tools.Add(new HostedFileSearchTool
{
Inputs =
[
new HostedVectorStoreContent(store.Value.Id),
],
MaximumResultCount = 10,
});

var chat = responses.AsIChatClient()
.AsBuilder()
.UseLogging(output.AsLoggerFactory())
.Use((messages, options, next, cancellationToken) =>
{

return next.Invoke(messages, options, cancellationToken);
})
//.Use((messages, options, next, cancellationToken) =>
//{
// return next.Invoke(messages, options, cancellationToken);
//})
.Build();

var response = await chat.GetResponseAsync(
[
new ChatMessage(ChatRole.System, "Use file search tool to respond, exclusively. If no content was found, respond just with the string 'N/A' and nothing else."),
new ChatMessage(ChatRole.User, question),
]);
], options);

output.WriteLine(response.Text);
if (empty)
Expand All @@ -52,7 +61,7 @@ public async Task CanRetrieveContent(string model, string question, bool empty =
}
finally
{
client.GetVectorStoreClient().DeleteVectorStore(store.VectorStoreId);
client.GetVectorStoreClient().DeleteVectorStore(store.Value.Id);
}
}
}
5 changes: 3 additions & 2 deletions src/AI.Tests/AI.Tests.csproj → src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AI.CodeAnalysis\AI.CodeAnalysis.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\AI\AI.csproj" />
<ProjectReference Include="..\Agents\Agents.csproj" />
<ProjectReference Include="..\Extensions.CodeAnalysis\Extensions.CodeAnalysis.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Extensions\Extensions.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
File renamed without changes.