chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from samples.getting_started_with_processes.step03.processes.fish_and_chips_process import FishAndChipsProcess
|
||||
from samples.getting_started_with_processes.step03.processes.fish_sandwich_process import FishSandwichProcess
|
||||
from samples.getting_started_with_processes.step03.processes.fried_fish_process import FriedFishProcess
|
||||
|
||||
__all__ = ["FishAndChipsProcess", "FriedFishProcess", "FishSandwichProcess"]
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
import json
|
||||
from enum import Enum
|
||||
|
||||
from samples.getting_started_with_processes.step03.processes.fried_fish_process import (
|
||||
FriedFishProcess,
|
||||
)
|
||||
from samples.getting_started_with_processes.step03.processes.potato_fries_process import (
|
||||
PotatoFriesProcess,
|
||||
)
|
||||
from samples.getting_started_with_processes.step03.steps.external_step import ExternalStep
|
||||
from semantic_kernel.functions.kernel_function_decorator import kernel_function
|
||||
from semantic_kernel.processes import ProcessBuilder
|
||||
from semantic_kernel.processes.kernel_process import (
|
||||
KernelProcessStep,
|
||||
KernelProcessStepContext,
|
||||
)
|
||||
|
||||
|
||||
class AddFishAndChipsCondimentsStep(KernelProcessStep):
|
||||
class Functions(Enum):
|
||||
AddCondiments = "AddCondiments"
|
||||
|
||||
class OutputEvents(Enum):
|
||||
CondimentsAdded = "CondimentsAdded"
|
||||
|
||||
@kernel_function(name=Functions.AddCondiments)
|
||||
async def add_condiments(
|
||||
self, context: KernelProcessStepContext, fish_actions: list[str], potato_actions: list[str]
|
||||
):
|
||||
print(
|
||||
f"ADD_CONDIMENTS: Added condiments to Fish & Chips - "
|
||||
f"Fish: {json.dumps(fish_actions)}, Potatoes: {json.dumps(potato_actions)}"
|
||||
)
|
||||
fish_actions.extend(potato_actions)
|
||||
fish_actions.append("Condiments")
|
||||
await context.emit_event(
|
||||
process_event=self.OutputEvents.CondimentsAdded,
|
||||
data=fish_actions,
|
||||
)
|
||||
|
||||
|
||||
class FishAndChipsProcess:
|
||||
class ProcessEvents(Enum):
|
||||
PrepareFishAndChips = "PrepareFishAndChips"
|
||||
FishAndChipsReady = "FishAndChipsReady"
|
||||
FishAndChipsIngredientOutOfStock = "FishAndChipsIngredientOutOfStock"
|
||||
|
||||
class ExternalFishAndChipsStep(ExternalStep):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(FishAndChipsProcess.ProcessEvents.FishAndChipsReady)
|
||||
|
||||
@staticmethod
|
||||
def create_process(process_name: str = "FishAndChipsProcess") -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
|
||||
make_fish_step = process_builder.add_step_from_process(FriedFishProcess.create_process())
|
||||
make_potato_step = process_builder.add_step_from_process(PotatoFriesProcess.create_process())
|
||||
add_condiments_step = process_builder.add_step(AddFishAndChipsCondimentsStep)
|
||||
external_step = process_builder.add_step(FishAndChipsProcess.ExternalFishAndChipsStep)
|
||||
|
||||
process_builder.on_input_event(FishAndChipsProcess.ProcessEvents.PrepareFishAndChips).send_event_to(
|
||||
make_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
).send_event_to(make_potato_step.where_input_event_is(PotatoFriesProcess.ProcessEvents.PreparePotatoFries))
|
||||
|
||||
make_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(
|
||||
add_condiments_step, parameter_name="fishActions"
|
||||
)
|
||||
make_potato_step.on_event(PotatoFriesProcess.ProcessEvents.PotatoFriesReady).send_event_to(
|
||||
add_condiments_step, parameter_name="potatoActions"
|
||||
)
|
||||
|
||||
add_condiments_step.on_event(AddFishAndChipsCondimentsStep.OutputEvents.CondimentsAdded).send_event_to(
|
||||
external_step
|
||||
)
|
||||
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps(
|
||||
process_name: str = "FishAndChipsWithStatefulStepsProcess",
|
||||
) -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
|
||||
make_fish_step = process_builder.add_step_from_process(FriedFishProcess.create_process_with_stateful_steps_v1())
|
||||
make_potato_step = process_builder.add_step_from_process(
|
||||
PotatoFriesProcess.create_process_with_stateful_steps()
|
||||
)
|
||||
add_condiments_step = process_builder.add_step(AddFishAndChipsCondimentsStep)
|
||||
external_step = process_builder.add_step(FishAndChipsProcess.ExternalFishAndChipsStep)
|
||||
|
||||
process_builder.on_input_event(FishAndChipsProcess.ProcessEvents.PrepareFishAndChips).send_event_to(
|
||||
make_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
).send_event_to(make_potato_step.where_input_event_is(PotatoFriesProcess.ProcessEvents.PreparePotatoFries))
|
||||
|
||||
make_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(
|
||||
add_condiments_step, parameter_name="fishActions"
|
||||
)
|
||||
make_potato_step.on_event(PotatoFriesProcess.ProcessEvents.PotatoFriesReady).send_event_to(
|
||||
add_condiments_step, parameter_name="potatoActions"
|
||||
)
|
||||
|
||||
add_condiments_step.on_event(AddFishAndChipsCondimentsStep.OutputEvents.CondimentsAdded).send_event_to(
|
||||
external_step
|
||||
)
|
||||
|
||||
return process_builder
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
from enum import Enum
|
||||
|
||||
from samples.getting_started_with_processes.step03.processes.fried_fish_process import (
|
||||
FriedFishProcess,
|
||||
)
|
||||
from samples.getting_started_with_processes.step03.steps.external_step import ExternalStep
|
||||
from semantic_kernel.functions import kernel_function
|
||||
from semantic_kernel.processes import ProcessBuilder
|
||||
from semantic_kernel.processes.kernel_process import (
|
||||
KernelProcessEventVisibility,
|
||||
KernelProcessStep,
|
||||
KernelProcessStepContext,
|
||||
)
|
||||
|
||||
|
||||
class AddBunStep(KernelProcessStep):
|
||||
class Functions(Enum):
|
||||
AddBuns = "AddBuns"
|
||||
|
||||
class OutputEvents(Enum):
|
||||
BunsAdded = "BunsAdded"
|
||||
|
||||
@kernel_function(name=Functions.AddBuns)
|
||||
async def slice_food(self, context: KernelProcessStepContext, food_actions: list[str]):
|
||||
print(f"BUNS_ADDED_STEP: Buns added to ingredient {food_actions[0]}")
|
||||
food_actions.append("Buns")
|
||||
await context.emit_event(process_event=self.OutputEvents.BunsAdded, data=food_actions)
|
||||
|
||||
|
||||
class AddSpecialSauceStep(KernelProcessStep):
|
||||
class Functions(Enum):
|
||||
AddSpecialSauce = "AddSpecialSauce"
|
||||
|
||||
class OutputEvents(Enum):
|
||||
SpecialSauceAdded = "SpecialSauceAdded"
|
||||
|
||||
@kernel_function(name=Functions.AddSpecialSauce)
|
||||
async def slice_food(self, context: KernelProcessStepContext, food_actions: list[str]):
|
||||
print(f"SPECIAL_SAUCE_ADDED: Special sauce added to ingredient {food_actions[0]}")
|
||||
food_actions.append("Sauce")
|
||||
await context.emit_event(
|
||||
process_event=self.OutputEvents.SpecialSauceAdded,
|
||||
data=food_actions,
|
||||
visibility=KernelProcessEventVisibility.Public,
|
||||
)
|
||||
|
||||
|
||||
class ExternalFriedFishStep(ExternalStep):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(FishSandwichProcess.ProcessEvents.FishSandwichReady)
|
||||
|
||||
|
||||
class FishSandwichProcess:
|
||||
class ProcessEvents(Enum):
|
||||
PrepareFishSandwich = "PrepareFishSandwich"
|
||||
FishSandwichReady = "FishSandwichReady"
|
||||
|
||||
@staticmethod
|
||||
def create_process(process_name: str = "FishSandwichProcess") -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
|
||||
make_fried_fish_step = process_builder.add_step_from_process(FriedFishProcess.create_process())
|
||||
add_buns_step = process_builder.add_step(AddBunStep)
|
||||
add_sauce_step = process_builder.add_step(AddSpecialSauceStep)
|
||||
external_step = process_builder.add_step(ExternalFriedFishStep)
|
||||
|
||||
process_builder.on_input_event(FishSandwichProcess.ProcessEvents.PrepareFishSandwich).send_event_to(
|
||||
make_fried_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
)
|
||||
|
||||
make_fried_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(add_buns_step)
|
||||
|
||||
add_buns_step.on_event(AddBunStep.OutputEvents.BunsAdded).send_event_to(add_sauce_step)
|
||||
|
||||
add_sauce_step.on_event(AddSpecialSauceStep.OutputEvents.SpecialSauceAdded).send_event_to(external_step)
|
||||
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps_v1(
|
||||
process_name: str = "FishSandwichWithStatefulStepsProcess",
|
||||
) -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name, version="FishSandwich.V1")
|
||||
|
||||
make_fried_fish_step = process_builder.add_step_from_process(
|
||||
FriedFishProcess.create_process_with_stateful_steps_v1()
|
||||
)
|
||||
add_buns_step = process_builder.add_step(AddBunStep)
|
||||
add_sauce_step = process_builder.add_step(AddSpecialSauceStep)
|
||||
external_step = process_builder.add_step(ExternalFriedFishStep)
|
||||
|
||||
process_builder.on_input_event(FishSandwichProcess.ProcessEvents.PrepareFishSandwich).send_event_to(
|
||||
make_fried_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
)
|
||||
|
||||
make_fried_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(add_buns_step)
|
||||
|
||||
add_buns_step.on_event(AddBunStep.OutputEvents.BunsAdded).send_event_to(add_sauce_step)
|
||||
|
||||
add_sauce_step.on_event(AddSpecialSauceStep.OutputEvents.SpecialSauceAdded).send_event_to(external_step)
|
||||
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps_v2(
|
||||
process_name: str = "FishSandwichWithStatefulStepsProcess",
|
||||
) -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name, version="FishSandwich.V2")
|
||||
|
||||
make_fried_fish_step = process_builder.add_step_from_process(
|
||||
FriedFishProcess.create_process_with_stateful_steps_v2(),
|
||||
aliases=["FriedFishWithStatefulStepsProcess"],
|
||||
)
|
||||
add_buns_step = process_builder.add_step(AddBunStep)
|
||||
add_sauce_step = process_builder.add_step(AddSpecialSauceStep)
|
||||
external_step = process_builder.add_step(ExternalFriedFishStep)
|
||||
|
||||
process_builder.on_input_event(FishSandwichProcess.ProcessEvents.PrepareFishSandwich).send_event_to(
|
||||
make_fried_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
)
|
||||
|
||||
make_fried_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(add_buns_step)
|
||||
|
||||
add_buns_step.on_event(AddBunStep.OutputEvents.BunsAdded).send_event_to(add_sauce_step)
|
||||
|
||||
add_sauce_step.on_event(AddSpecialSauceStep.OutputEvents.SpecialSauceAdded).send_event_to(external_step)
|
||||
|
||||
return process_builder
|
||||
@@ -0,0 +1,118 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
from enum import Enum
|
||||
|
||||
from samples.getting_started_with_processes.step03.models import FoodIngredients
|
||||
from samples.getting_started_with_processes.step03.steps import (
|
||||
CutFoodStep,
|
||||
FryFoodStep,
|
||||
GatherIngredientsStep,
|
||||
)
|
||||
from samples.getting_started_with_processes.step03.steps.cut_food_with_sharpening_step import (
|
||||
CutFoodWithSharpeningStep,
|
||||
)
|
||||
from samples.getting_started_with_processes.step03.steps.gather_ingredients_step import (
|
||||
GatherIngredientsWithStockStep,
|
||||
)
|
||||
from semantic_kernel.processes import ProcessBuilder
|
||||
from semantic_kernel.processes.kernel_process import (
|
||||
kernel_process_step_metadata,
|
||||
)
|
||||
|
||||
|
||||
@kernel_process_step_metadata("GatherFishIngredient.V1")
|
||||
class GatherFriedFishIngredientsStep(GatherIngredientsStep):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(FoodIngredients.FISH)
|
||||
|
||||
|
||||
@kernel_process_step_metadata("GatherFishIngredient.V2")
|
||||
class GatherFriedFishIngredientsWithStockStep(GatherIngredientsWithStockStep):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(FoodIngredients.FISH)
|
||||
|
||||
|
||||
class FriedFishProcess:
|
||||
class ProcessEvents(Enum):
|
||||
PrepareFriedFish = "PrepareFriedFish"
|
||||
FriedFishReady = FryFoodStep.OutputEvents.FriedFoodReady.value
|
||||
|
||||
@staticmethod
|
||||
def create_process(process_name: str = "FriedFishProcess") -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
gather = process_builder.add_step(GatherFriedFishIngredientsStep)
|
||||
chop = process_builder.add_step(CutFoodStep, name="chopStep")
|
||||
fry = process_builder.add_step(FryFoodStep)
|
||||
|
||||
process_builder.on_input_event(FriedFishProcess.ProcessEvents.PrepareFriedFish).send_event_to(gather)
|
||||
|
||||
gather.on_event(GatherFriedFishIngredientsStep.OutputEvents.IngredientsGathered).send_event_to(
|
||||
chop, function_name=CutFoodStep.Functions.ChopFood
|
||||
)
|
||||
|
||||
chop.on_event(CutFoodStep.OutputEvents.ChoppingReady).send_event_to(fry)
|
||||
fry.on_event(FryFoodStep.OutputEvents.FoodRuined).send_event_to(gather)
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps_v1(
|
||||
process_name: str = "FriedFishWithStatefulStepsProcess",
|
||||
) -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(name=process_name, version="FriedFishProcess.v1")
|
||||
|
||||
gather = process_builder.add_step(GatherFriedFishIngredientsWithStockStep)
|
||||
chop = process_builder.add_step(CutFoodWithSharpeningStep, name="chopStep")
|
||||
fry = process_builder.add_step(FryFoodStep)
|
||||
|
||||
process_builder.on_input_event(FriedFishProcess.ProcessEvents.PrepareFriedFish).send_event_to(gather)
|
||||
|
||||
gather.on_event(GatherFriedFishIngredientsWithStockStep.OutputEvents.IngredientsGathered).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.ChopFood
|
||||
)
|
||||
gather.on_event(GatherFriedFishIngredientsWithStockStep.OutputEvents.IngredientsOutOfStock).stop_process()
|
||||
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.ChoppingReady).send_event_to(fry)
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeNeedsSharpening).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.SharpenKnife
|
||||
)
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeSharpened).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.ChopFood
|
||||
)
|
||||
|
||||
fry.on_event(FryFoodStep.OutputEvents.FoodRuined).send_event_to(gather)
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps_v2(
|
||||
process_name: str = "FriedFishWithStatefulStepsProcess",
|
||||
) -> ProcessBuilder:
|
||||
process_builder = ProcessBuilder(name=process_name, version="FriedFishProcess.v2")
|
||||
|
||||
gather = process_builder.add_step(
|
||||
GatherFriedFishIngredientsWithStockStep,
|
||||
name="gatherFishIngredientStep",
|
||||
aliases=["GatherFriedFishIngredientsWithStockStep"],
|
||||
)
|
||||
chop = process_builder.add_step(
|
||||
CutFoodWithSharpeningStep,
|
||||
name="chopFishStep",
|
||||
aliases=["CutFoodStep"],
|
||||
)
|
||||
fry = process_builder.add_step(FryFoodStep, name="fryFishStep", aliases=["FryFoodStep"])
|
||||
|
||||
process_builder.on_input_event(FriedFishProcess.ProcessEvents.PrepareFriedFish).send_event_to(gather)
|
||||
|
||||
gather.on_event(GatherFriedFishIngredientsWithStockStep.OutputEvents.IngredientsGathered).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.ChopFood
|
||||
)
|
||||
gather.on_event(GatherFriedFishIngredientsWithStockStep.OutputEvents.IngredientsOutOfStock).stop_process()
|
||||
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.ChoppingReady).send_event_to(fry)
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeNeedsSharpening).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.SharpenKnife
|
||||
)
|
||||
chop.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeSharpened).send_event_to(
|
||||
chop, function_name=CutFoodWithSharpeningStep.Functions.ChopFood
|
||||
)
|
||||
|
||||
fry.on_event(FryFoodStep.OutputEvents.FoodRuined).send_event_to(gather)
|
||||
return process_builder
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from samples.getting_started_with_processes.step03.models.food_ingredients import FoodIngredients
|
||||
from samples.getting_started_with_processes.step03.steps.cut_food_step import CutFoodStep
|
||||
from samples.getting_started_with_processes.step03.steps.cut_food_with_sharpening_step import CutFoodWithSharpeningStep
|
||||
from samples.getting_started_with_processes.step03.steps.fry_food_step import FryFoodStep
|
||||
from samples.getting_started_with_processes.step03.steps.gather_ingredients_step import (
|
||||
GatherIngredientsStep,
|
||||
GatherIngredientsWithStockStep,
|
||||
)
|
||||
from semantic_kernel.processes import ProcessBuilder
|
||||
|
||||
|
||||
class GatherPotatoFriesIngredientsStep(GatherIngredientsStep):
|
||||
def __init__(self):
|
||||
super().__init__(FoodIngredients.POTATOES)
|
||||
|
||||
|
||||
class GatherPotatoFriesIngredientsWithStockStep(GatherIngredientsWithStockStep):
|
||||
def __init__(self):
|
||||
super().__init__(FoodIngredients.POTATOES)
|
||||
|
||||
|
||||
class PotatoFriesProcess:
|
||||
class ProcessEvents(Enum):
|
||||
PreparePotatoFries = "PreparePotatoFries"
|
||||
PotatoFriesReady = FryFoodStep.OutputEvents.FriedFoodReady.value
|
||||
|
||||
@staticmethod
|
||||
def create_process(process_name: str = "PotatoFriesProcess"):
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
gather_ingredients_step = process_builder.add_step(GatherPotatoFriesIngredientsStep)
|
||||
slice_step = process_builder.add_step(CutFoodStep, name="sliceStep")
|
||||
fry_step = process_builder.add_step(FryFoodStep)
|
||||
|
||||
process_builder.on_input_event(PotatoFriesProcess.ProcessEvents.PreparePotatoFries).send_event_to(
|
||||
gather_ingredients_step
|
||||
)
|
||||
|
||||
gather_ingredients_step.on_event(
|
||||
GatherPotatoFriesIngredientsStep.OutputEvents.IngredientsGathered
|
||||
).send_event_to(slice_step, function_name=CutFoodStep.Functions.SliceFood)
|
||||
|
||||
slice_step.on_event(CutFoodStep.OutputEvents.SlicingReady).send_event_to(fry_step)
|
||||
|
||||
fry_step.on_event(FryFoodStep.OutputEvents.FoodRuined).send_event_to(gather_ingredients_step)
|
||||
|
||||
return process_builder
|
||||
|
||||
@staticmethod
|
||||
def create_process_with_stateful_steps(process_name: str = "PotatoFriesWithStatefulStepsProcess"):
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
gather_ingredients_step = process_builder.add_step(GatherPotatoFriesIngredientsWithStockStep)
|
||||
slice_step = process_builder.add_step(CutFoodWithSharpeningStep, name="sliceStep")
|
||||
fry_step = process_builder.add_step(FryFoodStep)
|
||||
|
||||
process_builder.on_input_event(PotatoFriesProcess.ProcessEvents.PreparePotatoFries).send_event_to(
|
||||
gather_ingredients_step
|
||||
)
|
||||
|
||||
gather_ingredients_step.on_event(
|
||||
GatherPotatoFriesIngredientsWithStockStep.OutputEvents.IngredientsGathered
|
||||
).send_event_to(slice_step, function_name=CutFoodWithSharpeningStep.Functions.SliceFood)
|
||||
|
||||
gather_ingredients_step.on_event(
|
||||
GatherPotatoFriesIngredientsWithStockStep.OutputEvents.IngredientsOutOfStock
|
||||
).stop_process()
|
||||
|
||||
slice_step.on_event(CutFoodWithSharpeningStep.OutputEvents.SlicingReady).send_event_to(fry_step)
|
||||
|
||||
slice_step.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeNeedsSharpening).send_event_to(
|
||||
slice_step, function_name=CutFoodWithSharpeningStep.Functions.SharpenKnife
|
||||
)
|
||||
|
||||
slice_step.on_event(CutFoodWithSharpeningStep.OutputEvents.KnifeSharpened).send_event_to(
|
||||
slice_step, function_name=CutFoodWithSharpeningStep.Functions.SliceFood
|
||||
)
|
||||
|
||||
fry_step.on_event(FryFoodStep.OutputEvents.FoodRuined).send_event_to(gather_ingredients_step)
|
||||
|
||||
return process_builder
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from samples.getting_started_with_processes.step03.models.food_order_item import FoodItem
|
||||
from samples.getting_started_with_processes.step03.processes.fish_and_chips_process import FishAndChipsProcess
|
||||
from samples.getting_started_with_processes.step03.processes.fish_sandwich_process import FishSandwichProcess
|
||||
from samples.getting_started_with_processes.step03.processes.fried_fish_process import FriedFishProcess
|
||||
from samples.getting_started_with_processes.step03.processes.potato_fries_process import PotatoFriesProcess
|
||||
from samples.getting_started_with_processes.step03.steps.external_step import ExternalStep
|
||||
from semantic_kernel.functions import kernel_function
|
||||
from semantic_kernel.processes import ProcessBuilder
|
||||
from semantic_kernel.processes.kernel_process import KernelProcessStep, KernelProcessStepContext
|
||||
|
||||
|
||||
class PackOrderStep(KernelProcessStep):
|
||||
class Functions(Enum):
|
||||
PackFood = "PackFood"
|
||||
|
||||
class OutputEvents(Enum):
|
||||
FoodPacked = "FoodPacked"
|
||||
|
||||
@kernel_function(name=Functions.PackFood)
|
||||
async def pack_food(self, context: KernelProcessStepContext, food_actions: list[str]):
|
||||
print(f"PACKING_FOOD: Food {food_actions[0]} Packed! - {food_actions}")
|
||||
await context.emit_event(process_event=PackOrderStep.OutputEvents.FoodPacked)
|
||||
|
||||
|
||||
class ExternalSingleOrderStep(ExternalStep):
|
||||
def __init__(self):
|
||||
super().__init__(SingleFoodItemProcess.ProcessEvents.SingleOrderReady)
|
||||
|
||||
|
||||
class DispatchSingleOrderStep(KernelProcessStep):
|
||||
class Functions(Enum):
|
||||
PrepareSingleOrder = "PrepareSingleOrder"
|
||||
|
||||
class OutputEvents(Enum):
|
||||
PrepareFries = "PrepareFries"
|
||||
PrepareFriedFish = "PrepareFriedFish"
|
||||
PrepareFishSandwich = "PrepareFishSandwich"
|
||||
PrepareFishAndChips = "PrepareFishAndChips"
|
||||
|
||||
@kernel_function(name=Functions.PrepareSingleOrder)
|
||||
async def dispatch_single_order(self, context: KernelProcessStepContext, food_item: FoodItem):
|
||||
food_name = food_item.to_friendly_string()
|
||||
print(f"DISPATCH_SINGLE_ORDER: Dispatching '{food_name}'!")
|
||||
food_actions = []
|
||||
|
||||
if food_item == FoodItem.POTATO_FRIES:
|
||||
await context.emit_event(process_event=DispatchSingleOrderStep.OutputEvents.PrepareFries, data=food_actions)
|
||||
|
||||
elif food_item == FoodItem.FRIED_FISH:
|
||||
await context.emit_event(
|
||||
process_event=DispatchSingleOrderStep.OutputEvents.PrepareFriedFish, data=food_actions
|
||||
)
|
||||
|
||||
elif food_item == FoodItem.FISH_SANDWICH:
|
||||
await context.emit_event(
|
||||
process_event=DispatchSingleOrderStep.OutputEvents.PrepareFishSandwich, data=food_actions
|
||||
)
|
||||
|
||||
elif food_item == FoodItem.FISH_AND_CHIPS:
|
||||
await context.emit_event(
|
||||
process_event=DispatchSingleOrderStep.OutputEvents.PrepareFishAndChips, data=food_actions
|
||||
)
|
||||
|
||||
|
||||
class SingleFoodItemProcess:
|
||||
class ProcessEvents(Enum):
|
||||
SingleOrderReceived = "SingleOrderReceived"
|
||||
SingleOrderReady = "SingleOrderReady"
|
||||
|
||||
@staticmethod
|
||||
def create_process(process_name: str = "SingleFoodItemProcess"):
|
||||
process_builder = ProcessBuilder(process_name)
|
||||
|
||||
dispatch_order_step = process_builder.add_step(DispatchSingleOrderStep)
|
||||
make_fried_fish_step = process_builder.add_step_from_process(FriedFishProcess.create_process())
|
||||
make_potato_fries_step = process_builder.add_step_from_process(PotatoFriesProcess.create_process())
|
||||
make_fish_sandwich_step = process_builder.add_step_from_process(FishSandwichProcess.create_process())
|
||||
make_fish_and_chips_step = process_builder.add_step_from_process(FishAndChipsProcess.create_process())
|
||||
pack_order_step = process_builder.add_step(PackOrderStep)
|
||||
external_step = process_builder.add_step(ExternalSingleOrderStep)
|
||||
|
||||
process_builder.on_input_event(SingleFoodItemProcess.ProcessEvents.SingleOrderReceived).send_event_to(
|
||||
dispatch_order_step
|
||||
)
|
||||
|
||||
dispatch_order_step.on_event(DispatchSingleOrderStep.OutputEvents.PrepareFriedFish).send_event_to(
|
||||
make_fried_fish_step.where_input_event_is(FriedFishProcess.ProcessEvents.PrepareFriedFish)
|
||||
)
|
||||
|
||||
dispatch_order_step.on_event(DispatchSingleOrderStep.OutputEvents.PrepareFries).send_event_to(
|
||||
make_potato_fries_step.where_input_event_is(PotatoFriesProcess.ProcessEvents.PreparePotatoFries)
|
||||
)
|
||||
|
||||
dispatch_order_step.on_event(DispatchSingleOrderStep.OutputEvents.PrepareFishSandwich).send_event_to(
|
||||
make_fish_sandwich_step.where_input_event_is(FishSandwichProcess.ProcessEvents.PrepareFishSandwich)
|
||||
)
|
||||
|
||||
dispatch_order_step.on_event(DispatchSingleOrderStep.OutputEvents.PrepareFishAndChips).send_event_to(
|
||||
make_fish_and_chips_step.where_input_event_is(FishAndChipsProcess.ProcessEvents.PrepareFishAndChips)
|
||||
)
|
||||
|
||||
make_fried_fish_step.on_event(FriedFishProcess.ProcessEvents.FriedFishReady).send_event_to(pack_order_step)
|
||||
|
||||
make_potato_fries_step.on_event(PotatoFriesProcess.ProcessEvents.PotatoFriesReady).send_event_to(
|
||||
pack_order_step
|
||||
)
|
||||
|
||||
make_fish_sandwich_step.on_event(FishSandwichProcess.ProcessEvents.FishSandwichReady).send_event_to(
|
||||
pack_order_step
|
||||
)
|
||||
|
||||
make_fish_and_chips_step.on_event(FishAndChipsProcess.ProcessEvents.FishAndChipsReady).send_event_to(
|
||||
pack_order_step
|
||||
)
|
||||
|
||||
pack_order_step.on_event(PackOrderStep.OutputEvents.FoodPacked).send_event_to(external_step)
|
||||
|
||||
return process_builder
|
||||
Reference in New Issue
Block a user