Skip to content

Commit 892d345

Browse files
committed
C# signature functions
1 parent 41a8b8d commit 892d345

4 files changed

Lines changed: 24 additions & 21 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
build*/*
44
csharp/bin
55
csharp/obj
6+
tests/csharp/bin
7+
tests/csharp/obj
8+
tests/csharp/TestResults

csharp/LLM.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected LLMProvider(LlamaLib llamaLibInstance) : base(llamaLibInstance)
134134
{
135135
}
136136

137-
public string Lora_Weight(string jsonData)
137+
public string LoraWeight(string jsonData)
138138
{
139139
if (string.IsNullOrEmpty(jsonData))
140140
throw new ArgumentNullException(nameof(jsonData));
@@ -145,7 +145,7 @@ public string Lora_Weight(string jsonData)
145145
return Marshal.PtrToStringAnsi(result) ?? string.Empty;
146146
}
147147

148-
public string Lora_List()
148+
public string LoraList()
149149
{
150150
CheckLlamaLib();
151151

@@ -174,7 +174,7 @@ public void Stop()
174174
llamaLib.LLM_Stop(llm);
175175
}
176176

177-
public void Start_Server(string host = "0.0.0.0", int port = 0, string apiKey = "")
177+
public void StartServer(string host = "0.0.0.0", int port = 0, string apiKey = "")
178178
{
179179
CheckLlamaLib();
180180

@@ -184,14 +184,14 @@ public void Start_Server(string host = "0.0.0.0", int port = 0, string apiKey =
184184
llamaLib.LLM_Start_Server(llm, host, port, apiKey ?? string.Empty);
185185
}
186186

187-
public void Stop_Server()
187+
public void StopServer()
188188
{
189189
CheckLlamaLib();
190190

191191
llamaLib.LLM_Stop_Server(llm);
192192
}
193193

194-
public void Join_Service()
194+
public void JoinService()
195195
{
196196
CheckLlamaLib();
197197

@@ -205,7 +205,7 @@ public void JoinServer()
205205
llamaLib.LLM_Join_Server(llm);
206206
}
207207

208-
public void Set_SSL(string sslCert, string sslKey)
208+
public void SetSSL(string sslCert, string sslKey)
209209
{
210210
if (string.IsNullOrEmpty(sslCert))
211211
throw new ArgumentNullException(nameof(sslCert));
@@ -217,25 +217,22 @@ public void Set_SSL(string sslCert, string sslKey)
217217
llamaLib.LLM_Set_SSL(llm, sslCert, sslKey);
218218
}
219219

220-
public int Status_Code()
220+
public int StatusCode()
221221
{
222222
CheckLlamaLib();
223-
224223
return llamaLib.LLM_Status_Code(llm);
225224
}
226225

227-
public string Status_Message()
226+
public string StatusMessage()
228227
{
229228
CheckLlamaLib();
230-
231229
var result = llamaLib.LLM_Status_Message(llm);
232230
return Marshal.PtrToStringAnsi(result) ?? string.Empty;
233231
}
234232

235-
public int Embedding_Size()
233+
public int EmbeddingSize()
236234
{
237235
CheckLlamaLib();
238-
239236
return llamaLib.LLM_Embedding_Size(llm);
240237
}
241238

@@ -290,18 +287,19 @@ public LLMService(string modelPath, int numThreads = -1, int numGpuLayers = 0,
290287

291288
public LLMService(LlamaLib llamaLibInstance, IntPtr llmInstance)
292289
{
293-
llamaLib = llamaLibInstance ?? throw new ArgumentNullException(nameof(llamaLibInstance));
290+
if (llamaLibInstance == null) throw new ArgumentNullException(nameof(llamaLibInstance));
294291
if (llmInstance == IntPtr.Zero) throw new ArgumentNullException(nameof(llmInstance));
292+
llamaLib = llamaLibInstance;
295293
llm = llmInstance;
296294
}
297295

298-
public static LLMService From_Command(string paramsString)
296+
public static LLMService FromCommand(string paramsString)
299297
{
300298
if (string.IsNullOrEmpty(paramsString))
301299
throw new ArgumentNullException(nameof(paramsString));
302300

303301
LlamaLib llamaLibInstance = null;
304-
IntPtr llmInstance;
302+
IntPtr llmInstance = IntPtr.Zero;
305303
try
306304
{
307305
llamaLibInstance = new LlamaLib(LlamaLib.Has_GPU_Layers(paramsString));

csharp/LlamaLib.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ private void LoadLibraries(bool gpu)
259259
try
260260
{
261261
string libraryPath = Path.Combine(libraryBasePath, library.Trim());
262+
Console.WriteLine("Trying " + libraryPath);
262263
libraryHandle = LibraryLoader.LoadLibrary(libraryPath);
263264
LoadFunctionPointers();
264265
architecture = library.Trim();
266+
Console.WriteLine("Successfully loaded: " + libraryPath);
265267
return;
266268
}
267269
catch (Exception ex)

tests/csharp/Tests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,26 @@ public void Tests_LLMService()
215215
TestStart(llmService.Start, llmService.Started);
216216
TestTokenization(llmService.Tokenize, llmService.Detokenize);
217217
TestCompletion(llmService.Completion);
218-
TestEmbedding(llmService.Embeddings, llmService.Embedding_Size);
218+
TestEmbedding(llmService.Embeddings, llmService.EmbeddingSize);
219219
TestCancel(llmService.Cancel);
220220
TestSlotSaveRestore(llmService.Slot);
221-
TestLoraList(llmService.Lora_List);
221+
TestLoraList(llmService.LoraList);
222222

223223
llmService?.Dispose();
224224
}
225225

226226
[TestMethod]
227227
public void Tests_LLMClient()
228228
{
229-
LLMService llmService = new LLMService(testModelPath);
229+
LLMService llmService = LLMService.FromCommand(new String("-m " + testModelPath));
230230
llmService.Debug(3);
231231
TestStart(llmService.Start, llmService.Started);
232232

233233
LLMClient llmClient = new LLMClient(llmService);
234234

235235
TestTokenization(llmClient.Tokenize, llmClient.Detokenize);
236236
TestCompletion(llmClient.Completion);
237-
TestEmbedding(llmClient.Embeddings, llmService.Embedding_Size);
237+
TestEmbedding(llmClient.Embeddings, llmService.EmbeddingSize);
238238
TestCancel(llmClient.Cancel);
239239
TestSlotSaveRestore(llmClient.Slot);
240240

@@ -247,13 +247,13 @@ public void Tests_LLMRemoteClient()
247247
LLMService llmService = new LLMService(testModelPath);
248248
llmService.Debug(3);
249249
TestStart(llmService.Start, llmService.Started);
250-
llmService.Start_Server("", 13333);
250+
llmService.StartServer("", 13333);
251251

252252
LLMRemoteClient llmClient = new LLMRemoteClient("http://localhost", 13333);
253253

254254
TestTokenization(llmClient.Tokenize, llmClient.Detokenize);
255255
TestCompletion(llmClient.Completion);
256-
TestEmbedding(llmClient.Embeddings, llmService.Embedding_Size);
256+
TestEmbedding(llmClient.Embeddings, llmService.EmbeddingSize);
257257

258258
llmService?.Dispose();
259259
}

0 commit comments

Comments
 (0)