diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 609b21f..ee86018 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -20,7 +20,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2e68b0e..23ebda2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Get latest tag version id: vars run: echo "tag=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_OUTPUT diff --git a/DotPrompt.Tests/DotPrompt.Tests.csproj b/DotPrompt.Tests/DotPrompt.Tests.csproj index bd81673..54874fb 100644 --- a/DotPrompt.Tests/DotPrompt.Tests.csproj +++ b/DotPrompt.Tests/DotPrompt.Tests.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0 + net8.0;net9.0;net10.0 enable enable @@ -10,9 +10,9 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/DotPrompt.Tests/PromptFileTests.cs b/DotPrompt.Tests/PromptFileTests.cs index 80d6e65..11ac5fb 100644 --- a/DotPrompt.Tests/PromptFileTests.cs +++ b/DotPrompt.Tests/PromptFileTests.cs @@ -329,7 +329,7 @@ public void GenerateUserPrompt_WithAllParameterValues_GeneratesValidPrompt() { var promptFile = PromptFile.FromFile("SamplePrompts/param-types.prompt"); - var expectedPrompt = + const string expectedPrompt = "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"; var userPrompt = promptFile.GetUserPrompt(new Dictionary diff --git a/DotPrompt/DotPrompt.csproj b/DotPrompt/DotPrompt.csproj index 7525f8a..9080d48 100644 --- a/DotPrompt/DotPrompt.csproj +++ b/DotPrompt/DotPrompt.csproj @@ -1,7 +1,7 @@  - net8.0;net9.0 + net8.0;net9.0;net10.0 enable enable DotPrompt @@ -21,9 +21,9 @@ - - - + + + diff --git a/DotPrompt/Extensions/OpenAi/OpenAiExtensions.cs b/DotPrompt/Extensions/OpenAi/OpenAiExtensions.cs index d5ba39c..ac8e69a 100644 --- a/DotPrompt/Extensions/OpenAi/OpenAiExtensions.cs +++ b/DotPrompt/Extensions/OpenAi/OpenAiExtensions.cs @@ -7,73 +7,74 @@ namespace DotPrompt.Extensions.OpenAi; /// public static class OpenAiExtensions { - /// - /// Converts a instance to a collection of objects. - /// /// The instance containing prompt definitions. - /// A dictionary of values to be substituted in the user prompt template. - /// An enumerable collection of objects. - public static IEnumerable ToOpenAiChatMessages(this PromptFile promptFile, - IDictionary? values) + extension(PromptFile promptFile) { - var messages = new List(); - - // If the prompt file provides any few shot prompts, then include these first - if (promptFile.FewShots.Length != 0) + /// + /// Converts a instance to a collection of objects. + /// + /// A dictionary of values to be substituted in the user prompt template. + /// An enumerable collection of objects. + public IEnumerable ToOpenAiChatMessages(IDictionary? values) { - foreach (var fewShot in promptFile.FewShots) + var messages = new List(); + + // If the prompt file provides any few shot prompts, then include these first + if (promptFile.FewShots.Length != 0) { - messages.Add(new UserChatMessage(fewShot.User)); - messages.Add(new AssistantChatMessage(fewShot.Response)); + foreach (var fewShot in promptFile.FewShots) + { + messages.Add(new UserChatMessage(fewShot.User)); + messages.Add(new AssistantChatMessage(fewShot.Response)); + } } - } - if (!string.IsNullOrEmpty(promptFile.Prompts!.System)) - { - messages.Add(new SystemChatMessage(promptFile.GetSystemPrompt(values))); - } + if (!string.IsNullOrEmpty(promptFile.Prompts!.System)) + { + messages.Add(new SystemChatMessage(promptFile.GetSystemPrompt(values))); + } - messages.Add(new UserChatMessage(promptFile.GetUserPrompt(values))); + messages.Add(new UserChatMessage(promptFile.GetUserPrompt(values))); - return messages; - } + return messages; + } - /// - /// Converts a instance to an object. - /// - /// The instance containing configuration and prompt definitions. - /// A object configured based on the instance. - public static ChatCompletionOptions ToOpenAiChatCompletionOptions(this PromptFile promptFile) - { - var chatResponseFormat = promptFile.Config.OutputFormat switch + /// + /// Converts a instance to an object. + /// + /// A object configured based on the instance. + public ChatCompletionOptions ToOpenAiChatCompletionOptions() { - OutputFormat.Text => ChatResponseFormat.CreateTextFormat(), - OutputFormat.Json => ChatResponseFormat.CreateJsonObjectFormat(), - OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is not null => - ChatResponseFormat.CreateJsonSchemaFormat( - promptFile.Name, - BinaryData.FromString(promptFile.Config.Output.ToSchemaDocument()), - jsonSchemaIsStrict: true), - OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is null => - throw new DotPromptException("A valid schema was not provided to be used with the JsonSchema response type"), - _ => throw new DotPromptException("The requested output format is not available") - }; + var chatResponseFormat = promptFile.Config.OutputFormat switch + { + OutputFormat.Text => ChatResponseFormat.CreateTextFormat(), + OutputFormat.Json => ChatResponseFormat.CreateJsonObjectFormat(), + OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is not null => + ChatResponseFormat.CreateJsonSchemaFormat( + promptFile.Name, + BinaryData.FromString(promptFile.Config.Output.ToSchemaDocument()), + jsonSchemaIsStrict: true), + OutputFormat.JsonSchema when promptFile.Config.Output?.Schema is null => + throw new DotPromptException("A valid schema was not provided to be used with the JsonSchema response type"), + _ => throw new DotPromptException("The requested output format is not available") + }; - var chatCompletionOptions = new ChatCompletionOptions - { - ResponseFormat = chatResponseFormat - }; + var chatCompletionOptions = new ChatCompletionOptions + { + ResponseFormat = chatResponseFormat + }; - if (promptFile.Config.Temperature is not null) - { - chatCompletionOptions.Temperature = promptFile.Config.Temperature; - } + if (promptFile.Config.Temperature is not null) + { + chatCompletionOptions.Temperature = promptFile.Config.Temperature; + } - if (promptFile.Config.MaxTokens is not null) - { - chatCompletionOptions.MaxOutputTokenCount = promptFile.Config.MaxTokens; - } + if (promptFile.Config.MaxTokens is not null) + { + chatCompletionOptions.MaxOutputTokenCount = promptFile.Config.MaxTokens; + } - return chatCompletionOptions; + return chatCompletionOptions; + } } } \ No newline at end of file diff --git a/DotPrompt/Output.cs b/DotPrompt/Output.cs index abd9ad6..746c82e 100644 --- a/DotPrompt/Output.cs +++ b/DotPrompt/Output.cs @@ -8,7 +8,7 @@ namespace DotPrompt; /// public class Output { - private string? _schemaDocument = null; + private string? _schemaDocument; /// /// Gets or sets the format of the output. This determines how the output should be structured. diff --git a/DotPrompt/PromptFile.cs b/DotPrompt/PromptFile.cs index eb9b548..379d937 100644 --- a/DotPrompt/PromptFile.cs +++ b/DotPrompt/PromptFile.cs @@ -1,7 +1,6 @@ using System.Globalization; using System.Text.RegularExpressions; using Fluid; -using Json.Schema; using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions;