File size: 5,391 Bytes
b499f04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "716e0803-982b-49eb-926f-4d7bc1d24c71",
   "metadata": {},
   "source": [
    "# 5 Workflow Design Pattern"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13d96dc6",
   "metadata": {},
   "source": [
    "### 1. Prompt Chaining : \n",
    "Result from one llm to another llm"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "633cd510-5697-4890-a527-c36942a1c2d0",
   "metadata": {},
   "source": [
    "```mermaid\n",
    "flowchart LR\n",
    "    IN((IN)):::in --> LLM1[LLM1]:::llm\n",
    "    LLM1 --> Gate[Gate]:::gate\n",
    "    Gate --> LLM2[LLM2]:::llm\n",
    "    LLM2 --> LLM3[LLM3]:::llm\n",
    "    LLM3 --> OUT((OUT)):::out\n",
    "\n",
    "    classDef in fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef out fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef llm fill:#b58900,stroke:#000,color:#fff;\n",
    "    classDef gate fill:#1f77b4,stroke:#000,color:#fff;\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf9dc153-87a4-4a1a-b045-488408b2b944",
   "metadata": {},
   "source": [
    "### 2. Routing\n",
    "One LLM acts as a router to route to specialist llms"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c5e9561-643f-4368-8c35-94482134ddca",
   "metadata": {},
   "source": [
    "```mermaid\n",
    "flowchart LR\n",
    "    IN((IN)):::in --> Router[LLM Router]:::gate\n",
    "    Router --> LLM1[LLM1]:::llm\n",
    "    Router --> LLM2[LLM2]:::llm\n",
    "    Router --> LLM3[LLM3]:::llm\n",
    "    LLM1 --> OUT((OUT)):::out\n",
    "    LLM2 --> OUT\n",
    "    LLM3 --> OUT\n",
    "\n",
    "    classDef in fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef out fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef llm fill:#b58900,stroke:#000,color:#fff;\n",
    "    classDef gate fill:#1f77b4,stroke:#000,color:#fff;\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56c725b5-38b0-4cc0-8713-5a5d300e5a5c",
   "metadata": {},
   "source": [
    "### 3. Parallelization\n",
    "Code as a router and in parallel sent to llms for answer and then again code aggregates and send final output "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "555129f1-3d4f-46b3-a154-afb8331508ef",
   "metadata": {},
   "source": [
    "```mermaid\n",
    "flowchart LR\n",
    "    IN((IN)):::in --> Coord[Coordinator]:::gate\n",
    "    Coord --> LLM1[LLM1]:::llm\n",
    "    Coord --> LLM2[LLM2]:::llm\n",
    "    Coord --> LLM3[LLM3]:::llm\n",
    "    LLM1 --> Agg[Aggregator]:::gate\n",
    "    LLM2 --> Agg\n",
    "    LLM3 --> Agg\n",
    "    Agg --> OUT((OUT)):::out\n",
    "\n",
    "    classDef in fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef out fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef llm fill:#b58900,stroke:#000,color:#fff;\n",
    "    classDef gate fill:#1f77b4,stroke:#000,color:#fff;\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65b5521e-1f5f-4e96-90f6-d85b8f2b4624",
   "metadata": {},
   "source": [
    "### 4. Orchestrator-Worker\n",
    "Similar to Parallelization but instead of code, it is LLM"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed59e3a1-a64f-4619-b051-5fa42575f56a",
   "metadata": {},
   "source": [
    "```mermaid\n",
    "flowchart LR\n",
    "    IN((IN)):::in --> Orchestrator[Orchestrator]:::llm\n",
    "    Orchestrator --> LLM1[LLM1]:::llm\n",
    "    Orchestrator --> LLM2[LLM2]:::llm\n",
    "    Orchestrator --> LLM3[LLM3]:::llm\n",
    "    LLM1 --> Synth[Synthesizer]:::gate\n",
    "    LLM2 --> Synth\n",
    "    LLM3 --> Synth\n",
    "    Synth --> OUT((OUT)):::out\n",
    "\n",
    "    classDef in fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef out fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef llm fill:#b58900,stroke:#000,color:#fff;\n",
    "    classDef gate fill:#1f77b4,stroke:#000,color:#fff;\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57c7109b",
   "metadata": {},
   "source": [
    "### 5. Evaluator-Optimizer\n",
    "LLM Output is evaluated by another LLM and it either accepts or reject the answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "439b4e7d-1009-418a-b88c-a4f5bd089bd5",
   "metadata": {},
   "source": [
    "```mermaid\n",
    "flowchart LR\n",
    "    IN((IN)):::in --> Generator[LLM Generator]:::llm\n",
    "    Generator --> Evaluator[LLM Evaluator]:::llm\n",
    "    Evaluator -->|Accepted| OUT((OUT)):::out\n",
    "    Evaluator -.->|Rejected with Feedback| Generator\n",
    "\n",
    "    classDef in fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef out fill:#ff7f0e,stroke:#000,color:#fff;\n",
    "    classDef llm fill:#b58900,stroke:#000,color:#fff;\n",
    "    classDef gate fill:#1f77b4,stroke:#000,color:#fff;\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97096f3a-0c5f-4ff8-9b20-7cb7fce2195f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}