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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup Label="Version settings">
<MajorVersion>10</MajorVersion>
<MinorVersion>1</MinorVersion>
<PatchVersion>0</PatchVersion>
<PatchVersion>1</PatchVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
Expand Down
2 changes: 1 addition & 1 deletion eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageVersion Include="ModelContextProtocol.Core" Version="0.4.0-preview.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OllamaSharp" Version="5.1.9" />
<PackageVersion Include="OpenAI" Version="2.7.0" />
<PackageVersion Include="OpenAI" Version="2.8.0" />
<PackageVersion Include="Polly" Version="8.4.2" />
<PackageVersion Include="Polly.Core" Version="8.4.2" />
<PackageVersion Include="Polly.Extensions" Version="8.4.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Microsoft.Extensions.AI.Abstractions Release History

## NOT YET RELEASED
## 10.1.1 (NOT YET RELEASED)

- Added `InputCachedTokenCount` and `ReasoningTokenCount` to `UsageDetails`.
- Added constructors to `HostedCodeInterpreterTool`, `HostedFileSearchTool`, `HostedImageGeneratorTool`, `HostedMcpServerTool`,
and `HostedWebSearchTool` that accept a dictionary for `AdditionalProperties`.

## 10.1.0

- Fixed package references for net10.0 asset.
- Added `AIJsonSchemaCreateOptions.ParameterDescriptions`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1918,9 +1918,17 @@
{
"Member": "Microsoft.Extensions.AI.HostedCodeInterpreterTool.HostedCodeInterpreterTool();",
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.AI.HostedCodeInterpreterTool.HostedCodeInterpreterTool(System.Collections.Generic.IReadOnlyDictionary<string, object?>? additionalProperties);",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "override System.Collections.Generic.IReadOnlyDictionary<string, object?> Microsoft.Extensions.AI.HostedCodeInterpreterTool.AdditionalProperties { get; }",
"Stage": "Stable"
},
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.AI.AIContent>? Microsoft.Extensions.AI.HostedCodeInterpreterTool.Inputs { get; set; }",
"Stage": "Stable"
Expand All @@ -1938,9 +1946,17 @@
{
"Member": "Microsoft.Extensions.AI.HostedFileSearchTool.HostedFileSearchTool();",
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.AI.HostedFileSearchTool.HostedFileSearchTool(System.Collections.Generic.IReadOnlyDictionary<string, object?>? additionalProperties);",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "override System.Collections.Generic.IReadOnlyDictionary<string, object?> Microsoft.Extensions.AI.HostedFileSearchTool.AdditionalProperties { get; }",
"Stage": "Stable"
},
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.AI.AIContent>? Microsoft.Extensions.AI.HostedFileSearchTool.Inputs { get; set; }",
"Stage": "Stable"
Expand All @@ -1962,9 +1978,17 @@
{
"Member": "Microsoft.Extensions.AI.HostedWebSearchTool.HostedWebSearchTool();",
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.AI.HostedWebSearchTool.HostedWebSearchTool(System.Collections.Generic.IReadOnlyDictionary<string, object?>? additionalProperties);",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "override System.Collections.Generic.IReadOnlyDictionary<string, object?> Microsoft.Extensions.AI.HostedWebSearchTool.AdditionalProperties { get; }",
"Stage": "Stable"
},
{
"Member": "override string Microsoft.Extensions.AI.HostedWebSearchTool.Name { get; }",
"Stage": "Stable"
Expand Down Expand Up @@ -2236,6 +2260,14 @@
{
"Member": "long? Microsoft.Extensions.AI.UsageDetails.TotalTokenCount { get; set; }",
"Stage": "Stable"
},
{
"Member": "long? Microsoft.Extensions.AI.UsageDetails.CachedInputTokenCount { get; set; }",
"Stage": "Stable"
},
{
"Member": "long? Microsoft.Extensions.AI.UsageDetails.ReasoningTokenCount { get; set; }",
"Stage": "Stable"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ namespace Microsoft.Extensions.AI;
/// </remarks>
public class HostedCodeInterpreterTool : AITool
{
/// <summary>Any additional properties associated with the tool.</summary>
private IReadOnlyDictionary<string, object?>? _additionalProperties;

/// <summary>Initializes a new instance of the <see cref="HostedCodeInterpreterTool"/> class.</summary>
public HostedCodeInterpreterTool()
{
}

/// <summary>Initializes a new instance of the <see cref="HostedCodeInterpreterTool"/> class.</summary>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
public HostedCodeInterpreterTool(IReadOnlyDictionary<string, object?>? additionalProperties)
{
_additionalProperties = additionalProperties;
}

/// <inheritdoc />
public override string Name => "code_interpreter";

/// <inheritdoc />
public override IReadOnlyDictionary<string, object?> AdditionalProperties => _additionalProperties ?? base.AdditionalProperties;

/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the code interpreter tool.</summary>
/// <remarks>
/// Services support different varied kinds of inputs. Most support the IDs of files that are hosted by the service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ namespace Microsoft.Extensions.AI;
/// </remarks>
public class HostedFileSearchTool : AITool
{
/// <summary>Any additional properties associated with the tool.</summary>
private IReadOnlyDictionary<string, object?>? _additionalProperties;

/// <summary>Initializes a new instance of the <see cref="HostedFileSearchTool"/> class.</summary>
public HostedFileSearchTool()
{
}

/// <summary>Initializes a new instance of the <see cref="HostedFileSearchTool"/> class.</summary>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
public HostedFileSearchTool(IReadOnlyDictionary<string, object?>? additionalProperties)
{
_additionalProperties = additionalProperties;
}

/// <inheritdoc />
public override string Name => "file_search";

/// <inheritdoc />
public override IReadOnlyDictionary<string, object?> AdditionalProperties => _additionalProperties ?? base.AdditionalProperties;

/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the file search tool.</summary>
/// <remarks>
/// If no explicit inputs are provided, the service determines what inputs should be searched. Different services
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Extensions.AI;
Expand All @@ -13,13 +14,29 @@ namespace Microsoft.Extensions.AI;
[Experimental("MEAI001")]
public class HostedImageGenerationTool : AITool
{
/// <summary>Any additional properties associated with the tool.</summary>
private IReadOnlyDictionary<string, object?>? _additionalProperties;

/// <summary>
/// Initializes a new instance of the <see cref="HostedImageGenerationTool"/> class with the specified options.
/// </summary>
public HostedImageGenerationTool()
{
}

/// <summary>Initializes a new instance of the <see cref="HostedImageGenerationTool"/> class.</summary>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
public HostedImageGenerationTool(IReadOnlyDictionary<string, object?>? additionalProperties)
{
_additionalProperties = additionalProperties;
}

/// <inheritdoc />
public override string Name => "image_generation";

/// <inheritdoc />
public override IReadOnlyDictionary<string, object?> AdditionalProperties => _additionalProperties ?? base.AdditionalProperties;

/// <summary>
/// Gets or sets the options used to configure image generation.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace Microsoft.Extensions.AI;
[Experimental("MEAI001")]
public class HostedMcpServerTool : AITool
{
/// <summary>Any additional properties associated with the tool.</summary>
private IReadOnlyDictionary<string, object?>? _additionalProperties;

/// <summary>
/// Initializes a new instance of the <see cref="HostedMcpServerTool"/> class.
/// </summary>
Expand All @@ -27,6 +30,20 @@ public HostedMcpServerTool(string serverName, string serverAddress)
ServerAddress = Throw.IfNullOrWhitespace(serverAddress);
}

/// <summary>
/// Initializes a new instance of the <see cref="HostedMcpServerTool"/> class.
/// </summary>
/// <param name="serverName">The name of the remote MCP server.</param>
/// <param name="serverAddress">The address of the remote MCP server. This may be a URL, or in the case of a service providing built-in MCP servers with known names, it can be such a name.</param>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
/// <exception cref="ArgumentNullException"><paramref name="serverName"/> or <paramref name="serverAddress"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="serverName"/> or <paramref name="serverAddress"/> is empty or composed entirely of whitespace.</exception>
public HostedMcpServerTool(string serverName, string serverAddress, IReadOnlyDictionary<string, object?>? additionalProperties)
: this(serverName, serverAddress)
{
_additionalProperties = additionalProperties;
}

/// <summary>
/// Initializes a new instance of the <see cref="HostedMcpServerTool"/> class.
/// </summary>
Expand All @@ -40,6 +57,21 @@ public HostedMcpServerTool(string serverName, Uri serverUrl)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="HostedMcpServerTool"/> class.
/// </summary>
/// <param name="serverName">The name of the remote MCP server.</param>
/// <param name="serverUrl">The URL of the remote MCP server.</param>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
/// <exception cref="ArgumentNullException"><paramref name="serverName"/> or <paramref name="serverUrl"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="serverName"/> is empty or composed entirely of whitespace.</exception>
/// <exception cref="ArgumentException"><paramref name="serverUrl"/> is not an absolute URL.</exception>
public HostedMcpServerTool(string serverName, Uri serverUrl, IReadOnlyDictionary<string, object?>? additionalProperties)
: this(serverName, ValidateUrl(serverUrl))
{
_additionalProperties = additionalProperties;
}

private static string ValidateUrl(Uri serverUrl)
{
_ = Throw.IfNull(serverUrl);
Expand All @@ -55,6 +87,9 @@ private static string ValidateUrl(Uri serverUrl)
/// <inheritdoc />
public override string Name => "mcp";

/// <inheritdoc />
public override IReadOnlyDictionary<string, object?> AdditionalProperties => _additionalProperties ?? base.AdditionalProperties;

/// <summary>
/// Gets the name of the remote MCP server that is used to identify it.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;

namespace Microsoft.Extensions.AI;

/// <summary>Represents a hosted tool that can be specified to an AI service to enable it to perform web searches.</summary>
Expand All @@ -10,11 +12,24 @@ namespace Microsoft.Extensions.AI;
/// </remarks>
public class HostedWebSearchTool : AITool
{
/// <summary>Any additional properties associated with the tool.</summary>
private IReadOnlyDictionary<string, object?>? _additionalProperties;

/// <summary>Initializes a new instance of the <see cref="HostedWebSearchTool"/> class.</summary>
public HostedWebSearchTool()
{
}

/// <summary>Initializes a new instance of the <see cref="HostedWebSearchTool"/> class.</summary>
/// <param name="additionalProperties">Any additional properties associated with the tool.</param>
public HostedWebSearchTool(IReadOnlyDictionary<string, object?>? additionalProperties)
{
_additionalProperties = additionalProperties;
}

/// <inheritdoc />
public override string Name => "web_search";

/// <inheritdoc />
public override IReadOnlyDictionary<string, object?> AdditionalProperties => _additionalProperties ?? base.AdditionalProperties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ public class UsageDetails
/// <summary>Gets or sets the total number of tokens used to produce the response.</summary>
public long? TotalTokenCount { get; set; }

/// <summary>
/// Gets or sets the number of input tokens that were read from a cache.
/// </summary>
/// <remarks>
/// Cached input tokens should be counted as part of <see cref="InputTokenCount"/>.
/// </remarks>
public long? CachedInputTokenCount { get; set; }

/// <summary>
/// Gets or sets the number of "reasoning" / "thinking" tokens used internally
/// by the model.
/// </summary>
/// <remarks>
/// Reasoning tokens should be counted as part of <see cref="OutputTokenCount"/>.
/// </remarks>
public long? ReasoningTokenCount { get; set; }

/// <summary>Gets or sets a dictionary of additional usage counts.</summary>
/// <remarks>
/// All values set here are assumed to be summable. For example, when middleware makes multiple calls to an underlying
Expand All @@ -38,6 +55,8 @@ public void Add(UsageDetails usage)
InputTokenCount = NullableSum(InputTokenCount, usage.InputTokenCount);
OutputTokenCount = NullableSum(OutputTokenCount, usage.OutputTokenCount);
TotalTokenCount = NullableSum(TotalTokenCount, usage.TotalTokenCount);
CachedInputTokenCount = NullableSum(CachedInputTokenCount, usage.CachedInputTokenCount);
ReasoningTokenCount = NullableSum(ReasoningTokenCount, usage.ReasoningTokenCount);

if (usage.AdditionalCounts is { } countsToAdd)
{
Expand Down Expand Up @@ -80,6 +99,16 @@ internal string DebuggerDisplay
parts.Add($"{nameof(TotalTokenCount)} = {total}");
}

if (CachedInputTokenCount is { } cached)
{
parts.Add($"{nameof(CachedInputTokenCount)} = {cached}");
}

if (ReasoningTokenCount is { } reasoning)
{
parts.Add($"{nameof(ReasoningTokenCount)} = {reasoning}");
}

if (AdditionalCounts is { } additionalCounts)
{
foreach (var entry in additionalCounts)
Expand Down
12 changes: 11 additions & 1 deletion src/Libraries/Microsoft.Extensions.AI.OpenAI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Microsoft.Extensions.AI.OpenAI Release History

## NOT YET RELEASED
## 10.1.1-preview.1.? (NOT YET RELEASED)

- Updated to depend on OpenAI 2.8.0.
- Updated public API signatures in `OpenAIClientExtensions` and `MicrosoftExtensionsAIResponsesExtensions` to match the corresponding breaking changes in OpenAI's Responses APIs.
- Updated to accommodate the additions in `Microsoft.Extensions.AI.Abstractions`.
- Updated the OpenAI Responses and Chat Completion `IChatClient`s to populate `UsageDetails`'s `InputCachedTokenCount` and `ReasoningTokenCount`.
- Updated handling of `HostedWebSearchTool`, `HostedFileSearchTool`, and `HostedImageGenerationTool` to pull OpenAI-specific
options from `AdditionalProperties`.

## 10.1.0-preview.1.25608.1

- Fixed package references for net10.0 asset.
- Updated to accommodate the additions in `Microsoft.Extensions.AI.Abstractions`.
- Updated the OpenAI Responses `IChatClient` to ensure all `ResponseItem`s are yielded in `AIContent`.
- Added workaround to the OpenAI Responses `IChatClient` for OpenAI service sometimes sending error data in a manner different from how it's documented.

## 10.0.1-preview.1.25571.5

Expand Down
Loading
Loading