Skip to content

Commit

Permalink
WIP config APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerBarreto committed Jun 19, 2024
1 parent 52dbca4 commit 39ef577
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Embeddings;
using Microsoft.SemanticKernel.Http;
using Microsoft.SemanticKernel.TextToImage;
using OpenAI;

namespace Microsoft.SemanticKernel.Connectors.OpenAI;
Expand Down Expand Up @@ -164,4 +165,43 @@ public static IKernelBuilder AddOpenAIChatCompletion(
return builder;
}
#endregion

#region Images


/// <summary>
/// Add the OpenAI Dall-E text to image service to the list
/// </summary>
/// <param name="builder">The <see cref="IKernelBuilder"/> instance to augment.</param>
/// <param name="apiKey">OpenAI API key, see https://platform.openai.com/account/api-keys</param>
/// <param name="orgId">OpenAI organization id. This is usually optional unless your account belongs to multiple organizations.</param>
/// <param name="serviceId">A local identifier for the given AI service</param>
/// <param name="httpClient">The HttpClient to use with this service.</param>
/// <returns>The same instance as <paramref name="builder"/>.</returns>
[Experimental("SKEXP0010")]
//[Obsolete("Use the configuration paramether overload of this method instead.")]
public static IKernelBuilder AddOpenAITextToImage(
this IKernelBuilder builder,
string apiKey,
string? orgId = null,
string? serviceId = null,
HttpClient? httpClient = null)
{
Verify.NotNull(builder);
Verify.NotNullOrWhiteSpace(apiKey);

builder.Services.AddKeyedSingleton<ITextToImageService>(serviceId, (serviceProvider, _) =>
new OpenAITextToImageService(new()
{
ApiKey = apiKey,
OrganizationId = orgId,
ServiceId = serviceId,
LoggerFactory = serviceProvider.GetService<ILoggerFactory>()
},
HttpClientProvider.GetHttpClient(httpClient, serviceProvider));

return builder;
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static IServiceCollection AddOpenAIChatCompletion(this IServiceCollection
/// <param name="serviceId">A local identifier for the given AI service</param>
/// <returns>The same instance as <paramref name="services"/>.</returns>
[Experimental("SKEXP0010")]
[Obsolete("Use the configuration paramether overload of this method instead.")]
//[Obsolete("Use the configuration paramether overload of this method instead.")]
public static IServiceCollection AddOpenAIChatCompletion(
this IServiceCollection services,
string modelId,
Expand Down Expand Up @@ -160,35 +160,6 @@ public static IServiceCollection AddOpenAIChatCompletion(

#region Images

/// <summary>
/// Add the OpenAI Dall-E text to image service to the list
/// </summary>
/// <param name="builder">The <see cref="IKernelBuilder"/> instance to augment.</param>
/// <param name="apiKey">OpenAI API key, see https://platform.openai.com/account/api-keys</param>
/// <param name="orgId">OpenAI organization id. This is usually optional unless your account belongs to multiple organizations.</param>
/// <param name="serviceId">A local identifier for the given AI service</param>
/// <param name="httpClient">The HttpClient to use with this service.</param>
/// <returns>The same instance as <paramref name="builder"/>.</returns>
[Experimental("SKEXP0010")]
public static IKernelBuilder AddOpenAITextToImage(
this IKernelBuilder builder,
string apiKey,
string? orgId = null,
string? serviceId = null,
HttpClient? httpClient = null)
{
Verify.NotNull(builder);
Verify.NotNullOrWhiteSpace(apiKey);

builder.Services.AddKeyedSingleton<ITextToImageService>(serviceId, (serviceProvider, _) =>
new OpenAITextToImageService(
apiKey,
orgId,
HttpClientProvider.GetHttpClient(httpClient, serviceProvider),
serviceProvider.GetService<ILoggerFactory>()));

return builder;
}

/// <summary>
/// Add the OpenAI Dall-E text to image service to the list
Expand Down

0 comments on commit 39ef577

Please sign in to comment.