Use this file to discover all available pages before exploring further.
What this builds. Two demonstrations of cancellation against a slow LLM pipeline: (1) handler.terminate() on the RunHandler returned by pipeline.start(...), and (2) pipeline.terminate(run_id=...) using the raw task id.
You’ll end up with. Two terminated runs with their post-termination status visible, useful when wiring a user “Stop generating” button.
import timefrom vectorshift.pipeline import Pipeline# Create an LLM pipeline (LLM calls take a few seconds, giving time to terminate)PIPELINE_NAME = "terminate_example"try: pipeline = Pipeline.fetch(name=PIPELINE_NAME) print(f"Pipeline fetched: id={pipeline.id}, branch_id={pipeline.branch_id}")except Exception as e: print(f"Error fetching pipeline: {e}") pipeline = Pipeline.new(name=PIPELINE_NAME) print(f"Pipeline created: id={pipeline.id}, branch_id={pipeline.branch_id}")inp = pipeline.add(name="input_0", id="input_0").input(input_type="string")llm = pipeline.add(name="llm", id="llm").llm( provider="openai", model="gpt-4o", prompt=inp.text)out = pipeline.add(name="output_0", id="output_0").output( output_type="string", value=llm.response)pipeline.save(deploy=True)# Start a background run and terminate via RunHandlerhandler = pipeline.start( inputs={"input_0": "Write a 500 word essay about the history of computing."})print(f"Started: {handler.task_id}")time.sleep(2)result = handler.terminate()print(f"Terminated via handler: {result}")print(f"Status after termination: {handler.run_status()}")# Start another and terminate via Pipeline directly using a run_idhandler2 = pipeline.start( inputs={"input_0": "Write another 500 word essay about robotics."})time.sleep(2)result2 = pipeline.terminate(run_id=handler2.task_id)print(f"Terminated via pipeline: {result2}")