Skip to content

Commit c52647f

Browse files
dazfullerDarren Fuller
andauthored
Update to net10 (#15)
* Add .NET 10.0 to target frameworks * Update package dependencies to latest versions * update to use new extension block syntax * remove redundant null assignment in _schemaDocument initialization * remove unused Json.Schema namespace * replace var with const for expectedPrompt in PromptFileTests * update workflows to use .NET 10.0 --------- Co-authored-by: Darren Fuller <dazfuller@proton.me>
1 parent 8a2f989 commit c52647f

8 files changed

Lines changed: 66 additions & 66 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup .NET
2121
uses: actions/setup-dotnet@v4
2222
with:
23-
dotnet-version: 9.0.x
23+
dotnet-version: 10.0.x
2424
- name: Restore dependencies
2525
run: dotnet restore
2626
- name: Build

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup .NET
1515
uses: actions/setup-dotnet@v4
1616
with:
17-
dotnet-version: 9.0.x
17+
dotnet-version: 10.0.x
1818
- name: Get latest tag version
1919
id: vars
2020
run: echo "tag=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_OUTPUT

DotPrompt.Tests/DotPrompt.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -10,9 +10,9 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1414
<PackageReference Include="xunit" Version="2.9.3" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>

DotPrompt.Tests/PromptFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public void GenerateUserPrompt_WithAllParameterValues_GeneratesValidPrompt()
329329
{
330330
var promptFile = PromptFile.FromFile("SamplePrompts/param-types.prompt");
331331

332-
var expectedPrompt =
332+
const string expectedPrompt =
333333
"Parameter 1: Arthur Dent\nParameter 2: 42\nParameter 3: true\nParameter 4: 2024-01-02 03:04:05Z\nParameter 5: { SEP = True }\nParameter 6: Hello : 12";
334334

335335
var userPrompt = promptFile.GetUserPrompt(new Dictionary<string, object>

DotPrompt/DotPrompt.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<PackageId>DotPrompt</PackageId>
@@ -21,9 +21,9 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Fluid.Core" Version="2.25.0" />
25-
<PackageReference Include="JsonSchema.Net" Version="7.4.0" />
26-
<PackageReference Include="OpenAI" Version="2.3.0" />
24+
<PackageReference Include="Fluid.Core" Version="2.31.0" />
25+
<PackageReference Include="JsonSchema.Net" Version="8.0.5" />
26+
<PackageReference Include="OpenAI" Version="2.8.0" />
2727
<PackageReference Include="YamlDotNet" Version="16.3.0" />
2828
</ItemGroup>
2929

DotPrompt/Extensions/OpenAi/OpenAiExtensions.cs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,74 @@ namespace DotPrompt.Extensions.OpenAi;
77
/// </summary>
88
public static class OpenAiExtensions
99
{
10-
/// <summary>
11-
/// Converts a <see cref="PromptFile"/> instance to a collection of <see cref="ChatMessage"/> objects.
12-
/// </summary>
1310
/// <param name="promptFile">The <see cref="PromptFile"/> instance containing prompt definitions.</param>
14-
/// <param name="values">A dictionary of values to be substituted in the user prompt template.</param>
15-
/// <returns>An enumerable collection of <see cref="ChatMessage"/> objects.</returns>
16-
public static IEnumerable<ChatMessage> ToOpenAiChatMessages(this PromptFile promptFile,
17-
IDictionary<string, object>? values)
11+
extension(PromptFile promptFile)
1812
{
19-
var messages = new List<ChatMessage>();
20-
21-
// If the prompt file provides any few shot prompts, then include these first
22-
if (promptFile.FewShots.Length != 0)
13+
/// <summary>
14+
/// Converts a <see cref="PromptFile"/> instance to a collection of <see cref="ChatMessage"/> objects.
15+
/// </summary>
16+
/// <param name="values">A dictionary of values to be substituted in the user prompt template.</param>
17+
/// <returns>An enumerable collection of <see cref="ChatMessage"/> objects.</returns>
18+
public IEnumerable<ChatMessage> ToOpenAiChatMessages(IDictionary<string, object>? values)
2319
{
24-
foreach (var fewShot in promptFile.FewShots)
20+
var messages = new List<ChatMessage>();
21+
22+
// If the prompt file provides any few shot prompts, then include these first
23+
if (promptFile.FewShots.Length != 0)
2524
{
26-
messages.Add(new UserChatMessage(fewShot.User));
27-
messages.Add(new AssistantChatMessage(fewShot.Response));
25+
foreach (var fewShot in promptFile.FewShots)
26+
{
27+
messages.Add(new UserChatMessage(fewShot.User));
28+
messages.Add(new AssistantChatMessage(fewShot.Response));
29+
}
2830
}
29-
}
3031

31-
if (!string.IsNullOrEmpty(promptFile.Prompts!.System))
32-
{
33-
messages.Add(new SystemChatMessage(promptFile.GetSystemPrompt(values)));
34-
}
32+
if (!string.IsNullOrEmpty(promptFile.Prompts!.System))
33+
{
34+
messages.Add(new SystemChatMessage(promptFile.GetSystemPrompt(values)));
35+
}
3536

36-
messages.Add(new UserChatMessage(promptFile.GetUserPrompt(values)));
37+
messages.Add(new UserChatMessage(promptFile.GetUserPrompt(values)));
3738

38-
return messages;
39-
}
39+
return messages;
40+
}
4041

41-
/// <summary>
42-
/// Converts a <see cref="PromptFile"/> instance to an <see cref="ChatCompletionOptions"/> object.
43-
/// </summary>
44-
/// <param name="promptFile">The <see cref="PromptFile"/> instance containing configuration and prompt definitions.</param>
45-
/// <returns>A <see cref="ChatCompletionOptions"/> object configured based on the <see cref="PromptFile"/> instance.</returns>
46-
public static ChatCompletionOptions ToOpenAiChatCompletionOptions(this PromptFile promptFile)
47-
{
48-
var chatResponseFormat = promptFile.Config.OutputFormat switch
42+
/// <summary>
43+
/// Converts a <see cref="PromptFile"/> instance to an <see cref="ChatCompletionOptions"/> object.
44+
/// </summary>
45+
/// <returns>A <see cref="ChatCompletionOptions"/> object configured based on the <see cref="PromptFile"/> instance.</returns>
46+
public ChatCompletionOptions ToOpenAiChatCompletionOptions()
4947
{
50-
OutputFormat.Text => ChatResponseFormat.CreateTextFormat(),
51-
OutputFormat.Json => ChatResponseFormat.CreateJsonObjectFormat(),
52-
OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is not null =>
53-
ChatResponseFormat.CreateJsonSchemaFormat(
54-
promptFile.Name,
55-
BinaryData.FromString(promptFile.Config.Output.ToSchemaDocument()),
56-
jsonSchemaIsStrict: true),
57-
OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is null =>
58-
throw new DotPromptException("A valid schema was not provided to be used with the JsonSchema response type"),
59-
_ => throw new DotPromptException("The requested output format is not available")
60-
};
48+
var chatResponseFormat = promptFile.Config.OutputFormat switch
49+
{
50+
OutputFormat.Text => ChatResponseFormat.CreateTextFormat(),
51+
OutputFormat.Json => ChatResponseFormat.CreateJsonObjectFormat(),
52+
OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is not null =>
53+
ChatResponseFormat.CreateJsonSchemaFormat(
54+
promptFile.Name,
55+
BinaryData.FromString(promptFile.Config.Output.ToSchemaDocument()),
56+
jsonSchemaIsStrict: true),
57+
OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is null =>
58+
throw new DotPromptException("A valid schema was not provided to be used with the JsonSchema response type"),
59+
_ => throw new DotPromptException("The requested output format is not available")
60+
};
6161

62-
var chatCompletionOptions = new ChatCompletionOptions
63-
{
64-
ResponseFormat = chatResponseFormat
65-
};
62+
var chatCompletionOptions = new ChatCompletionOptions
63+
{
64+
ResponseFormat = chatResponseFormat
65+
};
6666

67-
if (promptFile.Config.Temperature is not null)
68-
{
69-
chatCompletionOptions.Temperature = promptFile.Config.Temperature;
70-
}
67+
if (promptFile.Config.Temperature is not null)
68+
{
69+
chatCompletionOptions.Temperature = promptFile.Config.Temperature;
70+
}
7171

72-
if (promptFile.Config.MaxTokens is not null)
73-
{
74-
chatCompletionOptions.MaxOutputTokenCount = promptFile.Config.MaxTokens;
75-
}
72+
if (promptFile.Config.MaxTokens is not null)
73+
{
74+
chatCompletionOptions.MaxOutputTokenCount = promptFile.Config.MaxTokens;
75+
}
7676

77-
return chatCompletionOptions;
77+
return chatCompletionOptions;
78+
}
7879
}
7980
}

DotPrompt/Output.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace DotPrompt;
88
/// </summary>
99
public class Output
1010
{
11-
private string? _schemaDocument = null;
11+
private string? _schemaDocument;
1212

1313
/// <summary>
1414
/// Gets or sets the format of the output. This determines how the output should be structured.

DotPrompt/PromptFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Globalization;
22
using System.Text.RegularExpressions;
33
using Fluid;
4-
using Json.Schema;
54
using YamlDotNet.Core;
65
using YamlDotNet.Serialization;
76
using YamlDotNet.Serialization.NamingConventions;

0 commit comments

Comments
 (0)