Skip to content

Commit

Permalink
Pair review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRamosEs committed Apr 26, 2024
1 parent f46f58e commit 355c92e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Encamina.Enmarcha.AI.Abstractions/ITextSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface ITextSplitter
/// <param name="chunks">The collection of chunks to join.</param>
/// <param name="separator">The separator to use between chunks.</param>
/// <returns>A single string with all the chunks joined together by the specified separator.</returns>
string? JoinChunks(IEnumerable<string> chunks, string separator);
string JoinChunks(IEnumerable<string> chunks, string separator);

/// <summary>
/// Splits the specified text, using the specified length function.
Expand Down
6 changes: 2 additions & 4 deletions src/Encamina.Enmarcha.AI.Abstractions/TextSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ public virtual IEnumerable<string> Split(string text, Func<string, int> lengthFu
/// <exception cref="ArgumentNullException">
/// Thrown when any of the parameters <paramref name="chunks"/> or <paramref name="separator"/> is <see langword="null"/>.
/// </exception>"
public virtual string? JoinChunks(IEnumerable<string> chunks, string separator)
public virtual string JoinChunks(IEnumerable<string> chunks, string separator)
{
Guard.IsNotNull(chunks);
Guard.IsNotNull(separator);

var text = string.Join(separator, chunks).Trim();

return string.IsNullOrWhiteSpace(text)
? null
: text;
return text;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected IntentKindBase(string value)
public override string ToString() => value;

/// <inheritdoc />
public bool Equals(IntentKindBase x, IntentKindBase y) => (x == null! && y == null!) || (x != null! && y != null! && x.Equals(y));
public bool Equals(IntentKindBase x, IntentKindBase y) => (x is null && y is null) || (x is not null && y is not null && x.Equals(y));

/// <inheritdoc />
public int GetHashCode(IntentKindBase obj) => obj != null! ? obj.GetHashCode() : 0;
public int GetHashCode(IntentKindBase obj) => obj is not null ? obj.GetHashCode() : 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IMetadataProcessor
/// </summary>
/// <param name="message">The message to process for metadata.</param>
/// <param name="cancellationToken">A cancellation token that can be used to receive notice of cancellation.</param>
/// <returns>A valid instace of <see cref="MetadataOptions"/> of metadata is successfully retrieved from the given message, otherwise <see langword="null"/>.</returns>
/// <returns>A valid instance of <see cref="MetadataOptions"/> of metadata is successfully retrieved from the given message, otherwise <see langword="null"/>.</returns>
Task<MetadataOptions> ProcessMessageAsync(string message, CancellationToken cancellationToken);

/// <summary>
Expand All @@ -35,6 +35,6 @@ public interface IMetadataProcessor
/// <param name="message">The message to process for metadata.</param>
/// <param name="metadataOptions">The metadata options to use when processing the message.</param>
/// <param name="cancellationToken">A cancellation token that can be used to receive notice of cancellation.</param>
/// <returns>A valid instace of <see cref="MetadataOptions"/> of metadata is successfully retrieved from the given message, otherwise <see langword="null"/>.</returns>
Task<MetadataOptions> ProcessMessageAsync(string message, MetadataOptions metadataOptions, CancellationToken cancellationToken);
/// <returns>A valid instance of <see cref="MetadataOptions"/> of metadata is successfully retrieved from the given message, otherwise <see langword="null"/>.</returns>
Task<MetadataOptions> ProcessMessageAsync(string message, MetadataOptions? metadataOptions, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Encamina.Enmarcha.AI.QuestionsAnswering.Abstractions;

/// <summary>
/// Represents a congnitive service that provides question answering capabilities.
/// Represents a cognitive service that provides question answering capabilities.
/// </summary>
public interface IQuestionAnsweringService : ICognitiveService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public virtual async Task<IReadOnlyCollection<IAnswer>> ProcessAnswersAsync(IEnu
/// <inheritdoc/>
public virtual Task<MetadataOptions> ProcessMessageAsync(string message, CancellationToken cancellationToken)
{
return ProcessMessageAsync(message, null!, cancellationToken);
return ProcessMessageAsync(message, null, cancellationToken);
}

/// <inheritdoc/>
public async Task<MetadataOptions> ProcessMessageAsync(string message, MetadataOptions metadataOptions, CancellationToken cancellationToken)
public async Task<MetadataOptions> ProcessMessageAsync(string message, MetadataOptions? metadataOptions, CancellationToken cancellationToken)
{
metadataOptions ??= new MetadataOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

using Encamina.Enmarcha.AI.QuestionsAnswering.Abstractions;

using Microsoft.Extensions.Options;

namespace Encamina.Enmarcha.AI.QuestionsAnswering.Azure;

/// <summary>
Expand Down Expand Up @@ -69,7 +67,7 @@ public virtual async Task<QuestionResult> GetAnswersAsync(QuestionRequest reques
{
if (requestOptions == null)
{
return null!;
return null;
}

var queryFilter = new QueryFilters()
Expand All @@ -88,11 +86,11 @@ public virtual async Task<QuestionResult> GetAnswersAsync(QuestionRequest reques
return queryFilter.MetadataFilter != null || queryFilter.SourceFilter.Any() ? queryFilter : null;
}

private static MetadataFilter BuildMetadataFilter(MetadataOptions metadataOptions)
private static MetadataFilter? BuildMetadataFilter(MetadataOptions metadataOptions)
{
if (metadataOptions == null || (!metadataOptions.Metadata?.Any() ?? true))
{
return null!;
return null;
}

var metadataFilter = new MetadataFilter()
Expand Down
4 changes: 1 addition & 3 deletions src/Encamina.Enmarcha.AI/CognitiveServiceFactoryBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics.CodeAnalysis;

using CommunityToolkit.Diagnostics;
using CommunityToolkit.Diagnostics;

using Encamina.Enmarcha.AI.Abstractions;

Expand Down
34 changes: 17 additions & 17 deletions src/Encamina.Enmarcha.AI/CognitiveServiceProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,65 +44,65 @@ protected CognitiveServiceProviderBase(
}

/// <inheritdoc/>
public virtual IConversationAnalysisService GetConversationAnalysisService(string serviceName) => GetByName(conversationAnalysisServiceFactory!, serviceName);
public virtual IConversationAnalysisService GetConversationAnalysisService(string serviceName) => GetByName(conversationAnalysisServiceFactory, serviceName)!;

/// <inheritdoc/>
public virtual ILanguageDetectionService GetLanguageDetectionService(string serviceName) => GetByName(languageDetectionServiceFactory!, serviceName);
public virtual ILanguageDetectionService GetLanguageDetectionService(string serviceName) => GetByName(languageDetectionServiceFactory, serviceName)!;

/// <inheritdoc/>
public virtual IQuestionAnsweringService GetQuestionsAnsweringService(string serviceName) => GetByName(questionsAnsweringServiceFactory!, serviceName);
public virtual IQuestionAnsweringService GetQuestionsAnsweringService(string serviceName) => GetByName(questionsAnsweringServiceFactory, serviceName)!;

/// <inheritdoc/>
public virtual ITextTranslationService GetTextTranslationService(string serviceName) => GetByName(textTranslationServiceFactory!, serviceName);
public virtual ITextTranslationService GetTextTranslationService(string serviceName) => GetByName(textTranslationServiceFactory, serviceName)!;

/// <inheritdoc/>
public virtual IIntentPredictionService GetIntentPredictionService(string serviceName) => GetByName(intentPredictionServiceFactory!, serviceName);
public virtual IIntentPredictionService GetIntentPredictionService(string serviceName) => GetByName(intentPredictionServiceFactory, serviceName)!;

/// <inheritdoc/>
public bool TryGetConversationAnalysisService(string serviceName, out IConversationAnalysisService service)
public bool TryGetConversationAnalysisService(string serviceName, out IConversationAnalysisService? service)
{
service = GetByName(conversationAnalysisServiceFactory!, serviceName, false);
service = GetByName(conversationAnalysisServiceFactory, serviceName, false);

return service != null;
}

/// <inheritdoc/>
public bool TryGetLanguageDetectionService(string serviceName, out ILanguageDetectionService service)
public bool TryGetLanguageDetectionService(string serviceName, out ILanguageDetectionService? service)
{
service = GetByName(languageDetectionServiceFactory!, serviceName, false);
service = GetByName(languageDetectionServiceFactory, serviceName, false);

return service != null;
}

/// <inheritdoc/>
public bool TryGetQuestionsAnsweringService(string serviceName, out IQuestionAnsweringService service)
public bool TryGetQuestionsAnsweringService(string serviceName, out IQuestionAnsweringService? service)
{
service = GetByName(questionsAnsweringServiceFactory!, serviceName, false);
service = GetByName(questionsAnsweringServiceFactory, serviceName, false);

return service != null;
}

/// <inheritdoc/>
public bool TryGetTextTranslationService(string serviceName, out ITextTranslationService service)
public bool TryGetTextTranslationService(string serviceName, out ITextTranslationService? service)
{
service = GetByName(textTranslationServiceFactory!, serviceName, false);
service = GetByName(textTranslationServiceFactory, serviceName, false);

return service != null;
}

/// <inheritdoc/>
public bool TryGetIntentPredictionService(string serviceName, out IIntentPredictionService service)
public bool TryGetIntentPredictionService(string serviceName, out IIntentPredictionService? service)
{
service = GetByName(intentPredictionServiceFactory!, serviceName, false);
service = GetByName(intentPredictionServiceFactory, serviceName, false);

return service != null;
}

private static TCognitiveService GetByName<TCognitiveService>(ICognitiveServiceFactory<TCognitiveService> cognitiveServiceFactory, string serviceName, bool throwIfNotFound = true)
private static TCognitiveService? GetByName<TCognitiveService>(ICognitiveServiceFactory<TCognitiveService>? cognitiveServiceFactory, string serviceName, bool throwIfNotFound = true)
where TCognitiveService : class, ICognitiveService
{
return cognitiveServiceFactory != null
? cognitiveServiceFactory.GetByName(serviceName, throwIfNotFound)!
? cognitiveServiceFactory.GetByName(serviceName, throwIfNotFound)
: throw new InvalidOperationException(string.Format(Resources.ExceptionMessages.NotConfiguredCognitiveServiceFactory, typeof(TCognitiveService).Name));
}
}
10 changes: 5 additions & 5 deletions src/Encamina.Enmarcha.AI/ICognitiveServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public interface ICognitiveServiceProvider
/// <returns>
/// Returns <see langword="true"/> if a service is found; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetConversationAnalysisService(string serviceName, out IConversationAnalysisService service);
bool TryGetConversationAnalysisService(string serviceName, out IConversationAnalysisService? service);

/// <summary>
/// Tries to retrieve a language detection cognitive service given its name.
Expand All @@ -78,7 +78,7 @@ public interface ICognitiveServiceProvider
/// <returns>
/// Returns <see langword="true"/> if a service is found; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetLanguageDetectionService(string serviceName, out ILanguageDetectionService service);
bool TryGetLanguageDetectionService(string serviceName, out ILanguageDetectionService? service);

/// <summary>
/// Tries to retrieve a question answering cognitive service given its name.
Expand All @@ -90,7 +90,7 @@ public interface ICognitiveServiceProvider
/// <returns>
/// Returns <see langword="true"/> if a service is found; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetQuestionsAnsweringService(string serviceName, out IQuestionAnsweringService service);
bool TryGetQuestionsAnsweringService(string serviceName, out IQuestionAnsweringService? service);

/// <summary>
/// Tries to retrieve a text translation cognitive service given its name.
Expand All @@ -102,7 +102,7 @@ public interface ICognitiveServiceProvider
/// <returns>
/// Returns <see langword="true"/> if a service is found; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetTextTranslationService(string serviceName, out ITextTranslationService service);
bool TryGetTextTranslationService(string serviceName, out ITextTranslationService? service);

/// <summary>
/// Tries to retrieve an intent prediction cognitive service given its name.
Expand All @@ -114,5 +114,5 @@ public interface ICognitiveServiceProvider
/// <returns>
/// Returns <see langword="true"/> if a service is found; otherwise, returns <see langword="false"/>.
/// </returns>
bool TryGetIntentPredictionService(string serviceName, out IIntentPredictionService service);
bool TryGetIntentPredictionService(string serviceName, out IIntentPredictionService? service);
}

0 comments on commit 355c92e

Please sign in to comment.