Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code style warnings and code clean up #517

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace

namespace Microsoft.KernelMemory.Evaluators.AnswerCorrectness;

#pragma warning disable CA1812 // 'StatementEvaluation' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace

namespace Microsoft.KernelMemory.Evaluators.ContextRecall;

#pragma warning disable CA1812 // 'GroundTruthClassification' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace

namespace Microsoft.KernelMemory.Evaluators.ContextRelevancy;

#pragma warning disable CA1812 // 'ContextRelevancy' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace

namespace Microsoft.KernelMemory.Evaluators.Faithfulness;

#pragma warning disable CA1812 // 'StatementEvaluation' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace

namespace Microsoft.KernelMemory.Evaluators.Relevance;

#pragma warning disable CA1812 // 'RelevanceEvaluation' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
namespace Microsoft.KernelMemory.SemanticKernelPlugin.Internals;

[TypeConverter(typeof(TypeConverter))]
public class TagCollectionWrapper : TagCollection
{
}
public class TagCollectionWrapper : TagCollection;

[TypeConverter(typeof(TypeConverter))]
public class ListOfStringsWrapper : List<string>
{
}
public class ListOfStringsWrapper : List<string>;

#pragma warning disable CA1812 // required by SK
internal sealed class TypeConverter : System.ComponentModel.TypeConverter
Expand Down
13 changes: 5 additions & 8 deletions examples/001-dotnet-WebClient/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable InconsistentNaming
// ReSharper disable CommentTypo

#pragma warning disable CS8602 // memory is initialized before usage
#pragma warning disable CS0162 // unreachable code is managed via boolean settings

Expand Down Expand Up @@ -504,18 +501,18 @@ Azure Active Directory (AAD) authentication mechanism. To test this locally, you
// Download file and print details
private static async Task DownloadFile()
{
const string filename = "file1-Wikipedia-Carbon.txt";
const string Filename = "file1-Wikipedia-Carbon.txt";

Console.WriteLine("Downloading file");
StreamableFileContent result = await s_memory.ExportFileAsync(documentId: "doc001", fileName: filename);
StreamableFileContent result = await s_memory.ExportFileAsync(documentId: "doc001", fileName: Filename);
var stream = new MemoryStream();
await (await result.GetStreamAsync()).CopyToAsync(stream);
var bytes = stream.ToArray();

Console.WriteLine();
Console.WriteLine("Original File name : " + filename);
Console.WriteLine("Original File size : " + new FileInfo(filename).Length);
Console.WriteLine("Original Bytes count: " + (await File.ReadAllBytesAsync(filename)).Length);
Console.WriteLine("Original File name : " + Filename);
Console.WriteLine("Original File size : " + new FileInfo(Filename).Length);
Console.WriteLine("Original Bytes count: " + (await File.ReadAllBytesAsync(Filename)).Length);
Console.WriteLine();
Console.WriteLine("Downloaded File name : " + result.FileName);
Console.WriteLine("Downloaded File type : " + result.FileType);
Expand Down
1 change: 0 additions & 1 deletion examples/003-dotnet-SemanticKernel-plugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public static class Program
{
// ReSharper disable InconsistentNaming
public static async Task Main()
{
const string DocFilename = "mydocs-NASA-news.pdf";
Expand Down
1 change: 0 additions & 1 deletion examples/101-dotnet-custom-Prompts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

public static class Program
{
// ReSharper disable InconsistentNaming
public static async Task Main()
{
var azureOpenAITextConfig = new AzureOpenAIConfig();
Expand Down
1 change: 0 additions & 1 deletion examples/106-dotnet-retrieve-synthetics/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ await memory.ImportDocumentAsync(new Document("doc1")
Console.WriteLine($"== {result.SourceName} summary ==\n{result.Partitions.First().Text}\n");
}

// ReSharper disable CommentTypo
/*

OUTPUT:
Expand Down
2 changes: 0 additions & 2 deletions examples/109-dotnet-custom-webscraper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable InconsistentNaming

using Microsoft.KernelMemory;
using Microsoft.KernelMemory.DataFormats.WebPages;

Expand Down
16 changes: 7 additions & 9 deletions examples/111-dotnet-azure-ai-hybrid-search/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable InconsistentNaming

using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI.OpenAI;

public static class Program
{
private const string indexName = "acronyms";
private const string IndexName = "acronyms";

public static async Task Main()
{
Expand Down Expand Up @@ -44,26 +42,26 @@ public static async Task Main()

await CreateIndexAndImportData(memoryWithHybridSearch);

const string question = "abc";
const string Question = "abc";

Console.WriteLine("Answer without hybrid search:");
await AskQuestion(memoryNoHybridSearch, question);
await AskQuestion(memoryNoHybridSearch, Question);
// Output: INFO NOT FOUND

Console.WriteLine("Answer using hybrid search:");
await AskQuestion(memoryWithHybridSearch, question);
await AskQuestion(memoryWithHybridSearch, Question);
// Output: 'Aliens Brewing Coffee'
}

private static async Task AskQuestion(IKernelMemory memory, string question)
{
var answer = await memory.AskAsync(question, index: indexName);
var answer = await memory.AskAsync(question, index: IndexName);
Console.WriteLine(answer.Result);
}

private static async Task CreateIndexAndImportData(IKernelMemory memory)
{
await memory.DeleteIndexAsync(indexName);
await memory.DeleteIndexAsync(IndexName);

var data = """
aaa bbb ccc 000000000
Expand All @@ -77,7 +75,7 @@ A B C D first 4 letters
var rows = data.Split("\n");
foreach (var acronym in rows)
{
await memory.ImportTextAsync(acronym, index: indexName);
await memory.ImportTextAsync(acronym, index: IndexName);
}
}
}
1 change: 0 additions & 1 deletion examples/201-dotnet-serverless-custom-handler/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// ReSharper disable InconsistentNaming

using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Diagnostics;
Expand Down
1 change: 0 additions & 1 deletion examples/206-dotnet-configuration-and-logging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

public static class Program
{
// ReSharper disable once InconsistentNaming
public static async Task Main()
{
var openAIConfig = new OpenAIConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
/// </summary>
public static class Program
{
// ReSharper disable once InconsistentNaming
public static async Task Main()
{
// Partition input text in chunks of 100 tokens
Expand Down
1 change: 0 additions & 1 deletion examples/208-dotnet-lmstudio/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

public static class Program
{
// ReSharper disable once InconsistentNaming
public static async Task Main()
{
// Using OpenAI for embeddings
Expand Down
4 changes: 1 addition & 3 deletions extensions/Anthropic/Client/StreamingResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Microsoft.KernelMemory.AI.Anthropic.Client;

internal abstract class StreamingResponseMessage
{
}
internal abstract class StreamingResponseMessage;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.AzureAISearch.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Microsoft.AzureAISearch.UnitTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public async Task CanGetListWithEmptyFiltersAsync()
{
}

;

// If it gets here, the test passed.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.Elasticsearch.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements

namespace Microsoft.KernelMemory.MemoryDb.Elasticsearch;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

// ReSharper disable CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements

namespace Microsoft.KernelMemory.MemoryDb.Elasticsearch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.LlamaSharp.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public async Task DeleteIndicesAsync(string collectionName)
{
{
"$listSearchIndexes",
new BsonDocument
{
}
new BsonDocument()
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ last_update TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
break;
}

// ReSharper disable once CommentTypo
/* If concurrency is not handled properly, the test should fail with
* Npgsql.PostgresException
* 23505: duplicate key value violates unique constraint "pg_type_typname_nsp_index"
* 23505: duplicate key value violates unique constraint
*/
var concurrency = 20;
var indexName = "create_index_test";
Expand Down
1 change: 0 additions & 1 deletion extensions/Postgres/Postgres.FunctionalTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.Postgres.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ private void Dispose(bool disposing)
{
if (disposing)
{
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
(this._dataSource as IDisposable)?.Dispose();
}
}
Expand Down
1 change: 0 additions & 1 deletion extensions/Postgres/Postgres/PostgresConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public PostgresConfig()
/// </summary>
public void Validate()
{
// ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
this.TableNamePrefix = this.TableNamePrefix?.Trim() ?? string.Empty;
this.ConnectionString = this.ConnectionString?.Trim() ?? string.Empty;

Expand Down
1 change: 0 additions & 1 deletion extensions/Qdrant/Qdrant.FunctionalTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.Qdrant.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
1 change: 0 additions & 1 deletion extensions/Qdrant/Qdrant.UnitTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Microsoft.Qdrant.UnitTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.SQLServer.FunctionalTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
var config = new ConfigurationBuilder()
Expand Down
1 change: 0 additions & 1 deletion extensions/TikToken/TikToken.UnitTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Microsoft.TikToken.UnitTests;

public class Startup
{
// ReSharper disable once UnusedMember.Global
public void ConfigureHost(IHostBuilder hostBuilder)
{
}
Expand Down
2 changes: 1 addition & 1 deletion service/Abstractions/AI/Embedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#pragma warning disable IDE0130 // first class concept we want to have readily available
#pragma warning disable CA2225 // no need for explicit methods

// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.KernelMemory;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;

#pragma warning disable IDE0130 // reduce number of "using" statements
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.Extensions.DependencyInjection;
#pragma warning restore IDE0130

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System;

// ReSharper disable CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.KernelMemory;

public class ConfigurationException : KernelMemoryException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

#pragma warning disable IDE0130 // reduce number of "using" statements
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.Extensions.Configuration;
#pragma warning restore IDE0130

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

// ReSharper disable CheckNamespace
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.KernelMemory;

#pragma warning disable CS8777
Expand Down
Loading
Loading