diff --git a/LLama.Examples/Examples/KernelMemory.cs b/LLama.Examples/Examples/KernelMemory.cs index 0c2b908f..0aea3d7a 100644 --- a/LLama.Examples/Examples/KernelMemory.cs +++ b/LLama.Examples/Examples/KernelMemory.cs @@ -30,7 +30,7 @@ namespace LLama.Examples.Examples MaxTokensPerLine = 100, OverlappingTokens = 30 }) - .BuildServerlessClient(); + .Build(); await memory.ImportDocumentAsync(@"./Assets/sample-SK-Readme.pdf", steps: Constants.PipelineWithoutSummary); diff --git a/LLama.Examples/LLama.Examples.csproj b/LLama.Examples/LLama.Examples.csproj index 03d22fcc..b7369172 100644 --- a/LLama.Examples/LLama.Examples.csproj +++ b/LLama.Examples/LLama.Examples.csproj @@ -29,6 +29,7 @@ + diff --git a/LLama.KernelMemory/BuilderExtensions.cs b/LLama.KernelMemory/BuilderExtensions.cs index dc746dc6..5f476ce8 100644 --- a/LLama.KernelMemory/BuilderExtensions.cs +++ b/LLama.KernelMemory/BuilderExtensions.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using LLama; using LLama.Common; using Microsoft.KernelMemory.AI; +using Microsoft.SemanticKernel.AI.Embeddings; namespace LLamaSharp.KernelMemory { @@ -15,13 +16,27 @@ namespace LLamaSharp.KernelMemory /// public static class BuilderExtensions { + + private static IKernelMemoryBuilder WithCustomEmbeddingGeneration(this IKernelMemoryBuilder builder, ITextEmbeddingGeneration embeddingGeneration) + { + builder.AddSingleton(embeddingGeneration); + builder.AddIngestionEmbeddingGenerator(embeddingGeneration); + return builder; + } + + private static IKernelMemoryBuilder WithCustomTextGeneration(this IKernelMemoryBuilder builder, ITextGeneration textGeneration) + { + builder.AddSingleton(textGeneration); + return builder; + } + /// /// Adds LLamaSharpTextEmbeddingGeneration to the KernelMemoryBuilder. /// /// The KernelMemoryBuilder instance. /// The LLamaSharpConfig instance. /// The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration added. - 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; @@ -33,7 +48,7 @@ namespace LLamaSharp.KernelMemory /// The KernelMemoryBuilder instance. /// The LLamaSharpTextEmbeddingGeneration instance. /// The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration added. - public static KernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this KernelMemoryBuilder builder, LLamaSharpTextEmbeddingGeneration textEmbeddingGeneration) + public static IKernelMemoryBuilder WithLLamaSharpTextEmbeddingGeneration(this IKernelMemoryBuilder builder, LLamaSharpTextEmbeddingGeneration textEmbeddingGeneration) { builder.WithCustomEmbeddingGeneration(textEmbeddingGeneration); return builder; @@ -45,7 +60,7 @@ namespace LLamaSharp.KernelMemory /// The KernelMemoryBuilder instance. /// The LLamaSharpConfig instance. /// The KernelMemoryBuilder instance with LLamaSharpTextGeneration added. - 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; @@ -57,7 +72,7 @@ namespace LLamaSharp.KernelMemory /// The KernelMemoryBuilder instance. /// The LlamaSharpTextGeneration instance. /// The KernelMemoryBuilder instance with LLamaSharpTextGeneration added. - public static KernelMemoryBuilder WithLLamaSharpTextGeneration(this KernelMemoryBuilder builder, LlamaSharpTextGeneration textGeneration) + public static IKernelMemoryBuilder WithLLamaSharpTextGeneration(this IKernelMemoryBuilder builder, LlamaSharpTextGeneration textGeneration) { builder.WithCustomTextGeneration(textGeneration); return builder; @@ -69,7 +84,7 @@ namespace LLamaSharp.KernelMemory /// The KernelMemoryBuilder instance. /// The LLamaSharpConfig instance. /// The KernelMemoryBuilder instance with LLamaSharpTextEmbeddingGeneration and LLamaSharpTextGeneration added. - public static KernelMemoryBuilder WithLLamaSharpDefaults(this KernelMemoryBuilder builder, LLamaSharpConfig config) + public static IKernelMemoryBuilder WithLLamaSharpDefaults(this IKernelMemoryBuilder builder, LLamaSharpConfig config) { var parameters = new ModelParams(config.ModelPath) { diff --git a/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj b/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj index b2aeffd6..78d4712b 100644 --- a/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj +++ b/LLama.KernelMemory/LLamaSharp.KernelMemory.csproj @@ -29,7 +29,7 @@ - +