Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laves committed Jan 27, 2025
1 parent 48fb86d commit 869eacf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/dotnet-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ jobs:

# ************** REMOVE AFTER RELEASE ********************
- name: Remove local package
if: ${{ matrix.machine != 'pv-windows' && matrix.machine != 'pv-windows-igpu' && matrix.machine != 'pv-windows-arm64' }}
run: rm -rf ~/.nuget/packages/picollm

- name: Remove local package
if: ${{ matrix.machine == 'pv-windows' && matrix.machine == 'pv-windows-igpu' && matrix.machine == 'pv-windows-arm64' }}
run: rm ~/.nuget/packages/picollm -r -force

- name: Build Local Packages
run: dotnet build && dotnet pack -c Release
working-directory: binding/dotnet/PicoLLM
Expand Down
6 changes: 4 additions & 2 deletions binding/dotnet/PicoLLM/PicoLLM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ public class PicoLLM : IDisposable
{
private const string LIBRARY = "libpv_picollm";
private IntPtr _libraryPointer = IntPtr.Zero;
private Action<string> _streamCallback;

private delegate void PicoLLMStreamCallbackDelegate(IntPtr token, IntPtr userData);
private PicoLLMStreamCallbackDelegate streamCallbackDelegate = new PicoLLMStreamCallbackDelegate(StreamCallbackWrapper);

private Action<string> _streamCallback;

static PicoLLM()
{
Expand Down Expand Up @@ -593,7 +595,6 @@ public PicoLLMCompletion Generate(

_streamCallback = streamCallback;

PicoLLMStreamCallbackDelegate streamCallbackDelegate = new PicoLLMStreamCallbackDelegate(StreamCallbackWrapper);
IntPtr streamCallbackPtr = Marshal.GetFunctionPointerForDelegate(streamCallbackDelegate);

CPicoLLMUsage cUsage;
Expand Down Expand Up @@ -939,6 +940,7 @@ public void Dispose()
{
pv_picollm_delete(_libraryPointer);
_libraryPointer = IntPtr.Zero;
_streamCallback = null;

// ensures finalizer doesn't trigger if already manually disposed
GC.SuppressFinalize(this);
Expand Down
27 changes: 11 additions & 16 deletions demo/dotnet/PicoLLMDemo/ChatDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace PicoLLMDemo
{
public class ChatDemo
{
private static Action<string> streamCallback;

public static void RunDemo(
string accessKey,
string modelPath,
Expand Down Expand Up @@ -56,12 +54,11 @@ public static void RunDemo(
dialog.AddHumanRequest(prompt);

bool isInterrupt = false;
PicoLLMCompletion response = null;
Task interruptKeyTask = Task.Run(async () =>
{
while (!isInterrupt && response == null)
while (!isInterrupt)
{
if (!Console.IsInputRedirected && Console.KeyAvailable)
if (Console.KeyAvailable)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(intercept: true);
if (keyInfo.Key == ConsoleKey.Spacebar)
Expand All @@ -75,16 +72,7 @@ public static void RunDemo(
}
});

streamCallback = (string token) =>
{
if (!isInterrupt)
{
Console.Write(token);
Console.Out.Flush();
}
};

response = picoLLM.Generate(
PicoLLMCompletion response = picoLLM.Generate(
dialog.Prompt(),
completionTokenLimit,
stopPhrases.ToArray(),
Expand All @@ -93,7 +81,14 @@ public static void RunDemo(
frequencyPenalty,
temperature,
topP,
streamCallback: streamCallback);
streamCallback: (string token) =>
{
if (!isInterrupt)
{
Console.Write(token);
Console.Out.Flush();
}
});

interruptKeyTask.Wait();
Console.WriteLine();
Expand Down
4 changes: 1 addition & 3 deletions demo/dotnet/PicoLLMDemo/CompletionDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace PicoLLMDemo
{
public class CompletionDemo
{
private static Action<string> streamCallback;

public static void RunDemo(
string accessKey,
string modelPath,
Expand Down Expand Up @@ -65,7 +63,7 @@ public static void RunDemo(
});

double startSec = 0.0;
streamCallback = (string token) =>
Action<string> streamCallback = (string token) =>
{
if (startSec == 0.0)
{
Expand Down

0 comments on commit 869eacf

Please sign in to comment.