Skip to content

Commit 9da9b38

Browse files
Merge branch 'main' into update-modelid
2 parents a3782cf + 79908b0 commit 9da9b38

6 files changed

Lines changed: 85 additions & 27 deletions

File tree

‎dotnet/Directory.Packages.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
4848
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
4949
<PackageVersion Include="xunit" Version="2.6.3" />
50-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.5" />
50+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
5151
<PackageVersion Include="xretry" Version="1.9.0" />
5252
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
5353
<PackageVersion Include="Polly" Version="8.2.0" />

‎dotnet/README.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ First, let's create a new project, targeting .NET 6 or newer, and add the
1414
`Microsoft.SemanticKernel` nuget package to your project from the command prompt
1515
in Visual Studio:
1616

17-
dotnet add package Microsoft.SemanticKernel --prerelease
17+
dotnet add package Microsoft.SemanticKernel
1818

1919
# Running prompts with input parameters
2020

@@ -24,7 +24,7 @@ Copy and paste the following code into your project, with your Azure OpenAI key
2424
using Microsoft.SemanticKernel;
2525
using Microsoft.SemanticKernel.Connectors.OpenAI;
2626

27-
var builder = new KernelBuilder();
27+
var builder = Kernel.CreateBuilder();
2828

2929
builder.AddAzureOpenAIChatCompletion(
3030
"gpt-35-turbo", // Azure OpenAI Deployment Name
@@ -54,9 +54,9 @@ string text2 = @"
5454
2. The acceleration of an object depends on the mass of the object and the amount of force applied.
5555
3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first.";
5656

57-
Console.WriteLine(await kernel.InvokeAsync(summarize, new KernelArguments(text1)));
57+
Console.WriteLine(await kernel.InvokeAsync(summarize, new() { ["input"] = text1 }));
5858

59-
Console.WriteLine(await kernel.InvokeAsync(summarize, new KernelArguments(text2)));
59+
Console.WriteLine(await kernel.InvokeAsync(summarize, new() { ["input"] = text2 }));
6060

6161
// Output:
6262
// Energy conserved, entropy increases, zero entropy at 0K.
@@ -102,13 +102,13 @@ Packages included in **Microsoft.SemanticKernel**:
102102
engineering, semantic memory and semantic functions definition and orchestration.
103103
1. **Microsoft.SemanticKernel.Connectors.OpenAI**: connectors to OpenAI and Azure
104104
OpenAI, allowing to run semantic functions, chats, text to image with GPT3,
105-
GPT3.5, GPT4, DALL-E2.
105+
GPT3.5, GPT4, DALL-E3.
106106

107107
Other SK packages available at nuget.org:
108108

109-
1. **Microsoft.SemanticKernel.Connectors.Memory.Qdrant**: Qdrant connector for
109+
1. **Microsoft.SemanticKernel.Connectors.Qdrant**: Qdrant connector for
110110
plugins and semantic memory.
111-
2. **Microsoft.SemanticKernel.Connectors.Memory.Sqlite**: SQLite connector for
111+
2. **Microsoft.SemanticKernel.Connectors.Sqlite**: SQLite connector for
112112
plugins and semantic memory
113113
3. **Microsoft.SemanticKernel.Plugins.Document**: Document Plugin: Word processing,
114114
OpenXML, etc.
@@ -117,4 +117,3 @@ Other SK packages available at nuget.org:
117117
5. **Microsoft.SemanticKernel.Plugins.OpenApi**: OpenAPI Plugin.
118118
6. **Microsoft.SemanticKernel.Plugins.Web**: Web Plugin: search the web, download
119119
files, etc.
120-
7. **Microsoft.SemanticKernel.Reliability.Polly**: Extension for http resiliency.

‎dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,28 @@ private static ChatCompletionsOptions CreateChatCompletionsOptions(
755755
Seed = executionSettings.Seed,
756756
};
757757

758+
switch (executionSettings.ResponseFormat)
759+
{
760+
case ChatCompletionsResponseFormat formatObject:
761+
// If the response format is an Azure SDK ChatCompletionsResponseFormat, just pass it along.
762+
options.ResponseFormat = formatObject;
763+
break;
764+
765+
case string formatString:
766+
// If the response format is a string, map the ones we know about, and ignore the rest.
767+
switch (formatString)
768+
{
769+
case "json_object":
770+
options.ResponseFormat = ChatCompletionsResponseFormat.JsonObject;
771+
break;
772+
773+
case "text":
774+
options.ResponseFormat = ChatCompletionsResponseFormat.Text;
775+
break;
776+
}
777+
break;
778+
}
779+
758780
executionSettings.ToolCallBehavior?.ConfigureOptions(kernel, options);
759781
if (executionSettings.TokenSelectionBiases is not null)
760782
{

‎dotnet/src/Connectors/Connectors.OpenAI/OpenAIPromptExecutionSettings.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public sealed class OpenAIPromptExecutionSettings : PromptExecutionSettings
7676
[JsonPropertyName("seed")]
7777
public long? Seed { get; set; }
7878

79+
/// <summary>
80+
/// Gets or sets the response format to use for the completion.
81+
/// </summary>
82+
[Experimental("SKEXP0013")]
83+
[JsonPropertyName("response_format")]
84+
public object? ResponseFormat { get; set; }
85+
7986
/// <summary>
8087
/// The system prompt to use when generating text using a chat model.
8188
/// Defaults to "Assistant is a large language model."

‎dotnet/src/Planners/Planners.Handlebars/Handlebars/Extensions/KernelParameterMetadataExtensions.cs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
using System.Linq;
66
using System.Reflection;
77
using System.Text.Json;
8+
using Microsoft.SemanticKernel.Text;
89

910
namespace Microsoft.SemanticKernel.Planning.Handlebars;
1011

1112
internal static class KernelParameterMetadataExtensions
1213
{
13-
private static readonly JsonSerializerOptions s_jsonOptionsCache = new()
14-
{
15-
WriteIndented = true,
16-
};
17-
1814
/// <summary>
1915
/// Checks if type is primitive or string
2016
/// </summary>
@@ -128,7 +124,7 @@ public static KernelParameterMetadata ParseJsonSchema(this KernelParameterMetada
128124

129125
public static string ToJsonString(this JsonElement jsonProperties)
130126
{
131-
return JsonSerializer.Serialize(jsonProperties, s_jsonOptionsCache);
127+
return JsonSerializer.Serialize(jsonProperties, JsonOptionsCache.WriteIndented);
132128
}
133129

134130
public static string GetSchemaTypeName(this KernelParameterMetadata parameter)

‎dotnet/src/SemanticKernel.Abstractions/Functions/KernelFunctionAttribute.cs‎

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
namespace Microsoft.SemanticKernel;
1111

1212
/// <summary>
13-
/// Specifies that a method on a class imported as a plugin with should be included as a <see cref="KernelFunction"/>.
13+
/// Specifies that a method on a class imported as a plugin should be included as a <see cref="KernelFunction"/> in the resulting <see cref="KernelPlugin"/>.
1414
/// </summary>
1515
/// <remarks>
1616
/// <para>
17-
/// When the system imports functions from an object, it searches all public methods tagged with this attribute.
17+
/// When the system imports functions from an object, it searches for all public methods tagged with this attribute.
1818
/// If a method is not tagged with this attribute, it may still be imported directly via a <see cref="Delegate"/>
1919
/// or <see cref="MethodInfo"/> referencing the method directly.
2020
/// </para>
@@ -26,18 +26,52 @@ namespace Microsoft.SemanticKernel;
2626
/// by an LLM or embedding.
2727
/// </para>
2828
/// <para>
29-
/// Functions may have any number of parameters. A given method function may declare at
30-
/// most one parameter of each of these types - <see cref="Kernel"/>, <see cref="KernelArguments"/>,
31-
/// <see cref="CancellationToken"/>, <see cref="CultureInfo"/>, <see cref="ILogger"/> or <see cref="ILoggerFactory"/>.
32-
/// Parameters are populated based on a arguments of the same name. If no argument of the given name is present, but
33-
/// a default value was specified via either a <see cref="DefaultValueAttribute"/> or an optional value in the signature,
34-
/// that default value is used instead. If no default value was specified and it's the first parameter, the "input"
35-
/// argument will be used. Otherwise, if no value is available, the invocation will fail.
29+
/// Functions may have any number of parameters. In general, arguments to parameters are supplied via the <see cref="KernelArguments"/>
30+
/// used to invoke the function, with the arguments matched by name to the parameters of the method. If no argument of the given name
31+
/// is present, but a default value was specified in the method's definition, that default value will be used. If the argument value in
32+
/// <see cref="KernelArguments"/> is not of the same type as the parameter, the system will attempt to convert the value to the parameter's
33+
/// type using a <see cref="TypeConverter"/>.
3634
/// </para>
3735
/// <para>
38-
/// For non-string parameters, the argument value is automatically converted to the appropriate type to be passed
39-
/// in based on the <see cref="TypeConverter"/> for the specified type. Similarly, return values are automatically converted
40-
/// back to strings via the associated <see cref="TypeConverter"/>.
36+
/// However, parameters of the following types are treated specially and are supplied from a source other than from the arguments dictionary:
37+
/// <list type="table">
38+
/// <item>
39+
/// <term><see cref="Kernel"/></term>
40+
/// <description>The <see cref="Kernel"/> supplied when invoking the function.</description>
41+
/// </item>
42+
/// <item>
43+
/// <term><see cref="KernelArguments"/></term>
44+
/// <description>The <see cref="KernelArguments"/> supplied when invoking the function.</description>
45+
/// </item>
46+
/// <item>
47+
/// <term><see cref="KernelFunction"/></term>
48+
/// <description>The <see cref="KernelFunction"/> that represents this function being invoked.</description>
49+
/// </item>
50+
/// <item>
51+
/// <term><see cref="CancellationToken"/></term>
52+
/// <description>The <see cref="CancellationToken"/> supplied when invoking the function.</description>
53+
/// </item>
54+
/// <item>
55+
/// <term><see cref="CultureInfo"/> or <see cref="IFormatProvider"/></term>
56+
/// <description>The result of <see cref="Kernel.Culture"/> from the <see cref="Kernel"/> used when invoking the function.</description>
57+
/// </item>
58+
/// <item>
59+
/// <term><see cref="ILoggerFactory"/> or <see cref="ILogger"/></term>
60+
/// <description>The result of <see cref="Kernel.LoggerFactory"/> from the <see cref="Kernel"/> (or an <see cref="ILogger"/> created from it) used when invoking the function.</description>
61+
/// </item>
62+
/// <item>
63+
/// <term><see cref="IAIServiceSelector"/></term>
64+
/// <description>The result of <see cref="Kernel.ServiceSelector"/> from the <see cref="Kernel"/> used when invoking the function.</description>
65+
/// </item>
66+
/// </list>
67+
/// </para>
68+
/// <para>
69+
/// Arguments may also be fulfilled from the associated <see cref="Kernel"/>'s <see cref="Kernel.Services"/> service provider. If a parameter is attributed
70+
/// with <see cref="FromKernelServicesAttribute"/>, the system will attempt to resolve the parameter by querying the service provider for a service of the
71+
/// parameter's type. If the service provider does not contain a service of the parameter's type and the parameter is not optional, the invocation will fail.
72+
/// </para>
73+
/// <para>
74+
/// If no value can be derived from any of these means for all parameters, the invocation will fail.
4175
/// </para>
4276
/// </remarks>
4377
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]

0 commit comments

Comments
 (0)