Skip to content

Commit

Permalink
Merge pull request #295 from xbotter/patch/examples
Browse files Browse the repository at this point in the history
Update examples
  • Loading branch information
martindevans authored Nov 15, 2023
2 parents 36c2e64 + 521e369 commit 0bfc1cb
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using LLama.Common;
using LLama.Native;

namespace LLama.Examples.NewVersion;
namespace LLama.Examples.Examples;

/// <summary>
/// This demonstrates generating multiple replies to the same prompt, with a shared cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class ChatSessionStripRoleName
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class ChatSessionWithRoleName
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
using LLama.Common;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class GetEmbeddings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LLama.Common;
using LLama.Grammars;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class GrammarJsonResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class InstructModeExecute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class InteractiveModeExecute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Handlers;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class KernelMemory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class SaveAndLoadSession
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class LoadAndSaveState
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class QuantizeModel
{
Expand Down
53 changes: 53 additions & 0 deletions LLama.Examples/Examples/Runner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Spectre.Console;

namespace LLama.Examples.Examples;

public class Runner
{
static Dictionary<string, Func<Task>> Examples = new()
{
{"Run a chat session without stripping the role names.", () => ChatSessionWithRoleName.Run()},
{"Run a chat session with the role names stripped.",()=> ChatSessionStripRoleName.Run()},
{"Interactive mode chat by using executor.",()=> InteractiveModeExecute.Run()},
{"Instruct mode chat by using executor.",()=> InstructModeExecute.Run()},
{"Stateless mode chat by using executor.",()=> StatelessModeExecute.Run()},
{"Load and save chat session.",()=> SaveAndLoadSession.Run()},
{"Load and save state of model and executor.",()=> LoadAndSaveState.Run()},
{"Get embeddings from LLama model.",()=> Task.Run(GetEmbeddings.Run)},
{"Quantize the model.",()=> Task.Run(QuantizeModel.Run)},
{"Automatic conversation.",()=> TalkToYourself.Run()},
{"Constrain response to json format using grammar.",()=> GrammarJsonResponse.Run()},
{"Semantic Kernel Prompt.",()=> SemanticKernelPrompt.Run()},
{"Semantic Kernel Chat.",()=> SemanticKernelChat.Run()},
{"Semantic Kernel Memory.",()=> SemanticKernelMemory.Run()},
{"Coding Assistant.",()=> CodingAssistant.Run()},
{"Batch Decoding.",()=> BatchedDecoding.Run()},
{"SK Kernel Memory.",()=> KernelMemory.Run()},
{"Exit", ()=> Task.CompletedTask}
};
public static async Task Run()
{
AnsiConsole.Write(new Rule("LLamaSharp Examples"));

while (true)
{
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Please choose[green] an example[/] to run: ")
.AddChoices(Examples.Keys));


if (Examples.TryGetValue(choice, out var example))
{
if (choice == "Exit")
{
break;
}
AnsiConsole.Write(new Rule(choice));
await example();
}

AnsiConsole.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.SemanticKernel.AI.ChatCompletion;
using LLamaSharp.SemanticKernel.ChatCompletion;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class SemanticKernelChat
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Plugins.Memory;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class SemanticKernelMemory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.SemanticKernel.AI.TextCompletion;
using LLamaSharp.SemanticKernel.TextCompletion;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class SemanticKernelPrompt
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LLama.Common;
using LLama.Examples.Extensions;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class StatelessModeExecute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using LLama.Abstractions;
using LLama.Common;

namespace LLama.Examples.NewVersion
namespace LLama.Examples.Examples
{
public class TalkToYourself
{
Expand Down
112 changes: 0 additions & 112 deletions LLama.Examples/NewVersion/TestRunner.cs

This file was deleted.

4 changes: 2 additions & 2 deletions LLama.Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LLama.Examples.NewVersion;
using LLama.Examples.Examples;
using LLama.Native;

Console.WriteLine("======================================================================================================");
Expand All @@ -12,4 +12,4 @@
NativeApi.llama_empty_call();
Console.WriteLine();

await NewVersionTestRunner.Run();
await Runner.Run();

0 comments on commit 0bfc1cb

Please sign in to comment.