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
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,10 @@
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.AI.AIContent>? Microsoft.Extensions.AI.HostedCodeInterpreterTool.Inputs { get; set; }",
"Stage": "Stable"
},
{
"Member": "override string Microsoft.Extensions.AI.HostedCodeInterpreterTool.Name { get; }",
"Stage": "Stable"
}
]
},
Expand All @@ -1972,6 +1976,10 @@
{
"Member": "int? Microsoft.Extensions.AI.HostedFileSearchTool.MaximumResultCount { get; set; }",
"Stage": "Stable"
},
{
"Member": "override string Microsoft.Extensions.AI.HostedFileSearchTool.Name { get; }",
"Stage": "Stable"
}
]
},
Expand All @@ -1983,6 +1991,12 @@
"Member": "Microsoft.Extensions.AI.HostedWebSearchTool.HostedWebSearchTool();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "override string Microsoft.Extensions.AI.HostedWebSearchTool.Name { get; }",
"Stage": "Stable"
}
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public HostedCodeInterpreterTool()
{
}

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

/// <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 @@ -17,6 +17,9 @@ public HostedFileSearchTool()
{
}

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

/// <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
Expand Up @@ -39,6 +39,9 @@ public HostedMcpServerTool(string serverName, Uri url)
Url = Throw.IfNull(url);
}

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

/// <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
Expand Up @@ -14,4 +14,7 @@ public class HostedWebSearchTool : AITool
public HostedWebSearchTool()
{
}

/// <inheritdoc />
public override string Name => "web_search";
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ internal static string SerializeChatMessages(IEnumerable<ChatMessage> messages,
m.Parts.Add(new OtelGenericPart { Content = tc.Text });
break;

case TextReasoningContent trc when !string.IsNullOrWhiteSpace(trc.Text):
m.Parts.Add(new OtelGenericPart { Type = "reasoning", Content = trc.Text });
break;

case FunctionCallContent fcc:
m.Parts.Add(new OtelToolCallRequestPart
{
Expand All @@ -268,10 +272,6 @@ internal static string SerializeChatMessages(IEnumerable<ChatMessage> messages,

// These are non-standard and are using the "generic" non-text part that provides an extensibility mechanism:

case TextReasoningContent trc when !string.IsNullOrWhiteSpace(trc.Text):
m.Parts.Add(new OtelGenericPart { Type = "reasoning", Content = trc.Text });
break;

case UriContent uc:
m.Parts.Add(new OtelGenericPart { Type = "image", Content = uc.Uri.ToString() });
break;
Expand Down Expand Up @@ -396,16 +396,20 @@ internal static string SerializeChatMessages(IEnumerable<ChatMessage> messages,

if (EnableSensitiveData)
{
if (options.Tools?.Any(t => t is AIFunctionDeclaration) is true)
if (options.Tools is { Count: > 0 })
{
_ = activity.AddTag(
OpenTelemetryConsts.GenAI.Tool.Definitions,
JsonSerializer.Serialize(options.Tools.OfType<AIFunctionDeclaration>().Select(t => new OtelFunction
OpenTelemetryConsts.GenAI.Tool.Definitions,
JsonSerializer.Serialize(options.Tools.Select(t => t switch
{
_ when t.GetService<AIFunctionDeclaration>() is { } af => new OtelFunction
{
Name = t.Name,
Description = t.Description,
Parameters = t.JsonSchema,
}), OtelContext.Default.IEnumerableOtelFunction));
Name = af.Name,
Description = af.Description,
Parameters = af.JsonSchema,
},
_ => new OtelFunction { Type = t.Name },
}), OtelContext.Default.IEnumerableOtelFunction));
}

// Log all additional request options as raw values on the span.
Expand Down Expand Up @@ -601,7 +605,7 @@ private sealed class OtelFunction
public string Type { get; set; } = "function";
public string? Name { get; set; }
public string? Description { get; set; }
public JsonElement Parameters { get; set; }
public JsonElement? Parameters { get; set; }
}

private static readonly JsonSerializerOptions _defaultOptions = CreateDefaultOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class HostedCodeInterpreterToolTests
public void Constructor_Roundtrips()
{
var tool = new HostedCodeInterpreterTool();
Assert.Equal(nameof(HostedCodeInterpreterTool), tool.Name);
Assert.Equal("code_interpreter", tool.Name);
Assert.Empty(tool.Description);
Assert.Empty(tool.AdditionalProperties);
Assert.Null(tool.Inputs);
Assert.Equal(nameof(HostedCodeInterpreterTool), tool.ToString());
Assert.Equal(tool.Name, tool.ToString());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class HostedFileSearchToolTests
public void Constructor_Roundtrips()
{
var tool = new HostedFileSearchTool();
Assert.Equal(nameof(HostedFileSearchTool), tool.Name);
Assert.Equal("file_search", tool.Name);
Assert.Empty(tool.Description);
Assert.Empty(tool.AdditionalProperties);
Assert.Null(tool.Inputs);
Assert.Null(tool.MaximumResultCount);
Assert.Equal(nameof(HostedFileSearchTool), tool.ToString());
Assert.Equal(tool.Name, tool.ToString());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void Constructor_Roundtrips()

Assert.Empty(tool.AdditionalProperties);
Assert.Empty(tool.Description);
Assert.Equal(nameof(HostedMcpServerTool), tool.Name);
Assert.Equal("mcp", tool.Name);
Assert.Equal(tool.Name, tool.ToString());

Assert.Equal("serverName", tool.ServerName);
Assert.Equal("https://localhost/", tool.Url.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class HostedWebSearchToolTests
public void Constructor_Roundtrips()
{
var tool = new HostedWebSearchTool();
Assert.Equal(nameof(HostedWebSearchTool), tool.Name);
Assert.Equal("web_search", tool.Name);
Assert.Empty(tool.Description);
Assert.Empty(tool.AdditionalProperties);
Assert.Equal(nameof(HostedWebSearchTool), tool.ToString());
Assert.Equal(tool.Name, tool.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync(
[
AIFunctionFactory.Create((string personName) => personName, "GetPersonAge", "Gets the age of a person by name."),
new HostedWebSearchTool(),
new HostedFileSearchTool(),
new HostedCodeInterpreterTool(),
new HostedMcpServerTool("myAwesomeServer", "http://localhost:1234/somewhere"),
AIFunctionFactory.Create((string location) => "", "GetCurrentWeather", "Gets the current weather for a location.").AsDeclarationOnly(),
],
};
Expand Down Expand Up @@ -288,6 +291,18 @@ async static IAsyncEnumerable<ChatResponseUpdate> CallbackAsync(
]
}
},
{
"type": "web_search"
},
{
"type": "file_search"
},
{
"type": "code_interpreter"
},
{
"type": "mcp"
},
{
"type": "function",
"name": "GetCurrentWeather",
Expand Down
Loading