/ examples / workflow_quickstart.py
workflow_quickstart.py
 1  """
 2  Workflow Quick Start
 3  Easy to use way to get started with deterministic workflows.
 4  
 5  TxtAI has many example notebooks covering everything the framework provides
 6  Examples: https://neuml.github.io/txtai/examples
 7  
 8  Install TxtAI
 9    pip install txtai[pipeline-data]
10  """
11  
12  from txtai import LLM, Workflow
13  from txtai.pipeline import Summary, Textractor, Translation
14  from txtai.workflow import Task
15  
16  # Step 1: Define available pipelines
17  textractor = Textractor(backend="docling", headers={"user-agent": "Mozilla/5.0"})
18  summary = Summary()
19  translate = Translation()
20  
21  # Step 2: Define workflow tasks
22  workflow = Workflow([Task(textractor), Task(summary), Task(lambda inputs: [translate(x, "fr") for x in inputs])])
23  
24  # Step 3: Run the workflow
25  print(list(workflow(["https://neuml.com"])))
26  
27  # Each component above is a single model that specializes in a task
28  # LLMs can also be used to accomplish the same tasks
29  
30  
31  # pylint: disable=E0102,C0116
32  def summary(text):
33      return f"""
34  Summarize the following text in 40 words or less.
35  
36  {text}
37  """
38  
39  
40  def translate(text, language):
41      return f"""
42  Translate the following text to {language}.
43  
44  {text}
45  """
46  
47  
48  textractor = Textractor(backend="docling", headers={"user-agent": "Mozilla/5.0"})
49  llm = LLM("Qwen/Qwen3-4B-Instruct-2507")
50  
51  workflow = Workflow(
52      [
53          Task(textractor),
54          Task(lambda inputs: llm([summary(x) for x in inputs], maxlength=25000, defaultrole="user")),
55          Task(lambda inputs: llm([translate(x, "fr") for x in inputs], maxlength=25000, defaultrole="user")),
56      ]
57  )
58  
59  print(list(workflow(["https://neuml.com"])))