mirror of
https://github.com/run-llama/workflows-py.git
synced 2026-07-19 16:53:35 -04:00
db90f89b74
* prep packages * wrong coverage detection I think * add ts deps? * extend path for namespaces * the big move, import issues though * llama_index.workflows * llama_agents * alias may be working * add type checker ignores for workflows secondary namespace, update ty, and add re-exports * Add descriptions to new client and server packages Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Rather, commit the outputs * keep the py files separate * ignore examples deps * Create afraid-books-own.md --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
34 lines
875 B
Python
34 lines
875 B
Python
import asyncio
|
|
|
|
from llama_agents.server import WorkflowServer
|
|
from workflows import Workflow, step
|
|
from workflows.context import Context
|
|
from workflows.events import Event, StartEvent, StopEvent
|
|
|
|
|
|
class StreamEvent(Event):
|
|
sequence: int
|
|
|
|
|
|
class GreetingWorkflow(Workflow):
|
|
@step
|
|
async def greet(self, ctx: Context, ev: StartEvent) -> StopEvent:
|
|
for i in range(3):
|
|
ctx.write_event_to_stream(StreamEvent(sequence=i))
|
|
await asyncio.sleep(0.3)
|
|
|
|
name = getattr(ev, "name", "World")
|
|
return StopEvent(result=f"Hello, {name}!")
|
|
|
|
|
|
server = WorkflowServer()
|
|
server.add_workflow("greeting", GreetingWorkflow())
|
|
|
|
|
|
# This is to test the server locally, run with `uv run python app.py`
|
|
if __name__ == "__main__":
|
|
try:
|
|
asyncio.run(server.serve(host="localhost", port=8080))
|
|
except KeyboardInterrupt:
|
|
pass
|