From 09e43d1926e6eedba31abf5fc3bbe46cb67b1396 Mon Sep 17 00:00:00 2001 From: Dan Begallie Date: Wed, 6 Dec 2023 15:35:39 -0500 Subject: [PATCH 1/6] .NET8 Updates and fixes for mulit-version --- OpenAI.Playground/OpenAI.Playground.csproj | 16 +++++++++---- OpenAI.SDK/ObjectModels/Models.cs | 14 +++++------ OpenAI.SDK/OpenAI.csproj | 13 +++++++---- .../FunctionCallingHelperTests.cs | 5 ++-- .../OpenAI.Utilities.Tests.csproj | 14 +++++------ OpenAI.Utilities/Embedding/EmbeddingTools.cs | 23 +++++++++++++------ .../Extensions/StringExtensions.cs | 12 +++------- .../FunctionCalling/FunctionCallingHelper.cs | 17 ++++++++------ .../FunctionDescriptionAttribute.cs | 6 +++-- .../InvalidFunctionCallException.cs | 6 +++-- .../ParameterDescriptionAttribute.cs | 6 +++-- OpenAI.Utilities/OpenAI.Utilities.csproj | 12 ++++++---- .../OpenAI.UtilitiesPlayground.csproj | 17 ++++++++++++-- .../TestHelpers/FunctionCallingTestHelpers.cs | 4 ++-- 14 files changed, 99 insertions(+), 66 deletions(-) diff --git a/OpenAI.Playground/OpenAI.Playground.csproj b/OpenAI.Playground/OpenAI.Playground.csproj index 258aaa00..1c686f96 100644 --- a/OpenAI.Playground/OpenAI.Playground.csproj +++ b/OpenAI.Playground/OpenAI.Playground.csproj @@ -2,7 +2,7 @@ Exe - net7.0;net6.0;netstandard2.0 + net8.0;net7.0;net6.0;netstandard2.0 true PackageReference enable @@ -25,15 +25,21 @@ + + + + + + + - - + @@ -41,8 +47,8 @@ - - + + diff --git a/OpenAI.SDK/ObjectModels/Models.cs b/OpenAI.SDK/ObjectModels/Models.cs index 283ef94d..7cbc8096 100644 --- a/OpenAI.SDK/ObjectModels/Models.cs +++ b/OpenAI.SDK/ObjectModels/Models.cs @@ -172,7 +172,7 @@ public enum Subject /// 128,000 tokens Up to Apr 2023 /// public static string Gpt_4_vision_preview => "gpt-4-vision-preview"; - + public static string Ada => "ada"; @@ -262,7 +262,7 @@ public enum Subject /// 4,096 tokens Up to Sep 2021 /// public static string Gpt_3_5_Turbo_0613 => "gpt-3.5-turbo-0613"; - + /// /// The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. /// 16,384 tokens Up to Sep 2021 @@ -289,19 +289,19 @@ public enum Subject /// public static string Dall_e_2 => "dall-e-2"; /// - /// The latest DALL·E model released in Nov 2023. + /// The latest DALL·E model released in Nov 2023. /// public static string Dall_e_3 => "dall-e-3"; /// - /// TTS is an AI model that converts text to natural sounding spoken text. + /// TTS is an AI model that converts text to natural sounding spoken text. /// tts-1 is optimized for real time text to speech use cases. /// Released in Nov 2023. /// public static string Tts_1 => "tts-1"; /// - /// TTS is an AI model that converts text to natural sounding spoken text. + /// TTS is an AI model that converts text to natural sounding spoken text. /// tts-1-hd is optimized for quality /// Released in Nov 2023. /// @@ -370,9 +370,7 @@ public static string EnumToString(this Model model) Model.CodeSearchBabbageTextV1 => CodeSearchBabbageTextV1, Model.TextEditDavinciV1 => TextEditDavinciV1, Model.CodeEditDavinciV1 => CodeEditDavinciV1, - Model.ChatGpt3_5Turbo => ChatGpt3_5Turbo, Model.Gpt_3_5_Turbo => Gpt_3_5_Turbo, - Model.ChatGpt3_5Turbo0301 => ChatGpt3_5Turbo0301, Model.Gpt_3_5_Turbo_0301 => Gpt_3_5_Turbo_0301, Model.Gpt_3_5_Turbo_0613 => Gpt_3_5_Turbo_0613, Model.Gpt_3_5_Turbo_1106 => Gpt_3_5_Turbo_1106, @@ -430,4 +428,4 @@ public static string EnumToString(this Subject subject, string baseModel) _ => throw new ArgumentOutOfRangeException(nameof(subject), subject, null) }, baseModel); } -} \ No newline at end of file +} diff --git a/OpenAI.SDK/OpenAI.csproj b/OpenAI.SDK/OpenAI.csproj index eb99be6f..1ef8ac06 100644 --- a/OpenAI.SDK/OpenAI.csproj +++ b/OpenAI.SDK/OpenAI.csproj @@ -1,11 +1,10 @@  - net7.0;net6.0;netstandard2.0 + net8.0;net7.0;net6.0;netstandard2.0 enable enable Latest - Betalgo Up Ltd. https://openai.com/ OpenAI-Betalgo.png @@ -53,18 +52,22 @@ \ + + + + + - + - - + \ No newline at end of file diff --git a/OpenAI.Utilities.Tests/FunctionCallingHelperTests.cs b/OpenAI.Utilities.Tests/FunctionCallingHelperTests.cs index 2a85814e..9b26a1e1 100644 --- a/OpenAI.Utilities.Tests/FunctionCallingHelperTests.cs +++ b/OpenAI.Utilities.Tests/FunctionCallingHelperTests.cs @@ -31,7 +31,7 @@ public void VerifyGetFunctionDefinition() stringParameter.Description.ShouldBe("String Parameter"); stringParameter.Type.ShouldBe("string"); - var enumValues = new List {"Value1", "Value2", "Value3"}; + var enumValues = new List { "Value1", "Value2", "Value3" }; var enumParameter = functionDefinition.Parameters.Properties["enumParameter"]; enumParameter.Description.ShouldBe("Enum Parameter"); @@ -62,7 +62,6 @@ public void VerifyTypeOverride() public void VerifyGetFunctionDefinitions() { var functionDefinitions = FunctionCallingHelper.GetFunctionDefinitions(); - functionDefinitions.Count.ShouldBe(3); var functionDefinition = functionDefinitions.First(x => x.Name == "TestFunction"); @@ -275,4 +274,4 @@ public enum TestEnum Value1, Value2, Value3 -} \ No newline at end of file +} diff --git a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj index 3247a108..b8b550fe 100644 --- a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj +++ b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj @@ -1,23 +1,23 @@ - + - net7.0 + net8.0;net7.0;net6.0 enable enable - + Latest false true - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/OpenAI.Utilities/Embedding/EmbeddingTools.cs b/OpenAI.Utilities/Embedding/EmbeddingTools.cs index e37e756e..280fe27b 100644 --- a/OpenAI.Utilities/Embedding/EmbeddingTools.cs +++ b/OpenAI.Utilities/Embedding/EmbeddingTools.cs @@ -1,6 +1,13 @@ -using System.Collections; +#if NET6_0_OR_GREATER + +using System; +using System.Collections; +using System.Collections.Generic; using System.Globalization; +using System.IO; +using System.Linq; using System.Text; +using System.Threading.Tasks; using CsvHelper; using MathNet.Numerics; using Microsoft.Data.Analysis; @@ -109,7 +116,7 @@ public EmbeddingTools(IOpenAIService sdk, int maxToken, string embeddingModel) public async Task ReadFilesAndCreateEmbeddingDataAsCsv(string pathToDirectoryOrFile, string outputFileName) { - return await ReadFilesAndCreateEmbeddingDataAsCsv(new[] {pathToDirectoryOrFile}, outputFileName); + return await ReadFilesAndCreateEmbeddingDataAsCsv(new[] { pathToDirectoryOrFile }, outputFileName); } public async Task ReadFilesAndCreateEmbeddingDataAsCsv(IEnumerable pathsToDirectoriesOrFiles, string outputFileName) @@ -180,7 +187,7 @@ public string CreateContext(string question, DataFrame df, int maxLen = 1800) } // Else add it to the text that is being returned - returns.Add((string) row[textIndex]); + returns.Add((string)row[textIndex]); } // Return the context @@ -200,7 +207,7 @@ public DataFrame LoadEmbeddedDataFromCsv(string path) /// public IEnumerable LoadFilesFromDirectory(string pathToDirectory) { - return !Path.Exists(pathToDirectory) + return !File.Exists(pathToDirectory) ? new List() : Directory.EnumerateFiles(pathToDirectory).Select(LoadFile).Where(r => r != null).ToList()!; } @@ -214,7 +221,7 @@ public async Task WriteToTempCsv(IEnumerable textEmbeddingDat Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath) ?? string.Empty); await using var writer = new StreamWriter(outputFilePath); await using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture); - await csv.WriteRecordsAsync((IEnumerable) textEmbeddingData); + await csv.WriteRecordsAsync((IEnumerable)textEmbeddingData); await csv.DisposeAsync(); } @@ -394,7 +401,7 @@ public PrimitiveDataFrameColumn DistancesFromEmbeddings(List qEm var distances = new PrimitiveDataFrameColumn(EmbedStaticValues.Distances, embeddingsColumn.Length); for (var i = 0; i < embeddingsColumn.Length; i++) { - var rowEmbeddings = embeddingsColumn[i].ToString()!.Split(",").Select(Convert.ToDouble); + var rowEmbeddings = embeddingsColumn[i].ToString()!.Split(',').Select(Convert.ToDouble); distances[i] = Distance.Cosine(qEmbeddings.Select(x => x).ToArray(), Array.ConvertAll(rowEmbeddings.ToArray(), x => x)); } @@ -439,4 +446,6 @@ public async Task ReadAllDataInFolderAndCreateEmbeddingData(string pa var files = LoadFilesFromDirectory(pathToDirectory); return await PerformTextEmbedding(files, outputFileName); } -} \ No newline at end of file +} + +#endif diff --git a/OpenAI.Utilities/Extensions/StringExtensions.cs b/OpenAI.Utilities/Extensions/StringExtensions.cs index f13b774e..5d4922fe 100644 --- a/OpenAI.Utilities/Extensions/StringExtensions.cs +++ b/OpenAI.Utilities/Extensions/StringExtensions.cs @@ -4,8 +4,8 @@ namespace OpenAI.Utilities; public static partial class StringExtensions { - private static readonly Regex NewlineToSpaceRegex = NewlineToSpace(); - private static readonly Regex MultipleSpacesToSingleSpaceRegex = MultipleSpacesToSingleSpace(); + private static readonly Regex NewlineToSpaceRegex = new Regex("\\r?\\n"); + private static readonly Regex MultipleSpacesToSingleSpaceRegex = new Regex(" {2,}"); public static string RemoveNewlines(this string input) { @@ -18,10 +18,4 @@ public static string RemoveNewlines(this string input) input = MultipleSpacesToSingleSpaceRegex.Replace(input, " "); return input; } - - [GeneratedRegex("\\r?\\n")] - private static partial Regex NewlineToSpace(); - - [GeneratedRegex(" {2,}")] - private static partial Regex MultipleSpacesToSingleSpace(); -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs index 019cb228..f8575770 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs @@ -1,4 +1,7 @@ -using System.Reflection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Text.Json; using OpenAI.Builders; using OpenAI.ObjectModels.RequestModels; @@ -55,11 +58,11 @@ public static FunctionDefinition GetFunctionDefinition(MethodInfo methodInfo) case ({ } t, _) when t.IsAssignableFrom(typeof(string)): definition = PropertyDefinition.DefineString(description); break; - case ({IsEnum: true}, _): + case ({ IsEnum: true }, _): var enumValues = string.IsNullOrEmpty(parameterDescriptionAttribute?.Enum) ? Enum.GetNames(parameter.ParameterType).ToList() - : parameterDescriptionAttribute.Enum.Split(",").Select(x => x.Trim()).ToList(); + : parameterDescriptionAttribute.Enum.Split(',').Select(x => x.Trim()).ToList(); definition = PropertyDefinition.DefineEnum(enumValues, description); @@ -153,7 +156,7 @@ public static List GetFunctionDefinitions(Type type) throw new InvalidFunctionCallException($"Method '{functionCall.Name}' on type '{obj.GetType()}' not found"); } - if (!methodInfo.ReturnType.IsAssignableTo(typeof(T))) + if (!typeof(T).IsAssignableFrom(methodInfo.ReturnType)) { throw new InvalidFunctionCallException( $"Method '{functionCall.Name}' on type '{obj.GetType()}' has return type '{methodInfo.ReturnType}' but expected '{typeof(T)}'"); @@ -176,12 +179,12 @@ public static List GetFunctionDefinitions(Type type) throw new Exception($"Argument '{name}' not found"); } - var value = parameter.ParameterType.IsEnum ? Enum.Parse(parameter.ParameterType, argument.Value.ToString()!) : ((JsonElement) argument.Value).Deserialize(parameter.ParameterType); + var value = parameter.ParameterType.IsEnum ? Enum.Parse(parameter.ParameterType, argument.Value.ToString()!) : ((JsonElement)argument.Value).Deserialize(parameter.ParameterType); args.Add(value); } - var result = (T?) methodInfo.Invoke(obj, args.ToArray()); + var result = (T?)methodInfo.Invoke(obj, args.ToArray()); return result; } -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs index 9b4d0d6f..eb411513 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs @@ -1,4 +1,6 @@ -namespace OpenAI.Utilities.FunctionCalling; +using System; + +namespace OpenAI.Utilities.FunctionCalling; /// /// Attribute to mark a method as a function, and provide a description for the function. Can also be used to override @@ -24,4 +26,4 @@ public FunctionDescriptionAttribute(string? description = null) /// Description of the function /// public string? Description { get; set; } -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs b/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs index ddb75e46..695b2112 100644 --- a/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs +++ b/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs @@ -1,4 +1,6 @@ -namespace OpenAI.Utilities.FunctionCalling; +using System; + +namespace OpenAI.Utilities.FunctionCalling; /// /// Exception thrown when a function call is invalid @@ -11,4 +13,4 @@ public class InvalidFunctionCallException : Exception public InvalidFunctionCallException(string message) : base(message) { } -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs b/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs index 748facb8..2423b948 100644 --- a/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs @@ -1,4 +1,6 @@ -namespace OpenAI.Utilities.FunctionCalling; +using System; + +namespace OpenAI.Utilities.FunctionCalling; /// /// Attribute to describe a parameter of a function. Can also be used to override the Name of the parameter @@ -39,4 +41,4 @@ public ParameterDescriptionAttribute(string? description = null) /// Whether the parameter is required. If not provided, the parameter will be required. Default is true /// public bool Required { get; set; } = true; -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/OpenAI.Utilities.csproj b/OpenAI.Utilities/OpenAI.Utilities.csproj index 6d2648d7..13c8f54d 100644 --- a/OpenAI.Utilities/OpenAI.Utilities.csproj +++ b/OpenAI.Utilities/OpenAI.Utilities.csproj @@ -1,11 +1,10 @@ - net7.0 - enable + net8.0;net7.0;net6.0;netstandard2.0 + disable enable Latest - Betalgo Up Ltd. https://openai.com/ OpenAI-Betalgo.png @@ -41,9 +40,12 @@ - - + + + + + \ No newline at end of file diff --git a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj index 556a798d..389d9748 100644 --- a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj +++ b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj @@ -2,14 +2,27 @@ Exe - net7.0 + net8.0;net7.0 enable enable acb2421b-1517-4212-93a4-e4eb182b4626 + latest - + + + + + + + + + + + + + diff --git a/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs b/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs index aed7c958..50047c24 100644 --- a/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs +++ b/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs @@ -15,7 +15,7 @@ public static async Task ExerciseFunctionCalling(IOpenAIService openAIService) { //Functions = FunctionCallingHelper.GetFunctionDefinitions(calculator), //Functions = FunctionCallingHelper.GetFunctionDefinitions(typeof(Calculator)), - Functions = FunctionCallingHelper.GetFunctionDefinitions(), + //Functions = FunctionCallingHelper.GetFunctionDefinitions(), Messages = new List { ChatMessage.FromSystem("You are a helpful assistant."), @@ -88,4 +88,4 @@ public float AdvancedMath(float a, float b, AdvancedOperators advancedOperator) }; } } -} \ No newline at end of file +} From ee926c6c6170bc54cd015b8c7555f0dfa86f901e Mon Sep 17 00:00:00 2001 From: Dan Begallie Date: Wed, 6 Dec 2023 15:52:29 -0500 Subject: [PATCH 2/6] cleanup --- OpenAI.Utilities/Embedding/EmbeddingTools.cs | 5 ----- OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs | 5 +---- .../FunctionCalling/FunctionDescriptionAttribute.cs | 4 +--- .../FunctionCalling/InvalidFunctionCallException.cs | 4 +--- .../FunctionCalling/ParameterDescriptionAttribute.cs | 4 +--- OpenAI.Utilities/OpenAI.Utilities.csproj | 2 +- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/OpenAI.Utilities/Embedding/EmbeddingTools.cs b/OpenAI.Utilities/Embedding/EmbeddingTools.cs index 280fe27b..9324084a 100644 --- a/OpenAI.Utilities/Embedding/EmbeddingTools.cs +++ b/OpenAI.Utilities/Embedding/EmbeddingTools.cs @@ -1,13 +1,8 @@ #if NET6_0_OR_GREATER -using System; using System.Collections; -using System.Collections.Generic; using System.Globalization; -using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; using CsvHelper; using MathNet.Numerics; using Microsoft.Data.Analysis; diff --git a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs index f8575770..f00d1ecd 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; +using System.Reflection; using System.Text.Json; using OpenAI.Builders; using OpenAI.ObjectModels.RequestModels; diff --git a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs index eb411513..76e013c2 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs @@ -1,6 +1,4 @@ -using System; - -namespace OpenAI.Utilities.FunctionCalling; +namespace OpenAI.Utilities.FunctionCalling; /// /// Attribute to mark a method as a function, and provide a description for the function. Can also be used to override diff --git a/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs b/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs index 695b2112..257f1eec 100644 --- a/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs +++ b/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs @@ -1,6 +1,4 @@ -using System; - -namespace OpenAI.Utilities.FunctionCalling; +namespace OpenAI.Utilities.FunctionCalling; /// /// Exception thrown when a function call is invalid diff --git a/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs b/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs index 2423b948..20884917 100644 --- a/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs @@ -1,6 +1,4 @@ -using System; - -namespace OpenAI.Utilities.FunctionCalling; +namespace OpenAI.Utilities.FunctionCalling; /// /// Attribute to describe a parameter of a function. Can also be used to override the Name of the parameter diff --git a/OpenAI.Utilities/OpenAI.Utilities.csproj b/OpenAI.Utilities/OpenAI.Utilities.csproj index 13c8f54d..794eb03b 100644 --- a/OpenAI.Utilities/OpenAI.Utilities.csproj +++ b/OpenAI.Utilities/OpenAI.Utilities.csproj @@ -2,7 +2,7 @@ net8.0;net7.0;net6.0;netstandard2.0 - disable + enable enable Latest Betalgo Up Ltd. From 465333f06be7dc9a0cd0af80e86220dbb50842f4 Mon Sep 17 00:00:00 2001 From: Dan Begallie Date: Wed, 6 Dec 2023 15:57:43 -0500 Subject: [PATCH 3/6] Fix files --- OpenAI.SDK/ObjectModels/Models.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/OpenAI.SDK/ObjectModels/Models.cs b/OpenAI.SDK/ObjectModels/Models.cs index 7cbc8096..774e6a37 100644 --- a/OpenAI.SDK/ObjectModels/Models.cs +++ b/OpenAI.SDK/ObjectModels/Models.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; #pragma warning disable CS1591 namespace OpenAI.ObjectModels; @@ -172,7 +172,7 @@ public enum Subject /// 128,000 tokens Up to Apr 2023 /// public static string Gpt_4_vision_preview => "gpt-4-vision-preview"; - + public static string Ada => "ada"; @@ -262,7 +262,7 @@ public enum Subject /// 4,096 tokens Up to Sep 2021 /// public static string Gpt_3_5_Turbo_0613 => "gpt-3.5-turbo-0613"; - + /// /// The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more. /// 16,384 tokens Up to Sep 2021 @@ -289,19 +289,19 @@ public enum Subject /// public static string Dall_e_2 => "dall-e-2"; /// - /// The latest DALL·E model released in Nov 2023. + /// The latest DALL·E model released in Nov 2023. /// public static string Dall_e_3 => "dall-e-3"; /// - /// TTS is an AI model that converts text to natural sounding spoken text. + /// TTS is an AI model that converts text to natural sounding spoken text. /// tts-1 is optimized for real time text to speech use cases. /// Released in Nov 2023. /// public static string Tts_1 => "tts-1"; /// - /// TTS is an AI model that converts text to natural sounding spoken text. + /// TTS is an AI model that converts text to natural sounding spoken text. /// tts-1-hd is optimized for quality /// Released in Nov 2023. /// @@ -370,7 +370,9 @@ public static string EnumToString(this Model model) Model.CodeSearchBabbageTextV1 => CodeSearchBabbageTextV1, Model.TextEditDavinciV1 => TextEditDavinciV1, Model.CodeEditDavinciV1 => CodeEditDavinciV1, + Model.ChatGpt3_5Turbo => ChatGpt3_5Turbo, Model.Gpt_3_5_Turbo => Gpt_3_5_Turbo, + Model.ChatGpt3_5Turbo0301 => ChatGpt3_5Turbo0301, Model.Gpt_3_5_Turbo_0301 => Gpt_3_5_Turbo_0301, Model.Gpt_3_5_Turbo_0613 => Gpt_3_5_Turbo_0613, Model.Gpt_3_5_Turbo_1106 => Gpt_3_5_Turbo_1106, From f97cbd34bc2a79f7be4e7ea1038104dcfd4f3de9 Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Wed, 3 Apr 2024 19:52:03 +0100 Subject: [PATCH 4/6] Reverted OpenAI support for .net standart and .net 6 --- .../OpenAI.Utilities.Tests.csproj | 2 +- OpenAI.Utilities/Embedding/EmbeddingTools.cs | 8 ++------ OpenAI.Utilities/Extensions/StringExtensions.cs | 10 ++++++++-- .../FunctionCalling/FunctionCallingHelper.cs | 3 ++- OpenAI.Utilities/OpenAI.Utilities.csproj | 2 +- .../OpenAI.UtilitiesPlayground.csproj | 15 +++------------ 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj index b8b550fe..e1c7840f 100644 --- a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj +++ b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net8.0 enable enable Latest diff --git a/OpenAI.Utilities/Embedding/EmbeddingTools.cs b/OpenAI.Utilities/Embedding/EmbeddingTools.cs index 9324084a..1ebb2a17 100644 --- a/OpenAI.Utilities/Embedding/EmbeddingTools.cs +++ b/OpenAI.Utilities/Embedding/EmbeddingTools.cs @@ -1,6 +1,4 @@ -#if NET6_0_OR_GREATER - -using System.Collections; +using System.Collections; using System.Globalization; using System.Text; using CsvHelper; @@ -202,7 +200,7 @@ public DataFrame LoadEmbeddedDataFromCsv(string path) /// public IEnumerable LoadFilesFromDirectory(string pathToDirectory) { - return !File.Exists(pathToDirectory) + return !Path.Exists(pathToDirectory) ? new List() : Directory.EnumerateFiles(pathToDirectory).Select(LoadFile).Where(r => r != null).ToList()!; } @@ -442,5 +440,3 @@ public async Task ReadAllDataInFolderAndCreateEmbeddingData(string pa return await PerformTextEmbedding(files, outputFileName); } } - -#endif diff --git a/OpenAI.Utilities/Extensions/StringExtensions.cs b/OpenAI.Utilities/Extensions/StringExtensions.cs index 5d4922fe..7d0bfbdd 100644 --- a/OpenAI.Utilities/Extensions/StringExtensions.cs +++ b/OpenAI.Utilities/Extensions/StringExtensions.cs @@ -4,8 +4,8 @@ namespace OpenAI.Utilities; public static partial class StringExtensions { - private static readonly Regex NewlineToSpaceRegex = new Regex("\\r?\\n"); - private static readonly Regex MultipleSpacesToSingleSpaceRegex = new Regex(" {2,}"); + private static readonly Regex NewlineToSpaceRegex = NewlineToSpace(); + private static readonly Regex MultipleSpacesToSingleSpaceRegex = MultipleSpacesToSingleSpace(); public static string RemoveNewlines(this string input) { @@ -18,4 +18,10 @@ public static string RemoveNewlines(this string input) input = MultipleSpacesToSingleSpaceRegex.Replace(input, " "); return input; } + + [GeneratedRegex("\\r?\\n")] + private static partial Regex NewlineToSpace(); + + [GeneratedRegex(" {2,}")] + private static partial Regex MultipleSpacesToSingleSpace(); } diff --git a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs index a45e4ab7..9c8177a7 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs @@ -161,7 +161,8 @@ public static List GetToolDefinitions(Type type) throw new InvalidFunctionCallException($"Method '{functionCall.Name}' on type '{obj.GetType()}' not found"); } - if (!typeof(T).IsAssignableFrom(methodInfo.ReturnType)) + + if (!methodInfo.ReturnType.IsAssignableTo(typeof(T))) { throw new InvalidFunctionCallException( $"Method '{functionCall.Name}' on type '{obj.GetType()}' has return type '{methodInfo.ReturnType}' but expected '{typeof(T)}'"); diff --git a/OpenAI.Utilities/OpenAI.Utilities.csproj b/OpenAI.Utilities/OpenAI.Utilities.csproj index c2176656..8df1d189 100644 --- a/OpenAI.Utilities/OpenAI.Utilities.csproj +++ b/OpenAI.Utilities/OpenAI.Utilities.csproj @@ -1,7 +1,7 @@ - net8.0;net7.0;net6.0;netstandard2.0 + net8.0; enable enable Latest diff --git a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj index 389d9748..5cc6d93a 100644 --- a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj +++ b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj @@ -2,7 +2,7 @@ Exe - net8.0;net7.0 + net8.0; enable enable acb2421b-1517-4212-93a4-e4eb182b4626 @@ -13,7 +13,7 @@ - + @@ -21,17 +21,8 @@ + - - - - - - - - - - From 9d32d1b6e63e3d503cf562d3ae170229164a6a4e Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Wed, 3 Apr 2024 19:58:29 +0100 Subject: [PATCH 5/6] Updated nuget packages --- OpenAI.Playground/OpenAI.Playground.csproj | 4 ++-- OpenAI.Playground/Program.cs | 5 +---- OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj | 8 ++++---- OpenAI.Utilities/OpenAI.Utilities.csproj | 2 +- .../OpenAI.UtilitiesPlayground.csproj | 8 ++++---- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/OpenAI.Playground/OpenAI.Playground.csproj b/OpenAI.Playground/OpenAI.Playground.csproj index 1c686f96..bb245deb 100644 --- a/OpenAI.Playground/OpenAI.Playground.csproj +++ b/OpenAI.Playground/OpenAI.Playground.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/OpenAI.Playground/Program.cs b/OpenAI.Playground/Program.cs index 2b8f0e8c..bd181f14 100644 --- a/OpenAI.Playground/Program.cs +++ b/OpenAI.Playground/Program.cs @@ -3,9 +3,7 @@ using OpenAI.Extensions; using OpenAI.Interfaces; using OpenAI.Playground.TestHelpers; -#if NET6_0_OR_GREATER using LaserCatEyes.HttpClientListener; -#endif var builder = new ConfigurationBuilder() .AddJsonFile("ApiSettings.json") @@ -15,12 +13,11 @@ var serviceCollection = new ServiceCollection(); serviceCollection.AddScoped(_ => configuration); -#if NET6_0_OR_GREATER // Laser cat eyes is a tool that shows your requests and responses between OpenAI server and your client. // Get your app key from https://lasercateyes.com for FREE and put it under ApiSettings.json or secrets.json. // It is in Beta version, if you don't want to use it just comment out below line. serviceCollection.AddLaserCatEyesHttpClientListener(); -#endif + serviceCollection.AddOpenAIService(); //// DeploymentId and ResourceName are only for Azure OpenAI. If you want to use Azure OpenAI services you have to set Provider type To Azure. diff --git a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj index e1c7840f..067e42a2 100644 --- a/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj +++ b/OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj @@ -10,14 +10,14 @@ - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/OpenAI.Utilities/OpenAI.Utilities.csproj b/OpenAI.Utilities/OpenAI.Utilities.csproj index 8df1d189..633e6c2e 100644 --- a/OpenAI.Utilities/OpenAI.Utilities.csproj +++ b/OpenAI.Utilities/OpenAI.Utilities.csproj @@ -41,7 +41,7 @@ - + diff --git a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj index 5cc6d93a..d771f7a4 100644 --- a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj +++ b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj @@ -1,4 +1,4 @@ - + Exe @@ -15,13 +15,13 @@ - + - + - + From 638802d9cda3a3f015e40e49512b1aad7827c5c7 Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Sat, 6 Apr 2024 23:07:58 +0100 Subject: [PATCH 6/6] Yaml Update --- .github/workflows/BuildAndDeployBetalgoOpenAI.yml | 2 +- .github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml | 5 ++++- .github/workflows/codeql-analysis.yml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/BuildAndDeployBetalgoOpenAI.yml b/.github/workflows/BuildAndDeployBetalgoOpenAI.yml index c589dff3..b6eff3df 100644 --- a/.github/workflows/BuildAndDeployBetalgoOpenAI.yml +++ b/.github/workflows/BuildAndDeployBetalgoOpenAI.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Clean run: dotnet clean - name: Restore dependencies diff --git a/.github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml b/.github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml index 01edee8b..cda48cd0 100644 --- a/.github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml +++ b/.github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml @@ -11,10 +11,13 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Sleep for 15 minutes + run: sleep 15m + - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Clean run: dotnet clean - name: Restore dependencies diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6b23f1c1..b23a536e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -53,7 +53,7 @@ jobs: - name: Set up dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.0.*' + dotnet-version: '8.0.*' # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below)