Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit fbce228

Browse files
committed
Add some more code comments
1 parent ba39bdd commit fbce228

File tree

13 files changed

+139
-9
lines changed

13 files changed

+139
-9
lines changed
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
namespace LLamaStack.Core.Common
1+

2+
namespace LLamaStack.Core.Common
23
{
4+
/// <summary>
5+
/// LLamaSharp executor type
6+
/// </summary>
37
public enum ExecutorType
48
{
9+
10+
/// <summary>
11+
/// The interactive executor, for more personal type chatbot interaction
12+
/// </summary>
513
Interactive = 0,
14+
15+
16+
/// <summary>
17+
/// The instruct executor, good for instruction/response type interaction
18+
/// </summary>
619
Instruct = 1,
20+
21+
22+
/// <summary>
23+
/// The stateless executor, holds no state or context during interaction
24+
/// </summary>
725
Stateless = 2
826
}
927
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
namespace LLamaStack.Core.Common
22
{
3+
/// <summary>
4+
/// The type of model load caching to use
5+
/// </summary>
36
public enum ModelLoadType
47
{
8+
9+
/// <summary>
10+
/// Only one model will be loaded into memory at a time, any other models will be unloaded before the new one is loaded
11+
/// </summary>
512
Single = 0,
13+
14+
/// <summary>
15+
/// Multiple models will be loaded into memory, ensure you use the ModelConfigs to split the hardware resources
16+
/// </summary>
617
Multiple = 1,
18+
19+
/// <summary>
20+
/// The first model in the appsettings.json list will be preloaded into memory at app startup
21+
/// </summary>
722
PreloadSingle = 2,
23+
24+
25+
/// <summary>
26+
/// All models in the appsettings.json list will be preloaded into memory at app startup, ensure you use the ModelConfigs to split the hardware resources
27+
/// </summary>
828
PreloadMultiple = 3,
929
}
1030
}

LLamaStack.Core/Common/SamplerType.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
namespace LLamaStack.Core.Common
1+

2+
namespace LLamaStack.Core.Common
23
{
4+
/// <summary>
5+
/// The type of token sampling algo to use
6+
/// </summary>
37
public enum SamplerType
48
{
59
/// <summary>

LLamaStack.Core/Extensions/Extensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace LLamaStack.Core.Extensions
99
{
1010
public static class Extensions
1111
{
12+
13+
/// <summary>
14+
/// Converts an IModelConfig to IModelParams.
15+
/// </summary>
16+
/// <param name="modelConfig">The model configuration.</param>
1217
public static IModelParams ToModelParams(this IModelConfig modelConfig)
1318
{
1419
return new ModelParams(modelConfig.ModelPath)
@@ -72,7 +77,6 @@ public static InferenceParams ToInferenceParams(this IInferenceConfig inferenceC
7277
/// Converts SamplerType to MirostatType.
7378
/// </summary>
7479
/// <param name="samplerType">Type of the sampler.</param>
75-
/// <returns></returns>
7680
public static MirostatType ToMirostatType(this SamplerType samplerType)
7781
{
7882
return samplerType switch

LLamaStack.Core/LLamaStackContext.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,79 @@
22

33
namespace LLamaStack.Core
44
{
5+
/// <summary>
6+
/// Wrapper class for LLamaSharp LLamaContext
7+
/// </summary>
8+
/// <seealso cref="System.IDisposable" />
59
public class LLamaStackContext : IDisposable
610
{
711
private readonly LLamaContext _context;
812

13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="LLamaStackContext"/> class.
15+
/// </summary>
16+
/// <param name="context">The context.</param>
917
public LLamaStackContext(LLamaContext context)
1018
{
1119
_context = context;
1220
}
1321

22+
23+
/// <summary>
24+
/// Gets the LLamaSharp context.
25+
/// </summary>
1426
public LLamaContext LLamaContext => _context;
1527

28+
29+
/// <summary>
30+
/// Gets the size of the context.
31+
/// </summary>
1632
public int ContextSize => _context.ContextSize;
1733

34+
35+
/// <summary>
36+
/// Loads the state.
37+
/// </summary>
38+
/// <param name="filename">The filename.</param>
1839
public void LoadState(string filename)
1940
{
2041
_context.LoadState(filename);
2142
}
2243

44+
45+
/// <summary>
46+
/// Loads the state asynchronous.
47+
/// </summary>
48+
/// <param name="filename">The filename.</param>
2349
public async Task LoadStateAsync(string filename)
2450
{
2551
await Task.Run(() => LoadState(filename));
2652
}
2753

54+
55+
/// <summary>
56+
/// Saves the state.
57+
/// </summary>
58+
/// <param name="filename">The filename.</param>
2859
public void SaveState(string filename)
2960
{
3061
_context.SaveState(filename);
3162
}
3263

64+
65+
/// <summary>
66+
/// Saves the state asynchronous.
67+
/// </summary>
68+
/// <param name="filename">The filename.</param>
3369
public async Task SaveStateAsync(string filename)
3470
{
3571
await Task.Run(() => SaveState(filename));
3672
}
3773

74+
75+
/// <summary>
76+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
77+
/// </summary>
3878
public void Dispose()
3979
{
4080
_context?.Dispose();

LLamaStack.Core/LLamaStackModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class LLamaStackModel<T> : IDisposable
1717
private readonly LLamaWeights _weights;
1818
private readonly ConcurrentDictionary<T, LLamaStackContext> _contexts;
1919

20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="LLamaStackModel{T}"/> class.
22+
/// </summary>
23+
/// <param name="modelParams">The model parameters.</param>
2024
public LLamaStackModel(ModelConfig modelParams)
2125
{
2226
_config = modelParams;

LLamaStack.Core/Registration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace LLamaStack.Core
66
{
7+
/// <summary>
8+
/// .NET Core Service and Dependancy Injection registration helpers
9+
/// </summary>
710
public static class Registration
811
{
912

LLamaStack.Core/Services/IModelSessionService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
namespace LLamaStack.Core.Services
55
{
6+
/// <summary>
7+
/// Service for ineraticng with ModelSessions
8+
/// </summary>
9+
/// <typeparam name="T">Type used to identify contexts</typeparam>
610
public interface IModelSessionService<T> where T : IEquatable<T>, IComparable<T>
711
{
812

LLamaStack.Core/Services/IModelSessionStateService.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,48 @@
22

33
namespace LLamaStack.Core.Services
44
{
5+
/// <summary>
6+
/// Service for handling Loading and Saving of a ModelSessions state
7+
/// </summary>
8+
/// <typeparam name="T">Type used to identify contexts</typeparam>
59
public interface IModelSessionStateService<T> where T : IEquatable<T>, IComparable<T>
610
{
11+
12+
/// <summary>
13+
/// Gets the ModelSessionState with the specified identifier.
14+
/// </summary>
15+
/// <param name="sessionId">The session identifier.</param>
716
Task<ModelSessionState<T>> GetAsync(T sessionId);
17+
18+
19+
/// <summary>
20+
/// Gets all ModelSessionStates.
21+
/// </summary>
22+
/// <returns></returns>
823
Task<IEnumerable<ModelSessionState<T>>> GetAllAsync();
24+
25+
26+
/// <summary>
27+
/// Removes the ModelSessionState with the specified identifier.
28+
/// </summary>
29+
/// <param name="sessionId">The session identifier.</param>
930
Task<bool> RemoveAsync(T sessionId);
31+
32+
33+
/// <summary>
34+
/// Loads the ModelSessionState with the specified identifier.
35+
/// </summary>
36+
/// <param name="sessionId">The session identifier.</param>
37+
/// <param name="cancellationToken">The cancellation token.</param>
1038
Task<ModelSessionState<T>> LoadAsync(T sessionId, CancellationToken cancellationToken = default);
39+
40+
41+
/// <summary>
42+
/// Saves the specified ModelSessionState.
43+
/// </summary>
44+
/// <param name="sessionId">The session identifier.</param>
45+
/// <param name="session">The session.</param>
46+
/// <param name="cancellationToken">The cancellation token.</param>
1147
Task<ModelSessionState<T>> SaveAsync(T sessionId, ModelSession<T> session, CancellationToken cancellationToken = default);
1248
}
1349
}

LLamaStack.Core/Services/ModelSessionStateService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public ModelSessionStateService(ILogger<ModelSessionStateService<T>> logger, LLa
4747
}
4848

4949

50+
5051
/// <summary>
51-
/// Gets ModleSessionState by id.
52+
/// Gets the ModelSessionState with the specified identifier.
5253
/// </summary>
5354
/// <param name="sessionId">The session identifier.</param>
5455
/// <returns></returns>

0 commit comments

Comments
 (0)