- Passing `ILogger` into executorstags/v0.6.0
| @@ -17,7 +17,8 @@ namespace LLama | |||||
| /// <summary> | /// <summary> | ||||
| /// The LLama executor for instruct mode. | /// The LLama executor for instruct mode. | ||||
| /// </summary> | /// </summary> | ||||
| public class InstructExecutor : StatefulExecutorBase | |||||
| public class InstructExecutor | |||||
| : StatefulExecutorBase | |||||
| { | { | ||||
| private bool _is_prompt_run = true; | private bool _is_prompt_run = true; | ||||
| private readonly string _instructionPrefix; | private readonly string _instructionPrefix; | ||||
| @@ -28,11 +29,14 @@ namespace LLama | |||||
| /// | /// | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="context"></param> | /// <param name="context"></param> | ||||
| /// <param name="logger"></param> | |||||
| /// <param name="instructionPrefix"></param> | /// <param name="instructionPrefix"></param> | ||||
| /// <param name="instructionSuffix"></param> | /// <param name="instructionSuffix"></param> | ||||
| public InstructExecutor(LLamaContext context, ILogger logger = null!, string instructionPrefix = "\n\n### Instruction:\n\n", | |||||
| string instructionSuffix = "\n\n### Response:\n\n") : base(context) | |||||
| /// <param name="logger"></param> | |||||
| public InstructExecutor(LLamaContext context, | |||||
| string instructionPrefix = "\n\n### Instruction:\n\n", | |||||
| string instructionSuffix = "\n\n### Response:\n\n", | |||||
| ILogger? logger = null) | |||||
| : base(context, logger) | |||||
| { | { | ||||
| _inp_pfx = Context.Tokenize(instructionPrefix, true); | _inp_pfx = Context.Tokenize(instructionPrefix, true); | ||||
| _inp_sfx = Context.Tokenize(instructionSuffix, false); | _inp_sfx = Context.Tokenize(instructionSuffix, false); | ||||
| @@ -27,7 +27,8 @@ namespace LLama | |||||
| /// </summary> | /// </summary> | ||||
| /// <param name="context"></param> | /// <param name="context"></param> | ||||
| /// <param name="logger"></param> | /// <param name="logger"></param> | ||||
| public InteractiveExecutor(LLamaContext context) : base(context) | |||||
| public InteractiveExecutor(LLamaContext context, ILogger? logger = null) | |||||
| : base(context, logger) | |||||
| { | { | ||||
| _llama_token_newline = NativeApi.llama_token_nl(Context.NativeHandle); | _llama_token_newline = NativeApi.llama_token_nl(Context.NativeHandle); | ||||
| } | } | ||||
| @@ -21,9 +21,9 @@ namespace LLama | |||||
| public class StatelessExecutor | public class StatelessExecutor | ||||
| : ILLamaExecutor | : ILLamaExecutor | ||||
| { | { | ||||
| private readonly ILogger? _logger; | |||||
| private readonly LLamaWeights _weights; | private readonly LLamaWeights _weights; | ||||
| private readonly IContextParams _params; | private readonly IContextParams _params; | ||||
| private readonly ILogger? _logger; | |||||
| /// <summary> | /// <summary> | ||||
| /// The context used by the executor when running the inference. | /// The context used by the executor when running the inference. | ||||
| @@ -36,24 +36,25 @@ namespace LLama | |||||
| /// <param name="weights"></param> | /// <param name="weights"></param> | ||||
| /// <param name="params"></param> | /// <param name="params"></param> | ||||
| /// <param name="logger"></param> | /// <param name="logger"></param> | ||||
| public StatelessExecutor(LLamaWeights weights, IContextParams @params) | |||||
| public StatelessExecutor(LLamaWeights weights, IContextParams @params, ILogger? logger = null) | |||||
| { | { | ||||
| _weights = weights; | _weights = weights; | ||||
| _params = @params; | _params = @params; | ||||
| _logger = logger; | |||||
| Context = _weights.CreateContext(_params); | |||||
| Context = _weights.CreateContext(_params, logger); | |||||
| Context.Dispose(); | Context.Dispose(); | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async IAsyncEnumerable<string> InferAsync(string text, IInferenceParams? inferenceParams = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) | public async IAsyncEnumerable<string> InferAsync(string text, IInferenceParams? inferenceParams = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) | ||||
| { | { | ||||
| using var context = _weights.CreateContext(_params); | |||||
| using var context = _weights.CreateContext(_params, _logger); | |||||
| Context = context; | Context = context; | ||||
| if (!Context.NativeHandle.IsClosed) | if (!Context.NativeHandle.IsClosed) | ||||
| Context.Dispose(); | Context.Dispose(); | ||||
| Context = _weights.CreateContext(Context.Params); | |||||
| Context = _weights.CreateContext(Context.Params, _logger); | |||||
| if (inferenceParams != null) | if (inferenceParams != null) | ||||
| { | { | ||||
| @@ -81,10 +81,11 @@ namespace LLama | |||||
| /// Create a llama_context using this model | /// Create a llama_context using this model | ||||
| /// </summary> | /// </summary> | ||||
| /// <param name="params"></param> | /// <param name="params"></param> | ||||
| /// <param name="logger"></param> | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public LLamaContext CreateContext(IContextParams @params) | |||||
| public LLamaContext CreateContext(IContextParams @params, ILogger? logger = null) | |||||
| { | { | ||||
| return new LLamaContext(this, @params); | |||||
| return new LLamaContext(this, @params, logger); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||