Skip to content

Commit

Permalink
Update version, reduce extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger committed Feb 17, 2024
1 parent 373a32c commit da954e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Console.WriteLine(result.GetValue<string>());
You can get the transcript using `result.GetValue<string>()`.

You can also upload local audio and video file. To do this:
- Set the `AssemblyAI:AllowFileSystemAccess` configuration to `true`.
- Set the `AssemblyAI:Plugin:AllowFileSystemAccess` configuration to `true`.
- Configure the `INPUT` variable with a local file path.

```csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<PackageTags>SemanticKernel;AI;AssemblyAI;transcript</PackageTags>
<Company>AssemblyAI</Company>
<Product>AssemblyAI</Product>
<AssemblyVersion>1.0.3.0</AssemblyVersion>
<FileVersion>1.0.3.0</FileVersion>
<PackageVersion>1.0.3</PackageVersion>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<PackageVersion>1.1.0</PackageVersion>
<OutputType>Library</OutputType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/AssemblyAI/assemblyai-semantic-kernel</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/AssemblyAI.SemanticKernel/AssemblyAIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ string input
if (AllowFileSystemAccess == false)
{
throw new Exception(
"You need to allow file system access to upload files. Set AssemblyAI:AllowFileSystemAccess to true."
"You need to allow file system access to upload files. Set AssemblyAI:Plugin:AllowFileSystemAccess to true."
);
}

Expand Down
37 changes: 8 additions & 29 deletions src/AssemblyAI.SemanticKernel/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,6 @@ namespace AssemblyAI.SemanticKernel
{
public static class Extensions
{
/// <summary>
/// Configure the AssemblyAI plugins using the specified configuration section path.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IKernelBuilder AddAssemblyAIPlugin(
this IKernelBuilder builder
) => AddAssemblyAIPlugin(builder, "AssemblyAI");

/// <summary>
/// Configure the AssemblyAI plugins using the specified configuration section path.
/// </summary>
/// <param name="builder"></param>
/// <param name="configSectionPath">The path of the configuration section to bind options to</param>
/// <returns></returns>
public static IKernelBuilder AddAssemblyAIPlugin(
this IKernelBuilder builder,
string configSectionPath
)
{
var services = builder.Services;
var optionsBuilder = services.AddOptions<AssemblyAIPluginOptions>();
optionsBuilder.BindConfiguration(configSectionPath);
ValidateOptions(optionsBuilder);
AddPlugin(builder);
return builder;
}

/// <summary>
/// Configure the AssemblyAI plugins using the specified configuration section path.
/// </summary>
Expand All @@ -50,6 +22,13 @@ string configSectionPath
IConfiguration configuration
)
{
var pluginConfigurationSection = configuration.GetSection("AssemblyAI:Plugin");
// if configuration exists at section, use that config, otherwise using section that was passed in.
if (pluginConfigurationSection.Exists())
{
configuration = pluginConfigurationSection;
}

var services = builder.Services;
var optionsBuilder = services.AddOptions<AssemblyAIPluginOptions>();
optionsBuilder.Bind(configuration);
Expand Down Expand Up @@ -123,7 +102,7 @@ private static void ValidateOptions(OptionsBuilder<AssemblyAIPluginOptions> opti
{
optionsBuilder.Validate(
options => !string.IsNullOrEmpty(options.ApiKey),
"AssemblyAI:ApiKey must be configured."
"AssemblyAI:Plugin:ApiKey must be configured."
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planning.Handlebars;

Expand Down Expand Up @@ -33,12 +32,11 @@ private static IConfigurationRoot BuildConfig(string[] args)
private static Kernel BuildKernel(IConfiguration config)
{
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.Services.AddSingleton(config);
kernelBuilder.AddOpenAIChatCompletion(
"gpt-3.5-turbo",
config["OpenAI:ApiKey"] ?? throw new Exception("OpenAI:ApiKey configuration is required.")
)
.AddAssemblyAIPlugin();
.AddAssemblyAIPlugin(config);
var kernel = kernelBuilder.Build();

kernel.ImportPluginFromType<FindFilePlugin>();
Expand Down
6 changes: 4 additions & 2 deletions src/Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"AssemblyAI": {
"ApiKey": "<USE_USER_SECRETS>",
"AllowFileSystemAccess": true
"Plugin": {
"ApiKey": "<USE_USER_SECRETS>",
"AllowFileSystemAccess": true
}
}
}

0 comments on commit da954e5

Please sign in to comment.