LLM for Unity  v3.0.0
Create characters in Unity with LLMs!
Loading...
Searching...
No Matches
IL2CPP.cs
1#if ENABLE_IL2CPP
2using System;
3using System.Runtime.InteropServices;
4using AOT;
5using UndreamAI.LlamaLib;
6
7namespace LLMUnity
8{
9 public class IL2CPP_Logging
10 {
11 private static Action<string> onLogging;
12 private static LlamaLib.CharArrayCallback nativeLoggingThunk;
13
14 public static void LoggingCallback(Action<string> callback)
15 {
16 onLogging = callback;
17 if (nativeLoggingThunk == null)
18 {
19 nativeLoggingThunk = LoggingThunkImpl;
20 LlamaLib.LoggingCallback(nativeLoggingThunk);
21 }
22 }
23
24 [MonoPInvokeCallback(typeof(LlamaLib.CharArrayCallback))]
25 private static void LoggingThunkImpl(IntPtr msg)
26 {
27 if (onLogging == null || msg == IntPtr.Zero)
28 return;
29 try
30 {
31 onLogging(Marshal.PtrToStringUTF8(msg));
32 }
33 catch {}
34 }
35 }
36
37 public class IL2CPP_Completion
38 {
39 private static Action<string> onCompletion;
40 private static LlamaLib.CharArrayCallback nativeCompletionThunk;
41
42 public static LlamaLib.CharArrayCallback CreateCallback(Action<string> callback)
43 {
44 onCompletion = callback;
45 if (nativeCompletionThunk == null)
46 {
47 nativeCompletionThunk = CompletionThunkImpl;
48 }
49 return nativeCompletionThunk;
50 }
51
52 [MonoPInvokeCallback(typeof(LlamaLib.CharArrayCallback))]
53 private static void CompletionThunkImpl(IntPtr msg)
54 {
55 if (onCompletion == null || msg == IntPtr.Zero)
56 return;
57 try
58 {
59 onCompletion(Marshal.PtrToStringUTF8(msg));
60 }
61 catch {}
62 }
63 }
64}
65#endif