{ "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 }