Skip to content

Commit

Permalink
Merge pull request #325 from xbotter/deps/km-0.12
Browse files Browse the repository at this point in the history
🔧 Update KernelMemory Package
  • Loading branch information
AsakusaRinne authored Nov 24, 2023
2 parents 597188c + d1e2a47 commit 14b7cce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LLama.Examples/Examples/KernelMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static async Task Run()
MaxTokensPerLine = 100,
OverlappingTokens = 30
})
.BuildServerlessClient();
.Build();

await memory.ImportDocumentAsync(@"./Assets/sample-SK-Readme.pdf", steps: Constants.PipelineWithoutSummary);

Expand Down
1 change: 1 addition & 0 deletions LLama.Examples/LLama.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.12.231123.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta8" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
</ItemGroup>
Expand Down
25 changes: 20 additions & 5 deletions LLama.KernelMemory/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using LLama;
using LLama.Common;
using Microsoft.KernelMemory.AI;
using Microsoft.SemanticKernel.AI.Embeddings;

namespace LLamaSharp.KernelMemory
{
Expand All @@ -15,13 +16,27 @@ namespace LLamaSharp.KernelMemory
/// </summary>
public static class BuilderExtensions
{

private static IKernelMemoryBuilder WithCustomEmbeddingGeneration(this IKernelMemoryBuilder builder, ITextEmbeddingGeneration embeddingGeneration)
{
builder.AddSingleton<ITextEmbeddingGeneration>(embeddingGeneration);
builder.AddIngestionEmbeddingGenerator(embeddingGeneration);
return builder;
}

private static IKernelMemoryBuilder WithCustomTextGeneration(this IKernelMemoryBuilder builder, ITextGeneration textGeneration)
{
builder.AddSingleton<ITextGeneration>(textGeneration);
return builder;
}

/// <summary>
/// Adds LLamaSharpTextEmbeddingGeneration to the KernelMemoryBuilder.
/// </summary>
/// <param name="builder">The KernelMemoryBuilder instance.</param>
/// <param name="config">The LLamaSharpConfig instance.</param>
/// <returns>The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration added.</returns>
public static KernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this KernelMemoryBuilder builder, LLamaSharpConfig config)
public static IKernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this IKernelMemoryBuilder builder, LLamaSharpConfig config)
{
builder.WithCustomEmbeddingGeneration(new LLamaSharpTextEmbeddingGeneration(config));
return builder;
Expand All @@ -33,7 +48,7 @@ public static KernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this Ker
/// <param name="builder">The KernelMemoryBuilder instance.</param>
/// <param name="textEmbeddingGeneration">The LLamaSharpTextEmbeddingGeneration instance.</param>
/// <returns>The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration added.</returns>
public static KernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this KernelMemoryBuilder builder, LLamaSharpTextEmbeddingGeneration textEmbeddingGeneration)
public static IKernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this IKernelMemoryBuilder builder, LLamaSharpTextEmbeddingGeneration textEmbeddingGeneration)
{
builder.WithCustomEmbeddingGeneration(textEmbeddingGeneration);
return builder;
Expand All @@ -45,7 +60,7 @@ public static KernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this Ker
/// <param name="builder">The KernelMemoryBuilder instance.</param>
/// <param name="config">The LLamaSharpConfig instance.</param>
/// <returns>The KernelMemoryBuilder instance with LLamaSharpTextGeneration added.</returns>
public static KernelMemoryBuilder WithLLamaSharpTextGeneration(this KernelMemoryBuilder builder, LLamaSharpConfig config)
public static IKernelMemoryBuilder WithLLamaSharpTextGeneration(this IKernelMemoryBuilder builder, LLamaSharpConfig config)
{
builder.WithCustomTextGeneration(new LlamaSharpTextGeneration(config));
return builder;
Expand All @@ -57,7 +72,7 @@ public static KernelMemoryBuilder WithLLamaSharpTextGeneration(this KernelMemory
/// <param name="builder">The KernelMemoryBuilder instance.</param>
/// <param name="textGeneration">The LlamaSharpTextGeneration instance.</param>
/// <returns>The KernelMemoryBuilder instance with LLamaSharpTextGeneration added.</returns>
public static KernelMemoryBuilder WithLLamaSharpTextGeneration(this KernelMemoryBuilder builder, LlamaSharpTextGeneration textGeneration)
public static IKernelMemoryBuilder WithLLamaSharpTextGeneration(this IKernelMemoryBuilder builder, LlamaSharpTextGeneration textGeneration)
{
builder.WithCustomTextGeneration(textGeneration);
return builder;
Expand All @@ -69,7 +84,7 @@ public static KernelMemoryBuilder WithLLamaSharpTextGeneration(this KernelMemory
/// <param name="builder">The KernelMemoryBuilder instance.</param>
/// <param name="config">The LLamaSharpConfig instance.</param>
/// <returns>The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration and LLamaSharpTextGeneration added.</returns>
public static KernelMemoryBuilder WithLLamaSharpDefaults(this KernelMemoryBuilder builder, LLamaSharpConfig config)
public static IKernelMemoryBuilder WithLLamaSharpDefaults(this IKernelMemoryBuilder builder, LLamaSharpConfig config)
{
var parameters = new ModelParams(config.ModelPath)
{
Expand Down
2 changes: 1 addition & 1 deletion LLama.KernelMemory/LLamaSharp.KernelMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.10.231116.2-preview" />
<PackageReference Include="Microsoft.KernelMemory.Abstractions" Version="0.12.231123.1-preview" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 14b7cce

Please sign in to comment.