Skip to content

Commit

Permalink
Merge pull request #443 from BroMarduk/436-dot-net8
Browse files Browse the repository at this point in the history
Add DotNet 8.0 Support
  • Loading branch information
kayhantolga committed Apr 7, 2024
2 parents 8a4b972 + 638802d commit 6cb7989
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/BuildAndDeployBetalgoOpenAI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/BuildAndDeployBetalgoOpenAIUtilities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions OpenAI.Playground/OpenAI.Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -21,28 +21,34 @@
</Content>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
<ItemGroup>
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net7.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net8.0' And '$(TargetFramework)' != 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions OpenAI.SDK/ObjectModels/Models.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;

#pragma warning disable CS1591
namespace OpenAI.ObjectModels;
Expand Down Expand Up @@ -468,4 +468,4 @@ public static string EnumToString(this Subject subject, string? baseModel)
_ => throw new ArgumentOutOfRangeException(nameof(subject), subject, null)
}, baseModel);
}
}
}
13 changes: 8 additions & 5 deletions OpenAI.SDK/OpenAI.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>

<Copyright>Betalgo Up Ltd.</Copyright>
<PackageProjectUrl>https://openai.com/</PackageProjectUrl>
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
Expand Down Expand Up @@ -53,18 +52,22 @@
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net7.0'">
<ItemGroup Condition="'$(TargetFramework)' != 'net8.0' And '$(TargetFramework)' != 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions OpenAI.Utilities.Tests/FunctionCallingHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void VerifyGetFunctionDefinition()
stringParameter.Description.ShouldBe("String Parameter");
stringParameter.Type.ShouldBe("string");

var enumValues = new List<string> {"Value1", "Value2", "Value3"};
var enumValues = new List<string> { "Value1", "Value2", "Value3" };

var enumParameter = functionDefinition.Parameters.Properties["enumParameter"];
enumParameter.Description.ShouldBe("Enum Parameter");
Expand Down Expand Up @@ -301,4 +301,4 @@ public enum TestEnum
Value1,
Value2,
Value3
}
}
14 changes: 7 additions & 7 deletions OpenAI.Utilities.Tests/OpenAI.Utilities.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<LangVersion>Latest</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions OpenAI.Utilities/Embedding/EmbeddingTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public EmbeddingTools(IOpenAIService sdk, int maxToken, string embeddingModel)

public async Task<DataFrame> ReadFilesAndCreateEmbeddingDataAsCsv(string pathToDirectoryOrFile, string outputFileName)
{
return await ReadFilesAndCreateEmbeddingDataAsCsv(new[] {pathToDirectoryOrFile}, outputFileName);
return await ReadFilesAndCreateEmbeddingDataAsCsv(new[] { pathToDirectoryOrFile }, outputFileName);
}

public async Task<DataFrame> ReadFilesAndCreateEmbeddingDataAsCsv(IEnumerable<string> pathsToDirectoriesOrFiles, string outputFileName)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -214,7 +214,7 @@ public async Task WriteToTempCsv(IEnumerable<TextEmbeddingData> 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();
}

Expand Down Expand Up @@ -394,7 +394,7 @@ public PrimitiveDataFrameColumn<double> DistancesFromEmbeddings(List<double> qEm
var distances = new PrimitiveDataFrameColumn<double>(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));
}

Expand Down Expand Up @@ -439,4 +439,4 @@ public async Task<DataFrame> ReadAllDataInFolderAndCreateEmbeddingData(string pa
var files = LoadFilesFromDirectory(pathToDirectory);
return await PerformTextEmbedding(files, outputFileName);
}
}
}
2 changes: 1 addition & 1 deletion OpenAI.Utilities/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public static string RemoveNewlines(this string input)

[GeneratedRegex(" {2,}")]
private static partial Regex MultipleSpacesToSingleSpace();
}
}
11 changes: 6 additions & 5 deletions OpenAI.Utilities/FunctionCalling/FunctionCallingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -129,7 +129,7 @@ public static List<ToolDefinition> GetToolDefinitions(Type type)

return result;
}


/// <summary>
/// Calls the function on the provided object, using the provided <see cref="FunctionCall" /> and returns the result of
Expand Down Expand Up @@ -161,6 +161,7 @@ public static List<ToolDefinition> GetToolDefinitions(Type type)
throw new InvalidFunctionCallException($"Method '{functionCall.Name}' on type '{obj.GetType()}' not found");
}


if (!methodInfo.ReturnType.IsAssignableTo(typeof(T)))
{
throw new InvalidFunctionCallException(
Expand Down Expand Up @@ -199,7 +200,7 @@ public static List<ToolDefinition> GetToolDefinitions(Type type)
args.Add(value);
}

var result = (T?) methodInfo.Invoke(obj, args.ToArray());
var result = (T?)methodInfo.Invoke(obj, args.ToArray());
return result;
}

Expand All @@ -225,4 +226,4 @@ public static List<ToolDefinition> GetToolDefinitions(Type type)
return methodsWithAttributes;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public FunctionDescriptionAttribute(string? description = null)
/// Description of the function
/// </summary>
public string? Description { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class InvalidFunctionCallException : Exception
public InvalidFunctionCallException(string message) : base(message)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// </summary>
public bool Required { get; set; } = true;
}
}
7 changes: 3 additions & 4 deletions OpenAI.Utilities/OpenAI.Utilities.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>

<Copyright>Betalgo Up Ltd.</Copyright>
<PackageProjectUrl>https://openai.com/</PackageProjectUrl>
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
Expand Down Expand Up @@ -41,8 +40,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Betalgo.OpenAI" Version="7.4.4" />
<PackageReference Include="CsvHelper" Version="30.1.0" />
<PackageReference Include="Betalgo.OpenAI" Version="7.4.6" />
<PackageReference Include="CsvHelper" Version="31.0.3" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.Data.Analysis" Version="0.21.1" />
</ItemGroup>
Expand Down
23 changes: 13 additions & 10 deletions OpenAI.UtilitiesPlayground/OpenAI.UtilitiesPlayground.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net8.0;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>acb2421b-1517-4212-93a4-e4eb182b4626</UserSecretsId>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenAI.Utilities\OpenAI.Utilities.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ public float AdvancedMath(float a, float b, AdvancedOperators advancedOperator)
};
}
}
}
}

0 comments on commit 6cb7989

Please sign in to comment.