From 2c333aa5f9546bc8bfe10e6794fe928c188bfe2d Mon Sep 17 00:00:00 2001 From: eavanvalkenburg Date: Thu, 28 Nov 2024 13:16:54 +0100 Subject: [PATCH] remove mistaken on_activate func --- .../step01/step01_processes.py | 39 +++++++++++++------ .../kernel_process/kernel_process_step.py | 4 -- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/python/samples/getting_started_with_processes/step01/step01_processes.py b/python/samples/getting_started_with_processes/step01/step01_processes.py index 738f41212b0d..3ad8dcc04685 100644 --- a/python/samples/getting_started_with_processes/step01/step01_processes.py +++ b/python/samples/getting_started_with_processes/step01/step01_processes.py @@ -37,7 +37,7 @@ class UserInputState(KernelBaseModel): current_input_index: int = 0 -class ScriptedUserInputStep(KernelProcessStep[UserInputState]): +class UserInputStep(KernelProcessStep[UserInputState]): GET_USER_INPUT: ClassVar[str] = "get_user_input" def create_default_state(self) -> "UserInputState": @@ -48,16 +48,11 @@ def populate_user_inputs(self): """Method to be overridden by the user to populate with custom user messages.""" pass - async def on_activate(self): - """This is called during the activation of the process step.""" - self.populate_user_inputs() - async def activate(self, state: KernelProcessStepState[UserInputState]): """Activates the step and sets the state.""" state.state = state.state or self.create_default_state() self.state = state.state self.populate_user_inputs() - pass @kernel_function(name=GET_USER_INPUT) async def get_user_input(self, context: KernelProcessStepContext): @@ -65,9 +60,9 @@ async def get_user_input(self, context: KernelProcessStepContext): if not self.state: raise ValueError("State has not been initialized") - user_message = self.state.user_inputs[self.state.current_input_index] + user_message = input("USER: ") - print(f"USER: {user_message}") + # print(f"USER: {user_message}") if "exit" in user_message: await context.emit_event(process_event=ChatBotEvents.Exit, data=None) @@ -79,7 +74,7 @@ async def get_user_input(self, context: KernelProcessStepContext): await context.emit_event(process_event=CommonEvents.UserInputReceived, data=user_message) -class ChatUserInputStep(ScriptedUserInputStep): +class ScriptedInputStep(UserInputStep): def populate_user_inputs(self): """Override the method to populate user inputs for the chat step.""" if self.state is not None: @@ -89,6 +84,25 @@ def populate_user_inputs(self): self.state.user_inputs.append("How wide is the widest river?") self.state.user_inputs.append("exit") + @kernel_function + async def get_user_input(self, context: KernelProcessStepContext): + """Gets the user input.""" + if not self.state: + raise ValueError("State has not been initialized") + + user_message = self.state.user_inputs[self.state.current_input_index] + + print(f"USER: {user_message}") + + if "exit" in user_message: + await context.emit_event(process_event=ChatBotEvents.Exit, data=None) + return + + self.state.current_input_index += 1 + + # Emit the user input event + await context.emit_event(process_event=CommonEvents.UserInputReceived, data=user_message) + class IntroStep(KernelProcessStep): @kernel_function @@ -146,14 +160,14 @@ async def get_chat_response(self, context: "KernelProcessStepContext", user_mess kernel = Kernel() -async def step01_processes(): +async def step01_processes(scripted: bool = True): kernel.add_service(OpenAIChatCompletion(service_id="default")) process = ProcessBuilder(name="ChatBot") # Define the steps on the process builder based on their types, not concrete objects intro_step = process.add_step(IntroStep) - user_input_step = process.add_step(ChatUserInputStep) + user_input_step = process.add_step(ScriptedInputStep if scripted else UserInputStep) response_step = process.add_step(ChatBotResponseStep) # Define the input event that starts the process and where to send it @@ -186,4 +200,5 @@ async def step01_processes(): if __name__ == "__main__": - asyncio.run(step01_processes()) + # if you want to run this sample with your won input, set the below parameter to False + asyncio.run(step01_processes(scripted=False)) diff --git a/python/semantic_kernel/processes/kernel_process/kernel_process_step.py b/python/semantic_kernel/processes/kernel_process/kernel_process_step.py index 7fd09efbd32d..887dcfac47e1 100644 --- a/python/semantic_kernel/processes/kernel_process/kernel_process_step.py +++ b/python/semantic_kernel/processes/kernel_process/kernel_process_step.py @@ -21,7 +21,3 @@ class KernelProcessStep(ABC, KernelBaseModel, Generic[TState]): async def activate(self, state: "KernelProcessStepState[TState]"): """Activates the step and sets the state.""" pass # pragma: no cover - - async def on_activate(self): - """To be overridden by subclasses if needed.""" - pass # pragma: no cover