- Minor changes to cleanup some of the compiler warningstags/v0.5.1
| @@ -34,11 +34,11 @@ namespace LLama.Examples.NewVersion | |||||
| if (prompt == "save") | if (prompt == "save") | ||||
| { | { | ||||
| Console.Write("Your path to save model state: "); | Console.Write("Your path to save model state: "); | ||||
| string modelStatePath = Console.ReadLine(); | |||||
| var modelStatePath = Console.ReadLine(); | |||||
| ex.Context.SaveState(modelStatePath); | ex.Context.SaveState(modelStatePath); | ||||
| Console.Write("Your path to save executor state: "); | Console.Write("Your path to save executor state: "); | ||||
| string executorStatePath = Console.ReadLine(); | |||||
| var executorStatePath = Console.ReadLine(); | |||||
| ex.SaveState(executorStatePath); | ex.SaveState(executorStatePath); | ||||
| Console.ForegroundColor = ConsoleColor.Yellow; | Console.ForegroundColor = ConsoleColor.Yellow; | ||||
| @@ -7,6 +7,7 @@ using LLama.OldVersion; | |||||
| namespace LLama.Examples.Old | namespace LLama.Examples.Old | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class ChatSession | public class ChatSession | ||||
| { | { | ||||
| LLama.OldVersion.ChatSession<LLama.OldVersion.LLamaModel> _session; | LLama.OldVersion.ChatSession<LLama.OldVersion.LLamaModel> _session; | ||||
| @@ -7,6 +7,7 @@ using LLama.OldVersion; | |||||
| namespace LLama.Examples.Old | namespace LLama.Examples.Old | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class ChatWithLLamaModel | public class ChatWithLLamaModel | ||||
| { | { | ||||
| LLama.OldVersion.LLamaModel _model; | LLama.OldVersion.LLamaModel _model; | ||||
| @@ -7,6 +7,7 @@ using LLama.OldVersion; | |||||
| namespace LLama.Examples.Old | namespace LLama.Examples.Old | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class GetEmbeddings | public class GetEmbeddings | ||||
| { | { | ||||
| LLama.OldVersion.LLamaEmbedder _embedder; | LLama.OldVersion.LLamaEmbedder _embedder; | ||||
| @@ -7,6 +7,7 @@ using LLama.OldVersion; | |||||
| namespace LLama.Examples.Old | namespace LLama.Examples.Old | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class InstructMode | public class InstructMode | ||||
| { | { | ||||
| LLama.OldVersion.LLamaModel _model; | LLama.OldVersion.LLamaModel _model; | ||||
| @@ -7,6 +7,7 @@ using LLama.OldVersion; | |||||
| namespace LLama.Examples.Old | namespace LLama.Examples.Old | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class SaveAndLoadState: IDisposable | public class SaveAndLoadState: IDisposable | ||||
| { | { | ||||
| LLama.OldVersion.LLamaModel _model; | LLama.OldVersion.LLamaModel _model; | ||||
| @@ -367,7 +367,7 @@ namespace LLama | |||||
| public int MatchingSessionTokensCount { get; set; } | public int MatchingSessionTokensCount { get; set; } | ||||
| [JsonPropertyName("path_session")] | [JsonPropertyName("path_session")] | ||||
| public string SessionFilePath { get; set; } | |||||
| public string? SessionFilePath { get; set; } | |||||
| [JsonPropertyName("embd")] | [JsonPropertyName("embd")] | ||||
| public List<llama_token> Embeds { get; set; } | public List<llama_token> Embeds { get; set; } | ||||
| @@ -84,7 +84,7 @@ namespace LLama | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public override void SaveState(string filename) | public override void SaveState(string filename) | ||||
| { | { | ||||
| InstructExecutorState state = GetStateData() as InstructExecutorState; | |||||
| InstructExecutorState state = (InstructExecutorState)GetStateData(); | |||||
| using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) | using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) | ||||
| { | { | ||||
| JsonSerializer.Serialize<InstructExecutorState>(fs, state); | JsonSerializer.Serialize<InstructExecutorState>(fs, state); | ||||
| @@ -72,10 +72,10 @@ namespace LLama | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public override void SaveState(string filename) | public override void SaveState(string filename) | ||||
| { | { | ||||
| InteractiveExecutorState state = GetStateData() as InteractiveExecutorState; | |||||
| InteractiveExecutorState state = (InteractiveExecutorState)GetStateData(); | |||||
| using(FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) | using(FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) | ||||
| { | { | ||||
| JsonSerializer.Serialize<InteractiveExecutorState>(fs, state); | |||||
| JsonSerializer.Serialize(fs, state); | |||||
| } | } | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -121,7 +121,9 @@ namespace LLama | |||||
| /// <summary> | /// <summary> | ||||
| /// Return whether to break the generation. | /// Return whether to break the generation. | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="inferenceParams"></param> | |||||
| /// <param name="args"></param> | /// <param name="args"></param> | ||||
| /// <param name="extraOutputs"></param> | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| protected override bool PostProcess(IInferenceParams inferenceParams, InferStateArgs args, out IEnumerable<string>? extraOutputs) | protected override bool PostProcess(IInferenceParams inferenceParams, InferStateArgs args, out IEnumerable<string>? extraOutputs) | ||||
| { | { | ||||
| @@ -64,7 +64,7 @@ namespace LLama.Native | |||||
| /// Return NULL on failure | /// Return NULL on failure | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="path_model"></param> | /// <param name="path_model"></param> | ||||
| /// <param name="params_"></param> | |||||
| /// <param name="params"></param> | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] | [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)] | ||||
| public static extern IntPtr llama_load_model_from_file(string path_model, LLamaContextParams @params); | public static extern IntPtr llama_load_model_from_file(string path_model, LLamaContextParams @params); | ||||
| @@ -1,10 +1,12 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.IO; | using System.IO; | ||||
| using System.Text; | |||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class ChatSession<T> where T : IChatModel | public class ChatSession<T> where T : IChatModel | ||||
| { | { | ||||
| IChatModel _model; | IChatModel _model; | ||||
| @@ -1,9 +1,11 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | |||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public interface IChatModel | public interface IChatModel | ||||
| { | { | ||||
| string Name { get; } | string Name { get; } | ||||
| @@ -1,12 +1,14 @@ | |||||
| using LLama.Native; | using LLama.Native; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| using LLama.Exceptions; | using LLama.Exceptions; | ||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| public class LLamaEmbedder : IDisposable | |||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class LLamaEmbedder | |||||
| : IDisposable | |||||
| { | { | ||||
| SafeLLamaContextHandle _ctx; | SafeLLamaContextHandle _ctx; | ||||
| @@ -9,10 +9,15 @@ using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using LLama.Common; | using LLama.Common; | ||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| using llama_token = Int32; | using llama_token = Int32; | ||||
| public class LLamaModel : IChatModel, IDisposable | |||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public class LLamaModel | |||||
| : IChatModel, IDisposable | |||||
| { | { | ||||
| LLamaParams _params; | LLamaParams _params; | ||||
| SafeLLamaContextHandle _ctx; | SafeLLamaContextHandle _ctx; | ||||
| @@ -1,9 +1,13 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| using llama_token = Int32; | using llama_token = Int32; | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public struct LLamaParams | public struct LLamaParams | ||||
| { | { | ||||
| public int seed; // RNG seed | public int seed; // RNG seed | ||||
| @@ -1,6 +1,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | |||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| @@ -9,33 +10,49 @@ namespace LLama.OldVersion | |||||
| Human, | Human, | ||||
| Assistant | Assistant | ||||
| } | } | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record EmbeddingUsage(int PromptTokens, int TotalTokens); | public record EmbeddingUsage(int PromptTokens, int TotalTokens); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record EmbeddingData(int Index, string Object, float[] Embedding); | public record EmbeddingData(int Index, string Object, float[] Embedding); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record Embedding(string Object, string Model, EmbeddingData[] Data, EmbeddingUsage Usage); | public record Embedding(string Object, string Model, EmbeddingData[] Data, EmbeddingUsage Usage); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record CompletionLogprobs(int[] TextOffset, float[] TokenLogProbs, string[] Tokens, Dictionary<string, float>[] TopLogprobs); | public record CompletionLogprobs(int[] TextOffset, float[] TokenLogProbs, string[] Tokens, Dictionary<string, float>[] TopLogprobs); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record CompletionChoice(string Text, int Index, CompletionLogprobs? Logprobs, string? FinishReason); | public record CompletionChoice(string Text, int Index, CompletionLogprobs? Logprobs, string? FinishReason); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record CompletionUsage(int PromptTokens, int CompletionTokens, int TotalTokens); | public record CompletionUsage(int PromptTokens, int CompletionTokens, int TotalTokens); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record CompletionChunk(string Id, string Object, int Created, string Model, CompletionChoice[] Choices); | public record CompletionChunk(string Id, string Object, int Created, string Model, CompletionChoice[] Choices); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record Completion(string Id, string Object, int Created, string Model, CompletionChoice[] Choices, CompletionUsage Usage); | public record Completion(string Id, string Object, int Created, string Model, CompletionChoice[] Choices, CompletionUsage Usage); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletionMessage(ChatRole Role, string Content, string? Name = null); | public record ChatCompletionMessage(ChatRole Role, string Content, string? Name = null); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletionChoice(int Index, ChatCompletionMessage Message, string? FinishReason); | public record ChatCompletionChoice(int Index, ChatCompletionMessage Message, string? FinishReason); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletion(string Id, string Object, int Created, string Model, ChatCompletionChoice[] Choices, CompletionUsage Usage); | public record ChatCompletion(string Id, string Object, int Created, string Model, ChatCompletionChoice[] Choices, CompletionUsage Usage); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletionChunkDelta(string? Role, string? Content); | public record ChatCompletionChunkDelta(string? Role, string? Content); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletionChunkChoice(int Index, ChatCompletionChunkDelta Delta, string? FinishReason); | public record ChatCompletionChunkChoice(int Index, ChatCompletionChunkDelta Delta, string? FinishReason); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatCompletionChunk(string Id, string Model, string Object, int Created, ChatCompletionChunkChoice[] Choices); | public record ChatCompletionChunk(string Id, string Model, string Object, int Created, ChatCompletionChunkChoice[] Choices); | ||||
| [Obsolete("The entire LLama.OldVersion namespace will be removed")] | |||||
| public record ChatMessageRecord(ChatCompletionMessage Message, DateTime Time); | public record ChatMessageRecord(ChatCompletionMessage Message, DateTime Time); | ||||
| } | } | ||||
| @@ -3,14 +3,16 @@ using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using LLama.Exceptions; | using LLama.Exceptions; | ||||
| using System.Diagnostics; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Runtime.InteropServices; | using System.Runtime.InteropServices; | ||||
| using System.IO; | using System.IO; | ||||
| #pragma warning disable | |||||
| namespace LLama.OldVersion | namespace LLama.OldVersion | ||||
| { | { | ||||
| using llama_token = Int32; | using llama_token = Int32; | ||||
| internal static class Utils | internal static class Utils | ||||
| { | { | ||||
| public static SafeLLamaContextHandle llama_init_from_gpt_params(ref LLamaParams @params) | public static SafeLLamaContextHandle llama_init_from_gpt_params(ref LLamaParams @params) | ||||
| @@ -9,6 +9,7 @@ using LLama.Extensions; | |||||
| namespace LLama | namespace LLama | ||||
| { | { | ||||
| using llama_token = Int32; | using llama_token = Int32; | ||||
| public static class Utils | public static class Utils | ||||
| { | { | ||||
| public static SafeLLamaContextHandle InitLLamaContextFromModelParams(IModelParams @params) | public static SafeLLamaContextHandle InitLLamaContextFromModelParams(IModelParams @params) | ||||
| @@ -20,13 +21,17 @@ namespace LLama | |||||
| } | } | ||||
| [Obsolete("Use SafeLLamaContextHandle Tokenize method instead")] | [Obsolete("Use SafeLLamaContextHandle Tokenize method instead")] | ||||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | |||||
| public static IEnumerable<llama_token> Tokenize(SafeLLamaContextHandle ctx, string text, bool add_bos, Encoding encoding) | public static IEnumerable<llama_token> Tokenize(SafeLLamaContextHandle ctx, string text, bool add_bos, Encoding encoding) | ||||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | |||||
| { | { | ||||
| return ctx.Tokenize(text, add_bos, encoding); | return ctx.Tokenize(text, add_bos, encoding); | ||||
| } | } | ||||
| [Obsolete("Use SafeLLamaContextHandle GetLogits method instead")] | [Obsolete("Use SafeLLamaContextHandle GetLogits method instead")] | ||||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | |||||
| public static Span<float> GetLogits(SafeLLamaContextHandle ctx, int length) | public static Span<float> GetLogits(SafeLLamaContextHandle ctx, int length) | ||||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | |||||
| { | { | ||||
| if (length != ctx.VocabCount) | if (length != ctx.VocabCount) | ||||
| throw new ArgumentException("length must be the VocabSize"); | throw new ArgumentException("length must be the VocabSize"); | ||||
| @@ -35,33 +40,41 @@ namespace LLama | |||||
| } | } | ||||
| [Obsolete("Use SafeLLamaContextHandle Eval method instead")] | [Obsolete("Use SafeLLamaContextHandle Eval method instead")] | ||||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | |||||
| public static int Eval(SafeLLamaContextHandle ctx, llama_token[] tokens, int startIndex, int n_tokens, int n_past, int n_threads) | public static int Eval(SafeLLamaContextHandle ctx, llama_token[] tokens, int startIndex, int n_tokens, int n_past, int n_threads) | ||||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | |||||
| { | { | ||||
| var slice = tokens.AsSpan().Slice(startIndex, n_tokens); | var slice = tokens.AsSpan().Slice(startIndex, n_tokens); | ||||
| return ctx.Eval(slice, n_past, n_threads) ? 0 : 1; | return ctx.Eval(slice, n_past, n_threads) ? 0 : 1; | ||||
| } | } | ||||
| [Obsolete("Use SafeLLamaContextHandle TokenToString method instead")] | [Obsolete("Use SafeLLamaContextHandle TokenToString method instead")] | ||||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | |||||
| public static string TokenToString(llama_token token, SafeLLamaContextHandle ctx, Encoding encoding) | public static string TokenToString(llama_token token, SafeLLamaContextHandle ctx, Encoding encoding) | ||||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | |||||
| { | { | ||||
| return ctx.TokenToString(token, encoding); | return ctx.TokenToString(token, encoding); | ||||
| } | } | ||||
| [Obsolete("No longer used internally by LlamaSharp")] | [Obsolete("No longer used internally by LlamaSharp")] | ||||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | |||||
| public static string PtrToString(IntPtr ptr, Encoding encoding) | public static string PtrToString(IntPtr ptr, Encoding encoding) | ||||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | |||||
| { | { | ||||
| #if NET6_0_OR_GREATER | #if NET6_0_OR_GREATER | ||||
| // ReSharper disable once PossibleUnintendedReferenceComparison | |||||
| if(encoding == Encoding.UTF8) | if(encoding == Encoding.UTF8) | ||||
| { | { | ||||
| return Marshal.PtrToStringUTF8(ptr); | |||||
| return Marshal.PtrToStringUTF8(ptr)!; | |||||
| } | } | ||||
| // ReSharper disable once PossibleUnintendedReferenceComparison | |||||
| else if(encoding == Encoding.Unicode) | else if(encoding == Encoding.Unicode) | ||||
| { | { | ||||
| return Marshal.PtrToStringUni(ptr); | |||||
| return Marshal.PtrToStringUni(ptr)!; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| return Marshal.PtrToStringAuto(ptr); | |||||
| return Marshal.PtrToStringAuto(ptr)!; | |||||
| } | } | ||||
| #else | #else | ||||
| unsafe | unsafe | ||||