Skip to content

Commit

Permalink
KernelException is replaced by SKException
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMenshykh committed Jul 19, 2023
1 parent ef8ee07 commit f51df1c
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private static async Task<Plan> ExecutePlanAsync(
Console.WriteLine(plan.State.ToString());
}
}
catch (KernelException e)
catch (SKException e)
{
Console.WriteLine("Step - Execution failed:");
Console.WriteLine(e.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Planning.Sequential;
using Microsoft.SemanticKernel.SkillDefinition;
Expand Down Expand Up @@ -60,9 +61,7 @@ public static async Task<IOrderedEnumerable<FunctionView>> GetAvailableFunctions

if (context.Skills == null)
{
throw new KernelException(
KernelException.ErrorCodes.SkillCollectionNotSet,
"Skill collection not found in the context");
throw new SKException("Skill collection not found in the context");
}

var functionsView = context.Skills.GetFunctionsView();
Expand Down
8 changes: 2 additions & 6 deletions dotnet/src/InternalUtilities/src/Diagnostics/Verify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,15 @@ internal static void ParametersUniqueness(IList<ParameterView> parameters)

if (!seen.Add(p.Name))
{
throw new KernelException(
KernelException.ErrorCodes.InvalidFunctionDescription,
$"The function has two or more parameters with the same name '{p.Name}'");
throw new SKException($"The function has two or more parameters with the same name '{p.Name}'");
}
}
}
}

[DoesNotReturn]
private static void ThrowInvalidName(string kind, string name) =>
throw new KernelException(
KernelException.ErrorCodes.InvalidFunctionDescription,
$"A {kind} can contain only ASCII letters, digits, and underscores: '{name}' is not a valid name.");
throw new SKException($"A {kind} can contain only ASCII letters, digits, and underscores: '{name}' is not a valid name.");

[DoesNotReturn]
internal static void ThrowArgumentNullException(string? paramName) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.AI.ChatCompletion;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Services;

// Use base namespace for better discoverability and to avoid conflicts with other extensions.
Expand All @@ -17,11 +18,11 @@ public static class ChatCompletionServiceExtensions
/// <param name="services">The service provider.</param>
/// <param name="serviceId">Optional identifier of the desired service.</param>
/// <returns>The completion service id matching the given id or the default.</returns>
/// <exception cref="KernelException">Thrown when no suitable service is found.</exception>
/// <exception cref="SKException">Thrown when no suitable service is found.</exception>
public static IChatCompletion GetChatCompletionService(
this IAIServiceProvider services,
string? serviceId = null) => services.GetService<IChatCompletion>(serviceId)
?? throw new KernelException(KernelException.ErrorCodes.ServiceNotFound, "Chat completion service not found");
?? throw new SKException("Chat completion service not found");

/// <summary>
/// Returns true if a <see cref="IChatCompletion"/> exist with the specified ID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Services;

// Use base namespace for better discoverability and to avoid conflicts with other extensions.
Expand All @@ -17,12 +18,12 @@ public static class TextEmbeddingServiceExtensions
/// <param name="services">The service provider.</param>
/// <param name="serviceId">Optional identifier of the desired service.</param>
/// <returns>The embedding service matching the given id or the default service.</returns>
/// <exception cref="KernelException">Thrown when no suitable service is found.</exception>
/// <exception cref="SKException">Thrown when no suitable service is found.</exception>
public static ITextEmbeddingGeneration GetTextEmbeddingService(
this IAIServiceProvider services,
string? serviceId = null)
=> services.GetService<ITextEmbeddingGeneration>(serviceId)
?? throw new KernelException(KernelException.ErrorCodes.ServiceNotFound, "Text embedding service not available");
?? throw new SKException("Text embedding service not available");

/// <summary>
/// Returns true if a <see cref="ITextEmbeddingGeneration"/> exist with the specified ID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.AI.ImageGeneration;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Services;

// Use base namespace for better discoverability and to avoid conflicts with other extensions.
Expand All @@ -17,11 +18,11 @@ public static class ImageGenerationServiceExtensions
/// <param name="services">The service provider.</param>
/// <param name="serviceId">Optional identifier of the desired service.</param>
/// <returns>The <see cref="IImageGeneration"/> id matching the given id or the default.</returns>
/// <exception cref="KernelException">Thrown when no suitable service is found.</exception>
/// <exception cref="SKException">Thrown when no suitable service is found.</exception>
public static IImageGeneration GetImageGenerationService(
this IAIServiceProvider services,
string? serviceId = null) => services.GetService<IImageGeneration>(serviceId)
?? throw new KernelException(KernelException.ErrorCodes.ServiceNotFound, "Image generation service not found");
?? throw new SKException("Image generation service not found");

/// <summary>
/// Returns true if a <see cref="IImageGeneration"/> exist with the specified ID.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.AI.TextCompletion;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Services;

// Use base namespace for better discoverability and to avoid conflicts with other extensions.
Expand All @@ -17,11 +18,11 @@ public static class TextCompletionServiceExtensions
/// <param name="services">The service provider.</param>
/// <param name="serviceId">Optional identifier of the desired service.</param>
/// <returns>The text completion service id matching the given ID or the default.</returns>
/// <exception cref="KernelException">Thrown when no suitable service is found.</exception>
/// <exception cref="SKException">Thrown when no suitable service is found.</exception>
public static ITextCompletion GetTextCompletionServiceOrDefault(
this IAIServiceProvider services,
string? serviceId = null) => services.GetService<ITextCompletion>(serviceId)
?? throw new KernelException(KernelException.ErrorCodes.ServiceNotFound, "Text completion service not found");
?? throw new SKException("Text completion service not found");

/// <summary>
/// Returns true if a <see cref="ITextCompletion"/> exist with the specified ID.
Expand Down
119 changes: 0 additions & 119 deletions dotnet/src/SemanticKernel.Abstractions/KernelException.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.SkillDefinition;

Expand Down Expand Up @@ -115,9 +116,7 @@ public ISKFunction Func(string skillName, string functionName)
{
if (this.Skills is null)
{
throw new KernelException(
KernelException.ErrorCodes.SkillCollectionNotSet,
"Skill collection not found in the context");
throw new SKException("Skill collection not found in the context");
}

return this.Skills.GetFunction(skillName, functionName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using Microsoft.SemanticKernel.Diagnostics;

namespace Microsoft.SemanticKernel.SkillDefinition;

Expand All @@ -15,7 +16,7 @@ public interface IReadOnlySkillCollection
/// </summary>
/// <param name="functionName">The name of the function to retrieve.</param>
/// <returns>The function retrieved from the collection.</returns>
/// <exception cref="KernelException">The specified function could not be found in the collection.</exception>
/// <exception cref="SKException">The specified function could not be found in the collection.</exception>
ISKFunction GetFunction(string functionName);

/// <summary>
Expand All @@ -24,7 +25,7 @@ public interface IReadOnlySkillCollection
/// <param name="skillName">The name of the skill with which the function is associated.</param>
/// <param name="functionName">The name of the function to retrieve.</param>
/// <returns>The function retrieved from the collection.</returns>
/// <exception cref="KernelException">The specified function could not be found in the collection.</exception>
/// <exception cref="SKException">The specified function could not be found in the collection.</exception>
ISKFunction GetFunction(string skillName, string functionName);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.SemanticKernel.Diagnostics;

namespace Microsoft.SemanticKernel.SkillDefinition;

Expand Down Expand Up @@ -44,16 +45,12 @@ private NullReadOnlySkillCollection()
[DoesNotReturn]
private static ISKFunction ThrowFunctionNotAvailable(string skillName, string functionName)
{
throw new KernelException(
KernelException.ErrorCodes.FunctionNotAvailable,
$"Function not available: {skillName}.{functionName}");
throw new SKException($"Function not available: {skillName}.{functionName}");
}

[DoesNotReturn]
private static ISKFunction ThrowFunctionNotAvailable(string functionName)
{
throw new KernelException(
KernelException.ErrorCodes.FunctionNotAvailable,
$"Function not available: {functionName}");
throw new SKException($"Function not available: {functionName}");
}
}
63 changes: 0 additions & 63 deletions dotnet/src/SemanticKernel.UnitTests/KernelExceptionTests.cs

This file was deleted.

Loading

0 comments on commit f51df1c

Please sign in to comment.