Skip to content

Commit

Permalink
v1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JZO001 committed Apr 26, 2024
1 parent c6ca0bc commit f3ff8a1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Forge.OpenAI/Forge.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/JZO001/Forge.OpenAI</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>1.4.2.0</AssemblyVersion>
<AssemblyVersion>1.4.3.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>OpenAI, Azure-OpenAI, Azure-OpenAI-API, ChatGPT, GPT4, GPT-4, GPT-4-API, GPT35, GPT-35, GPT-35-API, GPT3, GPT-3, GPT-3-API, DALLE, DALL-E, DALL-E-API, OpenAi, openAi, azure, assistant, threads, Whisper, AI, ML, dotnet, dotnetcore, machine-learning, sdk, forge, translation, transcription, chat, chatbot, image, image-processing, embedding, embedding-models, moderation, text-completion, fine-tune, dotNet, csharp</PackageTags>
<PackageReleaseNotes>
v1.4.3 - Improved service factory methods
v1.4.2 - Fix issues
v1.4.1 - Fix issue in MessageResponseBase, duplicated status field and wrong "incomplete_details" field. Constants updated in Tool class.
v1.4.0 - New models, properties, bugfixes, supporting v2 of assistant, run, messages, threads
Expand Down
24 changes: 22 additions & 2 deletions Forge.OpenAI/Services/OpenAIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ public class OpenAIService : IOpenAIService
RunStepService = runStepService;
}

/// <summary>
/// Creates a new service instance with individual options.
/// The method gets back the ServiceProvider instance for further use.
/// It is the caller responsibility to dispose it, at the end of the OpenAIService instance lifecycle.
/// </summary>
/// <param name="configure">The configuration handler.</param>
/// <param name="serviceProvider">The constructed IServiceProvider instance.</param>
/// <returns>
/// <br />
/// </returns>
/// <exception cref="System.ArgumentNullException">configure</exception>
public static IOpenAIService CreateService(Action<OpenAIOptions> configure, out ServiceProvider serviceProvider)
{
if (configure == null) throw new ArgumentNullException(nameof(configure));

ServiceCollection services = new ServiceCollection();
services.AddForgeOpenAI(configure);
serviceProvider = services.BuildServiceProvider();

return CreateService(serviceProvider);
}

/// <summary>
/// Creates a new service instance with individual options.
/// The method gets back the ServiceProvider instance for further use.
Expand Down Expand Up @@ -175,8 +197,6 @@ public static IOpenAIService CreateService(IServiceProvider serviceProvider)
{
if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider));

serviceProvider.GetRequiredService<IProviderEndpointService>();

return new OpenAIService(
serviceProvider.GetRequiredService<IModelService>(),
serviceProvider.GetRequiredService<ITextCompletionService>(),
Expand Down
16 changes: 11 additions & 5 deletions Playgrounds/MultipleApiKeyUsage/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Forge.OpenAI.Services;
using Forge.OpenAI.Settings;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace MultipleApiKeyUsage
{
Expand All @@ -26,17 +27,22 @@ static async Task Main(string[] args)
const string apiKeyForUserA = "";
const string apiKeyForUserB = "";

// Create the OpenAI service instances for the users with manual DI configuration
// AddForgeOpenAI can be replaced with other init methods, see ServiceCollectionExtensions.cs
IOpenAIService openAiInstanceForUserA =
OpenAIService
.CreateService(sc =>
sc.AddForgeOpenAI(options =>
options.AuthenticationInfo = new AuthenticationInfo(apiKeyForUserA)), out ServiceProvider serviceProviderA);

IOpenAIService openAiInstanceForUserB =
OpenAIService
.CreateService(sc =>
sc.AddForgeOpenAI(options =>
options.AuthenticationInfo = new AuthenticationInfo(apiKeyForUserB)), out ServiceProvider serviceProviderB);
// The same can be done with the OpenAIOptions
OpenAIOptions optionsForUserB = new OpenAIOptions();
optionsForUserB.AuthenticationInfo = new AuthenticationInfo(apiKeyForUserB);

IOpenAIService openAiInstanceForUserB = OpenAIService.CreateService((OpenAIOptions options) =>
{
options.AuthenticationInfo = new AuthenticationInfo(apiKeyForUserB);
}, out ServiceProvider serviceProviderB);

using (serviceProviderA)
{
Expand Down

0 comments on commit f3ff8a1

Please sign in to comment.