Skip to content

Commit

Permalink
fixing sample 1 to emit exit event
Browse files Browse the repository at this point in the history
  • Loading branch information
esttenorio committed Oct 16, 2024
1 parent 8b4a149 commit 84fce96
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,29 @@ public override ValueTask ActivateAsync(KernelProcessStepState<UserInputState> s
return ValueTask.CompletedTask;
}

internal string GetNextUserMessage()
{
var userMessage = this._state!.UserInputs[_state.CurrentInputIndex];
_state.CurrentInputIndex++;

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"USER: {userMessage}");
Console.ResetColor();

return userMessage;
}

/// <summary>
/// Gets the user input.
/// Could be overriden to customize the output events to be emitted

Check warning on line 65 in dotnet/samples/GettingStartedWithProcesses/SharedSteps/ScriptedUserInputStep.cs

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"overriden" should be "overridden".
/// </summary>
/// <param name="context">An instance of <see cref="KernelProcessStepContext"/> which can be
/// used to emit events from within a KernelFunction.</param>
/// <returns>A <see cref="ValueTask"/></returns>
[KernelFunction(Functions.GetUserInput)]
public async ValueTask GetUserInputAsync(KernelProcessStepContext context)
public virtual async ValueTask GetUserInputAsync(KernelProcessStepContext context)
{
var userMessage = _state!.UserInputs[_state.CurrentInputIndex];
_state.CurrentInputIndex++;

Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"USER: {userMessage}");
Console.ResetColor();

var userMessage = this.GetNextUserMessage();
// Emit the user input
await context.EmitEventAsync(new() { Id = CommonEvents.UserInputReceived, Data = userMessage });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public override void PopulateUserInputs(UserInputState state)
state.UserInputs.Add("How low is the lowest valley?");
state.UserInputs.Add("How wide is the widest river?");
state.UserInputs.Add("exit");
state.UserInputs.Add("This text will be ignored because exit process condition was already met at this point.");
}

public override async ValueTask GetUserInputAsync(KernelProcessStepContext context)
{
var userMessage = this.GetNextUserMessage();

if (userMessage.ToLower() == "exit")

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Use StringComparison when comparing strings (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1155)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Specify a culture or use an invariant version to avoid implicit dependency on current culture (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862)

Check failure on line 105 in dotnet/samples/GettingStartedWithProcesses/Step01/Step01_Processes.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'Step01_Processes.ChatUserInputStep.GetUserInputAsync(KernelProcessStepContext)' with a call to 'string.ToLower(CultureInfo)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304)
{
// exit condition met, emitting exit event
await context.EmitEventAsync(new() { Id = ChatBotEvents.Exit, Data = userMessage });
return;
}

// emitting userInputReceived event
await context.EmitEventAsync(new() { Id = CommonEvents.UserInputReceived, Data = userMessage });
}
}

Expand Down

0 comments on commit 84fce96

Please sign in to comment.