kumardatascience/Multi-Source-RAG-AI-System-with-Query-Routing
1
1"""Tiny workflow demo to understand the pattern. Not used by the chatbot."""2 3import asyncio4from llama_index.core.workflow import (5 Workflow,6 step,7 Event,8 StartEvent,9 StopEvent,10)11 12# 1. Define our custom event types (just data containers)13class GreetingEvent(Event):14 message: str15 16 17class ShoutingEvent(Event):18 message: str19 20 21# 2. Define the workflow with its steps22class DemoWorkflow(Workflow):23 24 @step25 async def greet(self, ev: StartEvent) -> GreetingEvent:26 """Step 1: receives the start, emits a greeting."""27 print("๐ Step 1: greeting...")28 return GreetingEvent(message=f"Hello, {ev.name}!")29 30 @step31 async def shout(self, ev: GreetingEvent) -> ShoutingEvent:32 """Step 2: takes the greeting, shouts it."""33 print("๐ข Step 2: shouting...")34 return ShoutingEvent(message=ev.message.upper())35 36 @step37 async def finish(self, ev: ShoutingEvent) -> StopEvent:38 """Step 3: ends the workflow with the final result."""39 print("๐ Step 3: done.")40 return StopEvent(result=ev.message)41 42 43# 3. Run it44async def main():45 wf = DemoWorkflow()46 result = await wf.run(name="Mihir")47 print(f"\nFinal result: {result}")48 49 50if __name__ == "__main__":51 asyncio.run(main())