Skip to content

Commit dcec12d

Browse files
authored
Merge pull request #1111 from Lyrcaxis/warnings-cleanup
Cleaned up non-important warnings from the error list
2 parents 7eccdcb + 02c882a commit dcec12d

22 files changed

+93
-52
lines changed

LLama.Examples/Examples/LlavaInteractiveModeExecute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static async Task Run()
9393
Console.WriteLine($"Here are the images, that are sent to the chat model in addition to your message.");
9494
Console.WriteLine();
9595

96-
foreach (var consoleImage in imageBytes?.Select(bytes => new CanvasImage(bytes)))
96+
foreach (var consoleImage in imageBytes?.Select(bytes => new CanvasImage(bytes)) ?? Array.Empty<CanvasImage>())
9797
{
9898
consoleImage.MaxWidth = 50;
9999
AnsiConsole.Write(consoleImage);

LLama.Examples/Examples/SemanticKernelHomeAutomation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static async Task Run()
6868
}
6969
}
7070

71-
class Worker(
71+
internal class Worker(
7272
IHostApplicationLifetime hostApplicationLifetime,
7373
[FromKeyedServices("HomeAutomationKernel")] Kernel kernel) : BackgroundService
7474
{
@@ -92,7 +92,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
9292
TopP = 0.1f
9393
};
9494

95-
string? input = null;
95+
string? input;
9696

9797
while ((input = Console.ReadLine()) != null)
9898
{
@@ -123,19 +123,19 @@ [WHICH LIGHT IS ON]
123123
ChatMessageContent chatResult = await chatCompletionService.GetChatMessageContentAsync(chatHistory, llamaSharpPromptExecutionSettings, _kernel, stoppingToken);
124124

125125
FunctionResult? fres = null;
126-
if (chatResult.Content.Contains("[TURN ON THE LIGHT]"))
126+
if (chatResult.Content!.Contains("[TURN ON THE LIGHT]"))
127127
{
128-
fres = await _kernel.InvokeAsync("OfficeLight", "TurnOn");
128+
fres = await _kernel.InvokeAsync("OfficeLight", "TurnOn", cancellationToken: stoppingToken);
129129
}
130130
else if (chatResult.Content.Contains("[TURN OFF THE LIGHT]"))
131131
{
132-
fres = await _kernel.InvokeAsync("OfficeLight", "TurnOff");
132+
fres = await _kernel.InvokeAsync("OfficeLight", "TurnOff", cancellationToken: stoppingToken);
133133
}
134134

135135
Console.ForegroundColor = ConsoleColor.Green;
136136
if (fres != null || chatResult.Content.Contains("[WHICH LIGHT IS ON]"))
137137
{
138-
fres = await _kernel.InvokeAsync("OfficeLight", "IsTurnedOn");
138+
fres = await _kernel.InvokeAsync("OfficeLight", "IsTurnedOn", cancellationToken: stoppingToken);
139139
Console.Write($">>> Result:\n {(fres.GetValue<bool>()==true?"The light is ON.": "The light is OFF.")}\n\n> ");
140140
}
141141
else
@@ -154,7 +154,7 @@ [WHICH LIGHT IS ON]
154154
/// Class that represents a controllable light.
155155
/// </summary>
156156
[Description("Represents a light")]
157-
class MyLightPlugin(bool turnedOn = false)
157+
internal class MyLightPlugin(bool turnedOn = false)
158158
{
159159
private bool _turnedOn = turnedOn;
160160

LLama.Examples/Examples/SemanticKernelMemory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public static async Task Run()
1515
Console.WriteLine("This example is from: \n" +
1616
"https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/KernelSyntaxExamples/Example14_SemanticMemory.cs");
1717

18-
var seed = 1337u;
1918
// Load weights into memory
2019
var parameters = new ModelParams(modelPath)
2120
{

LLama.Examples/LLama.Examples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="Microsoft.SemanticKernel" Version="1.29.0" />
2020
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.6.2-alpha" />
2121
<PackageReference Include="NAudio" Version="2.2.1" />
22+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
2223
<PackageReference Include="Spectre.Console" Version="0.49.1" />
2324
<PackageReference Include="Spectre.Console.ImageSharp" Version="0.49.1" />
2425
<PackageReference Include="Whisper.net" Version="1.7.4" />

LLama.Unittest/SemanticKernel/LLamaSharpChatCompletionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class LLamaSharpChatCompletionTests
1212

1313
public LLamaSharpChatCompletionTests()
1414
{
15-
this.mockStatelessExecutor = new Mock<ILLamaExecutor>();
15+
mockStatelessExecutor = new Mock<ILLamaExecutor>();
1616
}
1717

1818
private LLamaSharpChatCompletion CreateLLamaSharpChatCompletion()
1919
{
2020
return new LLamaSharpChatCompletion(
21-
this.mockStatelessExecutor.Object,
21+
mockStatelessExecutor.Object,
2222
null,
2323
null,
2424
null);
@@ -28,7 +28,7 @@ private LLamaSharpChatCompletion CreateLLamaSharpChatCompletion()
2828
public async Task GetChatMessageContentsAsync_StateUnderTest_ExpectedBehavior()
2929
{
3030
// Arrange
31-
var unitUnderTest = this.CreateLLamaSharpChatCompletion();
31+
var unitUnderTest = CreateLLamaSharpChatCompletion();
3232
ChatHistory chatHistory = new ChatHistory();
3333
PromptExecutionSettings? executionSettings = null;
3434
Kernel? kernel = null;
@@ -51,7 +51,7 @@ public async Task GetChatMessageContentsAsync_StateUnderTest_ExpectedBehavior()
5151
public async Task GetStreamingChatMessageContentsAsync_StateUnderTest_ExpectedBehavior()
5252
{
5353
// Arrange
54-
var unitUnderTest = this.CreateLLamaSharpChatCompletion();
54+
var unitUnderTest = CreateLLamaSharpChatCompletion();
5555
ChatHistory chatHistory = new ChatHistory();
5656
PromptExecutionSettings? executionSettings = null;
5757
Kernel? kernel = null;

LLama.Web/Pages/Error.cshtml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace LLama.Web.Pages
88
[IgnoreAntiforgeryToken]
99
public class ErrorModel : PageModel
1010
{
11-
public string? RequestId { get; set; }
11+
public string RequestId { get; set; }
1212

1313
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
1414

LLama/ChatSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ public static SessionState Load(string path)
779779

780780
return new SessionState(
781781
contextState,
782-
executorState,
782+
executorState!,
783783
history,
784784
inputTransforms.ToList(),
785785
outputTransform,

LLama/Common/ChatHistory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public class Message
6464
/// <param name="content">Message content</param>
6565
public Message(AuthorRole authorRole, string content)
6666
{
67-
this.AuthorRole = authorRole;
68-
this.Content = content;
67+
AuthorRole = authorRole;
68+
Content = content;
6969
}
7070
}
7171

@@ -87,7 +87,7 @@ public ChatHistory() { }
8787
/// <param name="messageHistory"></param>
8888
public ChatHistory(Message[] messageHistory)
8989
{
90-
this.Messages = messageHistory.ToList();
90+
Messages = messageHistory.ToList();
9191
}
9292

9393
/// <summary>
@@ -97,7 +97,7 @@ public ChatHistory(Message[] messageHistory)
9797
/// <param name="content">Message content</param>
9898
public void AddMessage(AuthorRole authorRole, string content)
9999
{
100-
this.Messages.Add(new Message(authorRole, content));
100+
Messages.Add(new Message(authorRole, content));
101101
}
102102

103103
/// <summary>

LLama/Common/PolymorphicJSONConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal class PolymorphicJSONConverter<T> : JsonConverter<T>
4545
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
4646
{
4747
writer.WriteStartObject();
48-
writer.WriteString("Name", value.GetType().Name);
48+
writer.WriteString("Name", value!.GetType().Name);
4949
writer.WritePropertyName("Data");
5050
JsonSerializer.Serialize(writer, value, value.GetType(), options);
5151
writer.WriteEndObject();

LLama/LLamaExecutorBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ protected class InferStateArgs
395395
public bool NeedToSaveSession { get; set; }
396396
}
397397

398+
#pragma warning disable CS1591, CS8618 // Missing XML and irrelevant nullable warnings
398399
[JsonConverter(typeof(PolymorphicJSONConverter<ExecutorBaseState>))]
399400
public class ExecutorBaseState
400401
{
@@ -431,5 +432,6 @@ public class ExecutorBaseState
431432
[JsonPropertyName("mirostat_mu")]
432433
public float? MirostatMu { get; set; }
433434
}
435+
#pragma warning restore
434436
}
435437
}

LLama/LLamaInstructExecutor.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public class InstructExecutor
2525
private LLamaToken[] _inp_pfx;
2626
private LLamaToken[] _inp_sfx;
2727

28-
private ISamplingPipeline? _pipeline;
29-
3028
/// <summary>
3129
///
3230
/// </summary>
@@ -72,17 +70,17 @@ public override Task LoadState(ExecutorBaseState data)
7270
if(data is InstructExecutorState state)
7371
{
7472
_n_session_consumed = state.ConsumedSessionCount;
75-
_embed_inps = state.EmbedInps.ToList();
73+
_embed_inps = state.EmbedInps!.ToList();
7674
_is_prompt_run = state.IsPromptRun;
7775
_consumedTokensCount = state.ConsumedTokensCount;
78-
_embeds = state.Embeds.ToList();
79-
_last_n_tokens = new FixedSizeQueue<LLamaToken>(state.LastTokensCapacity, state.LastTokens);
80-
_inp_pfx = state.InputPrefixTokens;
81-
_inp_sfx = state.InputSuffixTokens;
76+
_embeds = state.Embeds!.ToList();
77+
_last_n_tokens = new FixedSizeQueue<LLamaToken>(state.LastTokensCapacity, state.LastTokens!);
78+
_inp_pfx = state.InputPrefixTokens!;
79+
_inp_sfx = state.InputSuffixTokens!;
8280
_n_matching_session_tokens = state.MatchingSessionTokensCount;
8381
_pastTokensCount = state.PastTokensCount;
8482
_pathSession = state.SessionFilePath;
85-
_session_tokens = state.SessionTokens.ToList();
83+
_session_tokens = state.SessionTokens!.ToList();
8684
}
8785
else
8886
{
@@ -107,7 +105,7 @@ public override async Task LoadState(string filename)
107105
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
108106
{
109107
var state = await JsonSerializer.DeserializeAsync<InstructExecutorState>(fs);
110-
await LoadState(state);
108+
await LoadState(state!);
111109
}
112110
}
113111

@@ -224,7 +222,7 @@ protected override async Task InferInternal(IInferenceParams inferenceParams, In
224222
if (!string.IsNullOrEmpty(_pathSession) && args.NeedToSaveSession)
225223
{
226224
args.NeedToSaveSession = false;
227-
SaveSessionFile(_pathSession);
225+
SaveSessionFile(_pathSession!);
228226
}
229227

230228
// Sample with the pipeline
@@ -266,12 +264,12 @@ public class InstructExecutorState : ExecutorBaseState
266264
/// Instruction prefix tokens.
267265
/// </summary>
268266
[JsonPropertyName("inp_pfx")]
269-
public LLamaToken[] InputPrefixTokens { get; set; }
267+
public LLamaToken[]? InputPrefixTokens { get; set; }
270268
/// <summary>
271269
/// Instruction suffix tokens.
272270
/// </summary>
273271
[JsonPropertyName("inp_sfx")]
274-
public LLamaToken[] InputSuffixTokens { get; set; }
272+
public LLamaToken[]? InputSuffixTokens { get; set; }
275273
}
276274
}
277275
}

LLama/LLamaInteractExecutor.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public class InteractiveExecutor : StatefulExecutorBase
2727
private List<SafeLlavaImageEmbedHandle> _imageEmbedHandles = new List<SafeLlavaImageEmbedHandle>();
2828
private bool _imageInPrompt = false;
2929

30-
private ISamplingPipeline? _pipeline;
31-
3230
/// <summary>
3331
///
3432
/// </summary>
@@ -39,6 +37,12 @@ public InteractiveExecutor(LLamaContext context, ILogger? logger = null)
3937
{
4038
}
4139

40+
/// <summary>
41+
///
42+
/// </summary>
43+
/// <param name="context"></param>
44+
/// <param name="clipModel"></param>
45+
/// <param name="logger"></param>
4246
public InteractiveExecutor(LLamaContext context, LLavaWeights clipModel, ILogger? logger = null)
4347
: base(context, clipModel, logger)
4448
{
@@ -69,15 +73,15 @@ public override Task LoadState(ExecutorBaseState data)
6973
if (data is InteractiveExecutorState state)
7074
{
7175
_n_session_consumed = state.ConsumedSessionCount;
72-
_embed_inps = state.EmbedInps.ToList();
76+
_embed_inps = state.EmbedInps!.ToList();
7377
_is_prompt_run = state.IsPromptRun;
7478
_consumedTokensCount = state.ConsumedTokensCount;
75-
_embeds = state.Embeds.ToList();
76-
_last_n_tokens = new FixedSizeQueue<LLamaToken>(state.LastTokensCapacity, state.LastTokens);
79+
_embeds = state.Embeds!.ToList();
80+
_last_n_tokens = new FixedSizeQueue<LLamaToken>(state.LastTokensCapacity, state.LastTokens!);
7781
_n_matching_session_tokens = state.MatchingSessionTokensCount;
7882
_pastTokensCount = state.PastTokensCount;
7983
_pathSession = state.SessionFilePath;
80-
_session_tokens = state.SessionTokens.ToList();
84+
_session_tokens = state.SessionTokens!.ToList();
8185
}
8286
else
8387
throw new ArgumentException("Invalid state data type.");
@@ -99,7 +103,7 @@ public override async Task LoadState(string filename)
99103
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
100104
{
101105
var state = await JsonSerializer.DeserializeAsync<InteractiveExecutorState>(fs);
102-
await LoadState(state);
106+
await LoadState(state!);
103107
}
104108
}
105109

@@ -119,7 +123,7 @@ protected override Task PreprocessInputs(string? text, InferStateArgs args)
119123
{
120124
// When running the first input (prompt) in interactive mode, we should specially process it.
121125
if (text == null) throw new ArgumentException("Prompt cannot be null to trigger continuation if a prompt has not been provided previously.");
122-
if (!this.IsMultiModal)
126+
if (!IsMultiModal)
123127
{
124128
_embed_inps = Context.Tokenize(text, true, true).ToList();
125129
}
@@ -138,7 +142,7 @@ protected override Task PreprocessInputs(string? text, InferStateArgs args)
138142
text += "\n";
139143
}
140144

141-
if (!this.IsMultiModal)
145+
if (!IsMultiModal)
142146
{
143147
var line_inp = Context.Tokenize(text, false, true);
144148
_embed_inps.AddRange(line_inp);
@@ -156,16 +160,14 @@ protected override Task PreprocessInputs(string? text, InferStateArgs args)
156160

157161
/// <inheritdoc />
158162
private Task PreprocessLlava(string text, InferStateArgs args, bool addBos = true )
159-
{
160-
int usedTokens = 0;
161-
163+
{
162164
// If the prompt contains the tag <image> extract this.
163165
_imageInPrompt = text.Contains("<image>");
164-
if (_imageInPrompt && IsMultiModal )
166+
if (_imageInPrompt && IsMultiModal)
165167
{
166168
foreach (var image in Images)
167169
{
168-
_imageEmbedHandles.Add(SafeLlavaImageEmbedHandle.CreateFromMemory(ClipModel.NativeHandle, Context, image));
170+
_imageEmbedHandles.Add(SafeLlavaImageEmbedHandle.CreateFromMemory(ClipModel!.NativeHandle, Context, image));
169171
}
170172

171173
int imageIndex = text.IndexOf("<image>");
@@ -178,7 +180,6 @@ private Task PreprocessLlava(string text, InferStateArgs args, bool addBos = tru
178180
var segment2 = Context.Tokenize(postImagePrompt, false, true);
179181
_embed_inps.AddRange(segment1);
180182
_embed_inps.AddRange(segment2);
181-
usedTokens += (segment1.Length + segment2.Length);
182183
}
183184
else
184185
{
@@ -195,7 +196,7 @@ private Task PreprocessLlava(string text, InferStateArgs args, bool addBos = tru
195196
}
196197
return Task.CompletedTask;
197198
}
198-
199+
199200
/// <summary>
200201
/// Return whether to break the generation.
201202
/// </summary>
@@ -267,7 +268,7 @@ protected override async Task InferInternal(IInferenceParams inferenceParams, In
267268

268269
// Images
269270
foreach( var image in _imageEmbedHandles )
270-
ClipModel.EvalImageEmbed(Context, image, ref _pastTokensCount);
271+
ClipModel!.EvalImageEmbed(Context, image, ref _pastTokensCount);
271272

272273
// Post-image Tokens
273274
end = await Context.DecodeAsync(_embeds.GetRange(_EmbedImagePosition, _embeds.Count - _EmbedImagePosition), LLamaSeqId.Zero, batch, _pastTokensCount);
@@ -301,7 +302,7 @@ protected override async Task InferInternal(IInferenceParams inferenceParams, In
301302
if (!string.IsNullOrEmpty(_pathSession) && args.NeedToSaveSession)
302303
{
303304
args.NeedToSaveSession = false;
304-
SaveSessionFile(_pathSession);
305+
SaveSessionFile(_pathSession!);
305306
}
306307

307308

LLama/LLamaTransforms.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public class DefaultHistoryTransform : IHistoryTransform
3030
private readonly string _unknownName;
3131
private readonly bool _isInstructMode;
3232

33+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
3334
public string UserName => _userName;
3435
public string AssistantName => _assistantName;
3536
public string SystemName => _systemName;
3637
public string UnknownName => _unknownName;
3738
public bool IsInstructMode => _isInstructMode;
39+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
3840

3941
/// <summary>
4042
///

0 commit comments

Comments
 (0)