From aa2b064d1d23fdbf36421469ffb7d7096d09f910 Mon Sep 17 00:00:00 2001 From: Yaohui Liu Date: Tue, 16 May 2023 02:51:02 +0800 Subject: [PATCH] fix: add IDisposable to model classes. --- LLama/GptModel.cs | 7 ++++++- LLama/LLamaEmbedder.cs | 7 ++++++- LLama/LLamaModel.cs | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/LLama/GptModel.cs b/LLama/GptModel.cs index 86985309..f29725b4 100644 --- a/LLama/GptModel.cs +++ b/LLama/GptModel.cs @@ -12,7 +12,7 @@ using System.Diagnostics; namespace LLama { using llama_token = Int32; - public class LLamaModel: IChatModel + public class LLamaModel: IChatModel, IDisposable { LLamaParams _params; SafeLLamaContextHandle _ctx; @@ -579,5 +579,10 @@ namespace LLama } } } + + public void Dispose() + { + _ctx.Dispose(); + } } } diff --git a/LLama/LLamaEmbedder.cs b/LLama/LLamaEmbedder.cs index 93139027..5ccde53a 100644 --- a/LLama/LLamaEmbedder.cs +++ b/LLama/LLamaEmbedder.cs @@ -6,7 +6,7 @@ using LLama.Exceptions; namespace LLama { - public class LLamaEmbedder + public class LLamaEmbedder: IDisposable { SafeLLamaContextHandle _ctx; @@ -60,5 +60,10 @@ namespace LLama span.CopyTo(res.AsSpan()); return res; } + + public void Dispose() + { + _ctx.Dispose(); + } } } diff --git a/LLama/LLamaModel.cs b/LLama/LLamaModel.cs index 29033ad3..c984a63d 100644 --- a/LLama/LLamaModel.cs +++ b/LLama/LLamaModel.cs @@ -22,7 +22,7 @@ namespace LLama /// is ok now. /// [Obsolete] - public class LLamaModelV1 + public class LLamaModelV1: IDisposable { private string _model_path; LLamaContextParams _params; @@ -828,5 +828,10 @@ namespace LLama } return longestPrefix; } + + public void Dispose() + { + _ctx.Dispose(); + } } }