Skip to content

Commit f76a4b0

Browse files
Merge branch 'microsoft:main' into update-modelid
2 parents a8cf41e + e4874bb commit f76a4b0

179 files changed

Lines changed: 3428 additions & 2568 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dotnet/nuget/nuget-package.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IsPackable>true</IsPackable>
1111

1212
<!-- Package validation. Baseline Version should be lower than current version. -->
13-
<PackageValidationBaselineVersion>1.0.1</PackageValidationBaselineVersion>
13+
<PackageValidationBaselineVersion>1.1.0</PackageValidationBaselineVersion>
1414
<!-- Validate assembly attributes only for Publish builds -->
1515
<NoWarn Condition="'$(Configuration)' != 'Publish'">$(NoWarn);CP0003</NoWarn>
1616
<!-- Do not validate reference assemblies -->

‎dotnet/samples/KernelSyntaxExamples/Example52_CustomOpenAIClient.cs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99
using Azure.Core.Pipeline;
1010
using Microsoft.SemanticKernel;
1111
using RepoUtils;
12+
using Xunit;
13+
using Xunit.Abstractions;
1214

13-
public static class Example52_CustomOpenAIClient
15+
namespace Examples;
16+
17+
public sealed class Example52_CustomOpenAIClient : BaseTest
1418
{
15-
public static async Task RunAsync()
19+
[Fact]
20+
public async Task RunAsync()
1621
{
17-
Console.WriteLine("======== Using a custom OpenAI client ========");
22+
this.WriteLine("======== Using a custom OpenAI client ========");
1823

1924
string endpoint = TestConfiguration.AzureOpenAI.Endpoint;
2025
string deploymentName = TestConfiguration.AzureOpenAI.ChatDeploymentName;
2126
string apiKey = TestConfiguration.AzureOpenAI.ApiKey;
2227

2328
if (endpoint is null || deploymentName is null || apiKey is null)
2429
{
25-
Console.WriteLine("Azure OpenAI credentials not found. Skipping example.");
30+
this.WriteLine("Azure OpenAI credentials not found. Skipping example.");
2631
return;
2732
}
2833

@@ -51,8 +56,10 @@ public static async Task RunAsync()
5156
kernel.Plugins["FunPlugin"]["Excuses"],
5257
new() { ["input"] = "I have no homework" }
5358
);
54-
Console.WriteLine(result.GetValue<string>());
59+
this.WriteLine(result.GetValue<string>());
5560

5661
httpClient.Dispose();
5762
}
63+
64+
public Example52_CustomOpenAIClient(ITestOutputHelper output) : base(output) { }
5865
}

‎dotnet/samples/KernelSyntaxExamples/Example58_ConfigureExecutionSettings.cs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3-
using System;
43
using System.Text.Json;
54
using System.Threading.Tasks;
65
using Microsoft.SemanticKernel;
76
using Microsoft.SemanticKernel.Connectors.OpenAI;
7+
using Xunit;
88
using Xunit.Abstractions;
99

1010
namespace Examples;
1111

12-
public class Example58_ConfigureExecutionSettings : BaseTest
12+
public sealed class Example58_ConfigureExecutionSettings : BaseTest
1313
{
1414
/// <summary>
1515
/// Show how to configure model execution settings
1616
/// </summary>
17-
public static async Task RunAsync()
17+
[Fact]
18+
public async Task RunAsync()
1819
{
19-
Console.WriteLine("======== Example58_ConfigureExecutionSettings ========");
20+
this.WriteLine("======== Example58_ConfigureExecutionSettings ========");
2021

2122
string serviceId = TestConfiguration.AzureOpenAI.ServiceId;
2223
string apiKey = TestConfiguration.AzureOpenAI.ApiKey;
@@ -26,7 +27,7 @@ public static async Task RunAsync()
2627

2728
if (apiKey == null || chatDeploymentName == null || endpoint == null)
2829
{
29-
Console.WriteLine("AzureOpenAI endpoint, apiKey, or deploymentName not found. Skipping example.");
30+
this.WriteLine("AzureOpenAI endpoint, apiKey, or deploymentName not found. Skipping example.");
3031
return;
3132
}
3233

@@ -50,7 +51,7 @@ public static async Task RunAsync()
5051
MaxTokens = 60,
5152
Temperature = 0.7
5253
}));
53-
Console.WriteLine(result.GetValue<string>());
54+
this.WriteLine(result.GetValue<string>());
5455

5556
// Option 2:
5657
// Load prompt template configuration including the execution settings from a JSON payload
@@ -74,7 +75,7 @@ public static async Task RunAsync()
7475
var func = kernel.CreateFunctionFromPrompt(promptConfig);
7576

7677
result = await kernel.InvokeAsync(func);
77-
Console.WriteLine(result.GetValue<string>());
78+
this.WriteLine(result.GetValue<string>());
7879

7980
/* OUTPUT (using gpt4):
8081
Hello! As an AI language model, I can help you with a variety of tasks, such as:

‎dotnet/samples/KernelSyntaxExamples/Example70_Agents.cs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3-
using System;
43
using System.Linq;
54
using System.Threading.Tasks;
65
using Microsoft.SemanticKernel;
@@ -153,15 +152,15 @@ private async Task ChatAsync(
153152
try
154153
{
155154
// Display agent identifier.
156-
Console.WriteLine($"[{agent.Id}]");
155+
this.WriteLine($"[{agent.Id}]");
157156

158157
// Process each user message and agent response.
159158
foreach (var response in messages.Select(m => thread.InvokeAsync(agent, m, arguments)))
160159
{
161160
await foreach (var message in response)
162161
{
163-
Console.WriteLine($"[{message.Id}]");
164-
Console.WriteLine($"# {message.Role}: {message.Content}");
162+
this.WriteLine($"[{message.Id}]");
163+
this.WriteLine($"# {message.Role}: {message.Content}");
165164
}
166165
}
167166
}

‎dotnet/samples/KernelSyntaxExamples/Example75_AgentTools.cs‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
using System.Linq;
66
using System.Threading.Tasks;
77
using Microsoft.SemanticKernel.Experimental.Agents;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace Examples;
812

913
// ReSharper disable once InconsistentNaming
1014
/// <summary>
1115
/// Showcase usage of code_interpreter and retrieval tools.
1216
/// </summary>
13-
public static class Example75_AgentTools
17+
public sealed class Example75_AgentTools : BaseTest
1418
{
1519
/// <summary>
1620
/// Specific model is required that supports agents and parallel function calling.
@@ -19,18 +23,19 @@ public static class Example75_AgentTools
1923
private const string OpenAIFunctionEnabledModel = "gpt-4-1106-preview";
2024

2125
// Track agents for clean-up
22-
private static readonly List<IAgent> s_agents = new();
26+
private readonly List<IAgent> _agents = new();
2327

2428
/// <summary>
2529
/// Show how to utilize code_interpreter and retrieval tools.
2630
/// </summary>
27-
public static async Task RunAsync()
31+
[Fact]
32+
public async Task RunAsync()
2833
{
29-
Console.WriteLine("======== Example75_AgentTools ========");
34+
this.WriteLine("======== Example75_AgentTools ========");
3035

3136
if (TestConfiguration.OpenAI.ApiKey == null)
3237
{
33-
Console.WriteLine("OpenAI apiKey not found. Skipping example.");
38+
this.WriteLine("OpenAI apiKey not found. Skipping example.");
3439
return;
3540
}
3641

@@ -41,9 +46,9 @@ public static async Task RunAsync()
4146
await RunRetrievalToolAsync();
4247
}
4348

44-
private static async Task RunCodeInterpreterToolAsync()
49+
private async Task RunCodeInterpreterToolAsync()
4550
{
46-
Console.WriteLine("======== Run:CodeInterpreterTool ========");
51+
this.WriteLine("======== Run:CodeInterpreterTool ========");
4752

4853
var builder =
4954
new AgentBuilder()
@@ -68,13 +73,13 @@ await ChatAsync(
6873
}
6974
finally
7075
{
71-
await Task.WhenAll(s_agents.Select(a => a.DeleteAsync()));
76+
await Task.WhenAll(this._agents.Select(a => a.DeleteAsync()));
7277
}
7378
}
7479

75-
private static async Task RunRetrievalToolAsync()
80+
private async Task RunRetrievalToolAsync()
7681
{
77-
Console.WriteLine("======== Run:RunRetrievalTool ========");
82+
this.WriteLine("======== Run:RunRetrievalTool ========");
7883

7984
// REQUIRED:
8085
//
@@ -111,29 +116,29 @@ await ChatAsync(
111116
}
112117
finally
113118
{
114-
await Task.WhenAll(s_agents.Select(a => a.DeleteAsync()));
119+
await Task.WhenAll(this._agents.Select(a => a.DeleteAsync()));
115120
}
116121
}
117122

118123
/// <summary>
119124
/// Common chat loop used for: RunCodeInterpreterToolAsync and RunRetrievalToolAsync.
120125
/// Processes each question for both "default" and "enabled" agents.
121126
/// </summary>
122-
private static async Task ChatAsync(
127+
private async Task ChatAsync(
123128
IAgent defaultAgent,
124129
IAgent enabledAgent,
125130
params string[] questions)
126131
{
127132
foreach (var question in questions)
128133
{
129-
Console.WriteLine("\nDEFAULT AGENT:");
134+
this.WriteLine("\nDEFAULT AGENT:");
130135
await InvokeAgentAsync(defaultAgent, question);
131136

132-
Console.WriteLine("\nTOOL ENABLED AGENT:");
137+
this.WriteLine("\nTOOL ENABLED AGENT:");
133138
await InvokeAgentAsync(enabledAgent, question);
134139
}
135140

136-
static async Task InvokeAgentAsync(IAgent agent, string question)
141+
async Task InvokeAgentAsync(IAgent agent, string question)
137142
{
138143
await foreach (var message in agent.InvokeAsync(question))
139144
{
@@ -143,26 +148,28 @@ static async Task InvokeAgentAsync(IAgent agent, string question)
143148
content = content.Replace(annotation.Label, string.Empty, StringComparison.Ordinal);
144149
}
145150

146-
Console.WriteLine($"# {message.Role}: {content}");
151+
this.WriteLine($"# {message.Role}: {content}");
147152

148153
if (message.Annotations.Count > 0)
149154
{
150-
Console.WriteLine("\n# files:");
155+
this.WriteLine("\n# files:");
151156
foreach (var annotation in message.Annotations)
152157
{
153-
Console.WriteLine($"* {annotation.FileId}");
158+
this.WriteLine($"* {annotation.FileId}");
154159
}
155160
}
156161
}
157162

158-
Console.WriteLine();
163+
this.WriteLine();
159164
}
160165
}
161166

162-
private static IAgent Track(IAgent agent)
167+
private IAgent Track(IAgent agent)
163168
{
164-
s_agents.Add(agent);
169+
this._agents.Add(agent);
165170

166171
return agent;
167172
}
173+
174+
public Example75_AgentTools(ITestOutputHelper output) : base(output) { }
168175
}

‎dotnet/samples/KernelSyntaxExamples/Getting_Started/Step1_Create_Kernel.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public async Task RunAsync()
4747
// Example 4. Invoke the kernel with a templated prompt and execution settings
4848
arguments = new(new OpenAIPromptExecutionSettings { MaxTokens = 500, Temperature = 0.5 }) { { "topic", "dogs" } };
4949
WriteLine(await kernel.InvokePromptAsync("Tell me a story about {{$topic}}", arguments));
50+
51+
// Example 5. Invoke the kernel with a templated prompt and execution settings configured to return JSON
52+
#pragma warning disable SKEXP0013
53+
arguments = new(new OpenAIPromptExecutionSettings { ResponseFormat = "json_object" }) { { "topic", "chocolate" } };
54+
WriteLine(await kernel.InvokePromptAsync("Create a recipe for a {{$topic}} cake in JSON format", arguments));
5055
}
5156

5257
public Step1_Create_Kernel(ITestOutputHelper output) : base(output)

‎dotnet/src/Functions/Functions.OpenApi/Extensions/RestApiOperationExtensions.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private static List<RestApiOperationParameter> GetParametersFromPayloadMetadata(
179179
expand: false,
180180
RestApiOperationParameterLocation.Body,
181181
RestApiOperationParameterStyle.Simple,
182+
defaultValue: property.DefaultValue,
182183
description: property.Description,
183184
schema: property.Schema));
184185
}

‎dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperationParameter.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public sealed class RestApiOperationParameter
5050
/// <summary>
5151
/// The default value.
5252
/// </summary>
53-
public string? DefaultValue { get; }
53+
public object? DefaultValue { get; }
5454

5555
/// <summary>
5656
/// Specifies whether arrays and objects should generate separate parameters for each array item or object property.
@@ -83,7 +83,7 @@ public RestApiOperationParameter(
8383
RestApiOperationParameterLocation location,
8484
RestApiOperationParameterStyle? style = null,
8585
string? arrayItemType = null,
86-
string? defaultValue = null,
86+
object? defaultValue = null,
8787
string? description = null,
8888
KernelJsonSchema? schema = null)
8989
{

‎dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperationPayloadProperty.cs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,37 @@ public sealed class RestApiOperationPayloadProperty
3939
/// </summary>
4040
public KernelJsonSchema? Schema { get; }
4141

42+
/// <summary>
43+
/// The default value.
44+
/// </summary>
45+
public object? DefaultValue { get; }
46+
4247
/// <summary>
4348
/// Creates an instance of a <see cref="RestApiOperationPayloadProperty"/> class.
4449
/// </summary>
45-
/// <param name="name">Property name.</param>
46-
/// <param name="type">Property type.</param>
47-
/// <param name="isRequired">Flag specifying if the property is required or not.</param>
48-
/// <param name="properties">Properties.</param>
49-
/// <param name="description">Property description.</param>
50+
/// <param name="name">The name of the property.</param>
51+
/// <param name="type">The type of the property.</param>
52+
/// <param name="isRequired">A flag specifying if the property is required or not.</param>
53+
/// <param name="properties">A list of properties for the payload property.</param>
54+
/// <param name="description">A description of the property.</param>
5055
/// <param name="schema">The schema of the payload property.</param>
56+
/// <param name="defaultValue">The default value of the property.</param>
57+
/// <returns>Returns a new instance of the <see cref="RestApiOperationPayloadProperty"/> class.</returns>
5158
public RestApiOperationPayloadProperty(
5259
string name,
5360
string type,
5461
bool isRequired,
5562
IList<RestApiOperationPayloadProperty> properties,
5663
string? description = null,
57-
KernelJsonSchema? schema = null)
64+
KernelJsonSchema? schema = null,
65+
object? defaultValue = null)
5866
{
5967
this.Name = name;
6068
this.Type = type;
6169
this.IsRequired = isRequired;
6270
this.Description = description;
6371
this.Properties = properties;
6472
this.Schema = schema;
73+
this.DefaultValue = defaultValue;
6574
}
6675
}

0 commit comments

Comments
 (0)