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) diff --git a/OpenAI.Playground/OpenAI.Playground.csproj b/OpenAI.Playground/OpenAI.Playground.csproj index 258aaa00..bb245deb 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 @@ -21,19 +21,25 @@ - - + + + + + + + + + - - + @@ -41,8 +47,8 @@ - - + + diff --git a/OpenAI.Playground/Program.cs b/OpenAI.Playground/Program.cs index 8229238e..8af03599 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.SDK/ObjectModels/Models.cs b/OpenAI.SDK/ObjectModels/Models.cs index e2fd4e82..30fea73f 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; @@ -468,4 +468,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 bb7e0445..5e54c6db 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 3c92a47e..f6c95183 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"); @@ -301,4 +301,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..067e42a2 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 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..1ebb2a17 100644 --- a/OpenAI.Utilities/Embedding/EmbeddingTools.cs +++ b/OpenAI.Utilities/Embedding/EmbeddingTools.cs @@ -109,7 +109,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 +180,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 @@ -214,7 +214,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 +394,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 +439,4 @@ public async Task ReadAllDataInFolderAndCreateEmbeddingData(string pa var files = LoadFilesFromDirectory(pathToDirectory); return await PerformTextEmbedding(files, outputFileName); } -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/Extensions/StringExtensions.cs b/OpenAI.Utilities/Extensions/StringExtensions.cs index f13b774e..7d0bfbdd 100644 --- a/OpenAI.Utilities/Extensions/StringExtensions.cs +++ b/OpenAI.Utilities/Extensions/StringExtensions.cs @@ -24,4 +24,4 @@ public static string RemoveNewlines(this string input) [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 ae0c8cad..9c8177a7 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs @@ -55,11 +55,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); @@ -129,7 +129,7 @@ public static List GetToolDefinitions(Type type) return result; } - + /// /// Calls the function on the provided object, using the provided and returns the result of @@ -161,6 +161,7 @@ public static List GetToolDefinitions(Type type) throw new InvalidFunctionCallException($"Method '{functionCall.Name}' on type '{obj.GetType()}' not found"); } + if (!methodInfo.ReturnType.IsAssignableTo(typeof(T))) { throw new InvalidFunctionCallException( @@ -199,7 +200,7 @@ public static List GetToolDefinitions(Type type) args.Add(value); } - var result = (T?) methodInfo.Invoke(obj, args.ToArray()); + var result = (T?)methodInfo.Invoke(obj, args.ToArray()); return result; } @@ -225,4 +226,4 @@ public static List GetToolDefinitions(Type type) return methodsWithAttributes; } -} \ No newline at end of file +} diff --git a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs index 9b4d0d6f..76e013c2 100644 --- a/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/FunctionDescriptionAttribute.cs @@ -24,4 +24,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..257f1eec 100644 --- a/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs +++ b/OpenAI.Utilities/FunctionCalling/InvalidFunctionCallException.cs @@ -11,4 +11,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..20884917 100644 --- a/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs +++ b/OpenAI.Utilities/FunctionCalling/ParameterDescriptionAttribute.cs @@ -39,4 +39,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 49aee28e..633e6c2e 100644 --- a/OpenAI.Utilities/OpenAI.Utilities.csproj +++ b/OpenAI.Utilities/OpenAI.Utilities.csproj @@ -1,11 +1,10 @@ - net7.0 + net8.0; enable enable Latest - Betalgo Up Ltd. https://openai.com/ OpenAI-Betalgo.png @@ -41,8 +40,8 @@ - - + + diff --git a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj index 6c82cb8f..d771f7a4 100644 --- a/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj +++ b/OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj @@ -1,25 +1,28 @@ - + Exe - net7.0 + net8.0; enable enable acb2421b-1517-4212-93a4-e4eb182b4626 latest - + - - - - - - - + + + + + + + + + + diff --git a/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs b/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs index 77b4ebc5..eca42028 100644 --- a/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs +++ b/OpenAI.UtilitiesPlayground/TestHelpers/FunctionCallingTestHelpers.cs @@ -88,4 +88,4 @@ public float AdvancedMath(float a, float b, AdvancedOperators advancedOperator) }; } } -} \ No newline at end of file +}