-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 Add Semantic Memory SDK to LLama.Examples
Added a project reference to LLama.KernelMemory in the LLama.Examples.csproj file. 🔧 Add KernelMemory class and update TestRunner Added a new class KernelMemory to the LLama.Examples.NewVersion namespace, which includes a Run method that demonstrates the usage of Semantic Kernel Memory. The class imports a sample PDF document and asks a question to the memory, displaying the answer and relevant sources. Updated the TestRunner class in the same namespace to include an option (choice 15) to run the KernelMemory example. 🔧 Fix typo in LLamaSharpTextEmbeddingGeneration class Fixed a typo in the LLamaSharpTextEmbeddingGeneration class where the LlamaSharpConfig variable was incorrectly named as LlamaSharpConfig. Added XML documentation for the LLamaSharpTextEmbeddingGeneration constructor, Dispose method, and GenerateEmbeddingsAsync method. Summary: - Added project reference to LLama.KernelMemory and LLama.SemanticKernel in LLama.Examples.csproj - Added KernelMemory class to demonstrate Semantic Kernel Memory usage - Updated TestRunner class to include option for running KernelMemory example - Fixed typo in LLamaSharpTextEmbeddingGeneration class - Added XML documentation for constructor, Dispose method, and GenerateEmbeddingsAsync method in LLamaSharpTextEmbeddingGeneration class
- Loading branch information
Showing
8 changed files
with
163 additions
and
15 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.SemanticMemory.Handlers; | ||
using Microsoft.SemanticMemory; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using LLamaSharp.KernelMemory; | ||
|
||
namespace LLama.Examples.NewVersion | ||
{ | ||
public class KernelMemory | ||
{ | ||
public static async Task Run() | ||
{ | ||
Console.WriteLine("Example from: https://github.com/microsoft/kernel-memory/blob/main/examples/101-using-core-nuget/Program.cs"); | ||
Console.Write("Please input your model path: "); | ||
var modelPath = Console.ReadLine(); | ||
var memory = new MemoryClientBuilder() | ||
.WithLLamaSharpDefaults(new LLamaSharpConfig(modelPath)) | ||
.With(new TextPartitioningOptions | ||
{ | ||
MaxTokensPerParagraph = 300, | ||
MaxTokensPerLine = 100, | ||
OverlappingTokens = 50 | ||
}) | ||
.BuildServerlessClient(); | ||
|
||
await memory.ImportDocumentAsync(@"./Asserts/sample-SK-Readme.pdf"); | ||
|
||
var question = "What's Semantic Kernel?"; | ||
|
||
Console.WriteLine($"\n\nQuestion: {question}"); | ||
|
||
var answer = await memory.AskAsync(question); | ||
|
||
Console.WriteLine($"\nAnswer: {answer.Result}"); | ||
|
||
Console.WriteLine("\n\n Sources:\n"); | ||
|
||
foreach (var x in answer.RelevantSources) | ||
{ | ||
Console.WriteLine($" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.SemanticMemory; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace LLamaSharp.KernelMemory | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for the MemoryClientBuilder class. | ||
/// </summary> | ||
public static class BuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds LLamaSharpTextEmbeddingGeneration to the MemoryClientBuilder. | ||
/// </summary> | ||
/// <param name="builder">The MemoryClientBuilder instance.</param> | ||
/// <param name="config">The LLamaSharpConfig instance.</param> | ||
/// <returns>The MemoryClientBuilder instance with LLamaSharpTextEmbeddingGeneration added.</returns> | ||
public static MemoryClientBuilder WithLLamaSharpTextEmbeddingGeneration(this MemoryClientBuilder builder, LLamaSharpConfig config) | ||
{ | ||
builder.WithCustomEmbeddingGeneration(new LLamaSharpTextEmbeddingGeneration(config)); | ||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds LLamaSharpTextGeneration to the MemoryClientBuilder. | ||
/// </summary> | ||
/// <param name="builder">The MemoryClientBuilder instance.</param> | ||
/// <param name="config">The LLamaSharpConfig instance.</param> | ||
/// <returns>The MemoryClientBuilder instance with LLamaSharpTextGeneration added.</returns> | ||
public static MemoryClientBuilder WithLLamaSharpTextGeneration(this MemoryClientBuilder builder, LLamaSharpConfig config) | ||
{ | ||
builder.WithCustomTextGeneration(new LlamaSharpTextGeneration(config)); | ||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds LLamaSharpTextEmbeddingGeneration and LLamaSharpTextGeneration to the MemoryClientBuilder. | ||
/// </summary> | ||
/// <param name="builder">The MemoryClientBuilder instance.</param> | ||
/// <param name="config">The LLamaSharpConfig instance.</param> | ||
/// <returns>The MemoryClientBuilder instance with LLamaSharpTextEmbeddingGeneration and LLamaSharpTextGeneration added.</returns> | ||
public static MemoryClientBuilder WithLLamaSharpDefaults(this MemoryClientBuilder builder, LLamaSharpConfig config) | ||
{ | ||
builder.WithLLamaSharpTextEmbeddingGeneration(config); | ||
builder.WithLLamaSharpTextGeneration(config); | ||
return builder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters