Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Moves demos into the right place. We have a half-baked demo for the kitchen sink.

elijahbenizzy8d0def3794a3
diff --git a/docs/contributing/contributing.rst b/docs/contributing/contributing.rst
index a0f955ce..450a6439 100644
--- a/docs/contributing/contributing.rst
+++ b/docs/contributing/contributing.rst
@@ -32,7 +32,8 @@ All examples must have the following files:
4. A ``statemachine.png`` file that shows the DAG for the example
3. A `notebook.ipynb` file that uses the example in a
-The ``notebook.ipynb`` can import stuff from the ``application.py``, or redefine it as an example.
+The ``notebook.ipynb`` can import stuff from the ``application.py``, or redefine it as an example. If you have something
+that does not fit this, or is a prototype but you want to push it in, you can fit in under the ``half-baked`` directory.
---------------
Developer notes
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 00000000..e69de29b
diff --git a/examples/conversational_rag/README.md b/examples/conversational-rag/README.md
similarity index 100%
rename from examples/conversational_rag/README.md
rename to examples/conversational-rag/README.md
diff --git a/examples/conversational_rag/application.py b/examples/conversational-rag/application.py
similarity index 100%
rename from examples/conversational_rag/application.py
rename to examples/conversational-rag/application.py
diff --git a/examples/conversational_rag/conversational_rag.png b/examples/conversational-rag/conversational_rag.png
similarity index 100%
rename from examples/conversational_rag/conversational_rag.png
rename to examples/conversational-rag/conversational_rag.png
diff --git a/examples/conversational_rag/notebook.ipynb b/examples/conversational-rag/notebook.ipynb
similarity index 100%
rename from examples/conversational_rag/notebook.ipynb
rename to examples/conversational-rag/notebook.ipynb
diff --git a/examples/conversational_rag/requirements.txt b/examples/conversational-rag/requirements.txt
similarity index 100%
rename from examples/conversational_rag/requirements.txt
rename to examples/conversational-rag/requirements.txt
diff --git a/examples/cowsay/README.md b/examples/cowsay/README.md
deleted file mode 100644
index 2fe0194e..00000000
--- a/examples/cowsay/README.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# Cowsay
-
-This is an example of a simple infinite state machine.
-
-We have three files:
-
-- [application.py](application.py) -- This contains a mainline to run the cowsay app as well as a function to export the app (for later use)
-- [requirements.txt](requirements.txt) -- Just the requirements. All this needs is Burr/Streamlit/cowsay
-- [streamlit_app.py](streamlit_app.py) -- This contains a simple Streamlit app to interact with the cow
-
-To run just the application, you can run:
-
-```bash
-python application.py
-```
-
-Note this is an infinte state machine, so this will run forever! Thus remember to ctrl-c eventually.
-To run the streamlit app, you can run:
-
-```bash
-streamlit run streamlit_app.py
-```
-
-This allows you to press a button and see the cow say something (or see it decide not to speak).
-
-This will open a chrome window and print out the URL. The state machine this encapsulates takes the following form:
-
-![State Machine](digraph.png)
diff --git a/examples/cowsay/application.py b/examples/cowsay/application.py
deleted file mode 100644
index c2bc2bd5..00000000
--- a/examples/cowsay/application.py
+++ /dev/null
@@ -1,76 +0,0 @@
-import random
-import time
-from typing import Tuple
-
-import cowsay
-
-from burr.core import Action, Application, ApplicationBuilder, State, default, expr
-from burr.core.action import action
-from burr.lifecycle import PostRunStepHook
-
-
-class PrintWhatTheCowSaid(PostRunStepHook):
- def post_run_step(self, *, state: "State", action: "Action", **future_kwargs):
- if action.name != "cow_should_say" and state["cow_said"] is not None:
- print(state["cow_said"])
-
-
-class CowCantSpeakFast(PostRunStepHook):
- def __init__(self, sleep_time: float):
- super(PostRunStepHook, self).__init__()
- self.sleep_time = sleep_time
-
- def post_run_step(self, *, state: "State", action: "Action", **future_kwargs):
- if action.name != "cow_should_say": # no need to print if we're not saying anything
- time.sleep(self.sleep_time)
-
-
-@action(reads=[], writes=["cow_said"])
-def cow_said(state: State, say_what: list[str]) -> Tuple[dict, State]:
- said = random.choice(say_what)
- result = {"cow_said": cowsay.get_output_string("cow", said) if say_what is not None else None}
- return result, state.update(**result)
-
-
-@action(reads=[], writes=["cow_should_speak"])
-def cow_should_speak(state: State) -> Tuple[dict, State]:
- result = {"cow_should_speak": random.randint(0, 3) == 0}
- return result, state.update(**result)
-
-
-def application(in_terminal: bool = False) -> Application:
- hooks = (
- [
- PrintWhatTheCowSaid(),
- CowCantSpeakFast(sleep_time=2.0),
- ]
- if in_terminal
- else []
- )
- return (
- ApplicationBuilder()
- .with_state(cow_said=None)
- .with_actions(
- say_nothing=cow_said.bind(say_what=None),
- say_hello=cow_said.bind(
- say_what=["Hello world!", "What's up?", "Are you Aaron Burr, sir?"]
- ),
- cow_should_speak=cow_should_speak,
- )
- .with_transitions(
- ("cow_should_speak", "say_hello", expr("cow_should_speak")),
- ("say_hello", "cow_should_speak", default),
- ("cow_should_speak", "say_nothing", expr("not cow_should_speak")),
- ("say_nothing", "cow_should_speak", default),
- )
- .with_entrypoint("cow_should_speak")
- .with_hooks(*hooks)
- .build()
- )
-
-
-if __name__ == "__main__":
- app = application(in_terminal=True)
- app.visualize(output_file_path="digraph", include_conditions=True, view=True, format="png")
- while True:
- action, result, state = app.step()
diff --git a/examples/cowsay/digraph.png b/examples/cowsay/digraph.png
deleted file mode 100644
index 5418c954..00000000
Binary files a/examples/cowsay/digraph.png and /dev/null differ
diff --git a/examples/cowsay/notebook.ipynb b/examples/cowsay/notebook.ipynb
deleted file mode 100644
index 3f4e8b26..00000000
--- a/examples/cowsay/notebook.ipynb
+++ /dev/null
@@ -1,313 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "initial_id",
- "metadata": {
- "collapsed": true,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:12:50.561804Z",
- "start_time": "2024-03-27T00:12:50.531039Z"
- }
- },
- "outputs": [],
- "source": [
- "import random\n",
- "import time\n",
- "from typing import Tuple\n",
- "\n",
- "import cowsay\n",
- "\n",
- "from burr.core import Action, Application, ApplicationBuilder, State, default, expr\n",
- "from burr.core.action import action\n",
- "from burr.lifecycle import PostRunStepHook"
- ]
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "# create some hooks!\n",
- "class PrintWhatTheCowSaid(PostRunStepHook):\n",
- " def post_run_step(self, *, state: \"State\", action: \"Action\", **future_kwargs):\n",
- " if action.name != \"cow_should_say\" and state[\"cow_said\"] is not None:\n",
- " print(state[\"cow_said\"])\n",
- "\n",
- "\n",
- "class CowCantSpeakFast(PostRunStepHook):\n",
- " def __init__(self, sleep_time: float):\n",
- " super(PostRunStepHook, self).__init__()\n",
- " self.sleep_time = sleep_time\n",
- "\n",
- " def post_run_step(self, *, state: \"State\", action: \"Action\", **future_kwargs):\n",
- " if action.name != \"cow_should_say\": # no need to print if we're not saying anything\n",
- " time.sleep(self.sleep_time)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:13:03.529875Z",
- "start_time": "2024-03-27T00:13:03.524449Z"
- }
- },
- "id": "9f5b9bfc78851a59",
- "execution_count": 3
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "# instantiate actions\n",
- "@action(reads=[], writes=[\"cow_said\"])\n",
- "def cow_said(state: State, say_what: list[str]) -> Tuple[dict, State]:\n",
- " said = random.choice(say_what)\n",
- " result = {\"cow_said\": cowsay.get_output_string(\"cow\", said) if say_what is not None else None}\n",
- " return result, state.update(**result)\n",
- "\n",
- "\n",
- "@action(reads=[], writes=[\"cow_should_speak\"])\n",
- "def cow_should_speak(state: State) -> Tuple[dict, State]:\n",
- " result = {\"cow_should_speak\": random.randint(0, 3) == 0}\n",
- " return result, state.update(**result)\n"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:13:12.756137Z",
- "start_time": "2024-03-27T00:13:12.750764Z"
- }
- },
- "id": "5b29e9de2ca536b9",
- "execution_count": 4
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "# build application\n",
- "hooks = [\n",
- " PrintWhatTheCowSaid(),\n",
- " CowCantSpeakFast(sleep_time=2.0),\n",
- "]\n",
- " \n",
- "app = (ApplicationBuilder()\n",
- " .with_state(cow_said=None)\n",
- " .with_actions(\n",
- " say_nothing=cow_said.bind(say_what=None),\n",
- " say_hello=cow_said.bind(\n",
- " say_what=[\"Hello world!\", \"What's up?\", \"Are you Aaron Burr, sir?\"]\n",
- " ),\n",
- " cow_should_speak=cow_should_speak,\n",
- " )\n",
- " .with_transitions(\n",
- " (\"cow_should_speak\", \"say_hello\", expr(\"cow_should_speak\")),\n",
- " (\"say_hello\", \"cow_should_speak\", default),\n",
- " (\"cow_should_speak\", \"say_nothing\", expr(\"not cow_should_speak\")),\n",
- " (\"say_nothing\", \"cow_should_speak\", default),\n",
- " )\n",
- " .with_entrypoint(\"cow_should_speak\")\n",
- " .with_hooks(*hooks)\n",
- " .build()\n",
- ")"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:14:10.836543Z",
- "start_time": "2024-03-27T00:14:10.829258Z"
- }
- },
- "id": "271b868317fbbdf4",
- "execution_count": 5
- },
- {
- "cell_type": "code",
- "outputs": [
- {
- "data": {
- "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 9.0.0 (20230911.1827)\n -->\n<!-- Pages: 1 -->\n<svg width=\"192pt\" height=\"209pt\"\n viewBox=\"0.00 0.00 192.02 209.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 205)\">\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-205 188.02,-205 188.02,4 -4,4\"/>\n<!-- say_nothing -->\n<g id=\"node1\" class=\"node\">\n<title>say_nothing</title>\n<path fill=\"none\" stroke=\"black\" d=\"M89.27,-201C89.27,-201 31.27,-201 31.27,-201 25.27,-201 19.27,-195 19.27,-189 19.27,-189 19.27,-177 19.27,-177 19.27,-171 25.27,-165 31.27,-165 31.27,-165 89.27,-165 89.27,-165 95.27,-165 101.27,-171 101.27,-177 101.27,-177 101.27,-189 101.27,-189 101.27,-195 95.27,-201 89.27,-201\"/>\n<text text-anchor=\"middle\" x=\"60.27\" y=\"-177.95\" font-family=\"Times,serif\" font-size=\"14.00\">say_nothing</text>\n</g>\n<!-- cow_should_speak -->\n<g id=\"node3\" class=\"node\">\n<title>cow_should_speak</title>\n<path fill=\"none\" stroke=\"black\" d=\"M107.65,-118.5C107.65,-118.5 12.9,-118.5 12.9,-118.5 6.9,-118.5 0.9,-112.5 0.9,-106.5 0.9,-106.5 0.9,-94.5 0.9,-94.5 0.9,-88.5 6.9,-82.5 12.9,-82.5 12.9,-82.5 107.65,-82.5 107.65,-82.5 113.65,-82.5 119.65,-88.5 119.65,-94.5 119.65,-94.5 119.65,-106.5 119.65,-106.5 119.65,-112.5 113.65,-118.5 107.65,-118.5\"/>\n<text text-anchor=\"middle\" x=\"60.27\" y=\"-95.45\" font-family=\"Times,serif\" font-size=\"14.00\">cow_should_speak</text>\n</g>\n<!-- say_nothing&#45;&gt;cow_should_speak -->\n<g id=\"edge4\" class=\"edge\">\n<title>say_nothing&#45;&gt;cow_should_speak</title>\n<path fill=\"none\" stroke=\"black\" d=\"M58.99,-164.74C58.7,-159.97 58.42,-154.78 58.27,-150 58.04,-142.67 58.04,-140.83 58.27,-133.5 58.31,-132.3 58.35,-131.08 58.41,-129.85\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"61.88,-130.45 58.91,-120.27 54.89,-130.07 61.88,-130.45\"/>\n</g>\n<!-- say_hello -->\n<g id=\"node2\" class=\"node\">\n<title>say_hello</title>\n<path fill=\"none\" stroke=\"black\" d=\"M82.15,-36C82.15,-36 38.4,-36 38.4,-36 32.4,-36 26.4,-30 26.4,-24 26.4,-24 26.4,-12 26.4,-12 26.4,-6 32.4,0 38.4,0 38.4,0 82.15,0 82.15,0 88.15,0 94.15,-6 94.15,-12 94.15,-12 94.15,-24 94.15,-24 94.15,-30 88.15,-36 82.15,-36\"/>\n<text text-anchor=\"middle\" x=\"60.27\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">say_hello</text>\n</g>\n<!-- say_hello&#45;&gt;cow_should_speak -->\n<g id=\"edge2\" class=\"edge\">\n<title>say_hello&#45;&gt;cow_should_speak</title>\n<path fill=\"none\" stroke=\"black\" d=\"M93.05,-36.42C97.97,-40.53 102.37,-45.38 105.27,-51 108.63,-57.52 108.63,-60.98 105.27,-67.5 104.09,-69.78 102.67,-71.94 101.06,-73.97\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"98.65,-71.43 94.11,-81 103.63,-76.35 98.65,-71.43\"/>\n</g>\n<!-- cow_should_speak&#45;&gt;say_nothing -->\n<g id=\"edge3\" class=\"edge\">\n<title>cow_should_speak&#45;&gt;say_nothing</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M60.27,-118.93C60.27,-128.95 60.27,-141.78 60.27,-153.25\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"56.77,-153.02 60.27,-163.02 63.77,-153.02 56.77,-153.02\"/>\n<text text-anchor=\"middle\" x=\"122.15\" y=\"-136.7\" font-family=\"Times,serif\" font-size=\"14.00\">not cow_should_speak</text>\n</g>\n<!-- cow_should_speak&#45;&gt;say_hello -->\n<g id=\"edge1\" class=\"edge\">\n<title>cow_should_speak&#45;&gt;say_hello</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M16.41,-82.17C10.87,-78.17 5.95,-73.33 2.52,-67.5 -4.42,-55.72 3.91,-45.49 16.2,-37.49\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"17.9,-40.55 24.87,-32.57 14.44,-34.46 17.9,-40.55\"/>\n<text text-anchor=\"middle\" x=\"54.65\" y=\"-54.2\" font-family=\"Times,serif\" font-size=\"14.00\">cow_should_speak</text>\n</g>\n</g>\n</svg>\n",
- "text/plain": "<graphviz.graphs.Digraph at 0x1107a98a0>"
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "app.visualize(include_conditions=True)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:14:29.829383Z",
- "start_time": "2024-03-27T00:14:29.511355Z"
- }
- },
- "id": "794bc0abda9e48ad",
- "execution_count": 6
- },
- {
- "cell_type": "code",
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n"
- ]
- }
- ],
- "source": [
- "# run things!\n",
- "for i in range(0, 4):\n",
- " # step through 4 times\n",
- " a_obj, result, state = app.step()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:16:40.234406Z",
- "start_time": "2024-03-27T00:16:32.211734Z"
- }
- },
- "id": "2facfb753233cd7d",
- "execution_count": 11
- },
- {
- "cell_type": "code",
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- " ________________________\n",
- "| Are you Aaron Burr, sir? |\n",
- " ========================\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ________________________\n",
- "| Are you Aaron Burr, sir? |\n",
- " ========================\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n",
- " ____________\n",
- "| Hello world! |\n",
- " ============\n",
- " \\\n",
- " \\\n",
- " ^__^\n",
- " (oo)\\_______\n",
- " (__)\\ )\\/\\\n",
- " ||----w |\n",
- " || ||\n"
- ]
- }
- ],
- "source": [
- "# Run some more\n",
- "for i in range(0, 4):\n",
- " # step through 4 times\n",
- " a_obj, result, state = app.step()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-03-27T00:17:18.640978Z",
- "start_time": "2024-03-27T00:17:10.619878Z"
- }
- },
- "id": "fed65721e7cc457a",
- "execution_count": 16
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [],
- "metadata": {
- "collapsed": false
- },
- "id": "19095ae96e98fd83"
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}
diff --git a/examples/cowsay/requirements.txt b/examples/cowsay/requirements.txt
deleted file mode 100644
index ee7475ae..00000000
--- a/examples/cowsay/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-burr[streamlit,graphviz]
-cowsay
diff --git a/examples/cowsay/streamlit_app.py b/examples/cowsay/streamlit_app.py
deleted file mode 100644
index 8db01336..00000000
--- a/examples/cowsay/streamlit_app.py
+++ /dev/null
@@ -1,69 +0,0 @@
-import application as cowsay_application
-import streamlit as st
-
-from burr.integrations.streamlit import (
- AppState,
- Record,
- get_state,
- render_explorer,
- set_slider_to_current,
- update_state,
-)
-
-
-def cow_say_view(app_state: AppState):
- application = app_state.app
- button = st.button("Cow say?", use_container_width=True)
- if button:
- step_output = application.step()
- action, result, state = step_output
- app_state.history.append(Record(state.get_all(), action.name, result))
- set_slider_to_current()
-
-
-def render_cow_said(record: Record):
- cow_said = record.state.get("cow_said")
- cow_should_speak = record.state.get("cow_should_speak")
- with st.chat_message("cow", avatar="🐮" if cow_should_speak and cow_said else "💭"):
- grey = "#A9A9A9"
- if record.action == "cow_should_say":
- if cow_should_speak:
- st.markdown(
- f"<p style='color: {grey};'>Cow will not speak.</p>", unsafe_allow_html=True
- )
- else:
- st.markdown(
- f"<p style='color: {grey};'>Cow will not speak.</p>", unsafe_allow_html=True
- )
- else:
- if cow_said is None:
- st.markdown(f"<p style='color: {grey};'>...</p>", unsafe_allow_html=True)
- if cow_said is not None:
- st.code(cow_said, language="plaintext")
-
-
-def retrieve_state():
- if "burr_state" not in st.session_state:
- state = AppState.from_empty(app=cowsay_application.application())
- else:
- state = get_state()
- return state
-
-
-def main():
- st.set_page_config(layout="wide")
- st.title("Talking cows with Burr")
- app_state = retrieve_state() # retrieve first so we can use for the ret of the step
- columns = st.columns(2)
- with columns[0]:
- cow_say_view(app_state)
- with st.container(height=800):
- for item in app_state.history:
- render_cow_said(item)
- with columns[1]:
- render_explorer(app_state)
- update_state(app_state) # update so the next iteration knows what to do
-
-
-if __name__ == "__main__":
- main()
diff --git a/examples/counter/README.md b/examples/hello-world-counter/counter/README.md
similarity index 100%
rename from examples/counter/README.md
rename to examples/hello-world-counter/counter/README.md
diff --git a/examples/counter/application.py b/examples/hello-world-counter/counter/application.py
similarity index 100%
rename from examples/counter/application.py
rename to examples/hello-world-counter/counter/application.py
diff --git a/examples/counter/digraph.png b/examples/hello-world-counter/counter/digraph.png
similarity index 100%
rename from examples/counter/digraph.png
rename to examples/hello-world-counter/counter/digraph.png
diff --git a/examples/counter/notebook.ipynb b/examples/hello-world-counter/counter/notebook.ipynb
similarity index 100%
rename from examples/counter/notebook.ipynb
rename to examples/hello-world-counter/counter/notebook.ipynb
diff --git a/examples/counter/requirements.txt b/examples/hello-world-counter/counter/requirements.txt
similarity index 100%
rename from examples/counter/requirements.txt
rename to examples/hello-world-counter/counter/requirements.txt
diff --git a/examples/counter/streamlit_app.py b/examples/hello-world-counter/counter/streamlit_app.py
similarity index 100%
rename from examples/counter/streamlit_app.py
rename to examples/hello-world-counter/counter/streamlit_app.py
diff --git a/examples/image_telephone/README.md b/examples/image_telephone/README.md
deleted file mode 100644
index 23864316..00000000
--- a/examples/image_telephone/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# Image Telephone
-
-This example demonstrates how to play telephone with DALL-E and ChatGPT.
-
-You provide an initial image to ChatGPT, which then generates a caption. The caption
-is saved to state. That caption is then provided to DALL-E, which generates an image, which is saved to state.
-You then provide that image to ChatGPT, and so on.
-
-Right now the teriminal state is set to 2, so the game will end after 2 iterations:
-
-![Telephone](telephone_graph.png)
-
-## Modifying the game
-There are two levels you can modify:
-
-1. The high-level orchestration and state management
-2. What each action actually does.
-
-For the high-level orchestration you can add more nodes, change conditions, etc.
-
-For the low-level actions, you can change the prompt, the template, etc. too. To do so see the
-documentation for the Hamilton dataflows that are used: [captioning](https://hub.dagworks.io/docs/Users/elijahbenizzy/caption_images/) and
-[generating image](https://hub.dagworks.io/docs/Users/elijahbenizzy/generate_images/). You can easily modify the prompt and
-template by overriding values, or by copying the code and modifying it yourself in 2 minutes - see instructions on the [hub](https://hub.dagworks.io/).
diff --git a/examples/image_telephone/application.py b/examples/image_telephone/application.py
deleted file mode 100644
index 599d2400..00000000
--- a/examples/image_telephone/application.py
+++ /dev/null
@@ -1,156 +0,0 @@
-from typing import Tuple
-
-from hamilton import dataflows, driver
-
-from burr.core import Action, ApplicationBuilder, State, default, expr
-from burr.core.action import action
-from burr.integrations import hamilton
-from burr.lifecycle import PostRunStepHook
-
-caption_images = dataflows.import_module("caption_images", "elijahbenizzy")
-generate_images = dataflows.import_module("generate_images", "elijahbenizzy")
-
-
-caption_image_driver = driver.Builder().with_config({}).with_modules(caption_images).build()
-
-generate_image_driver = driver.Builder().with_config({}).with_modules(generate_images).build()
-
-
-class PrintStepHook(PostRunStepHook):
- def post_run_step(self, *, state: "State", action: "Action", **future_kwargs):
- print("action=====\n", action)
- print("state======\n", state)
-
-
-# procedural way to do this
-@action(
- reads=["current_image_location"],
- writes=["current_image_caption", "image_location_history"],
-)
-def image_caption(state: State) -> Tuple[dict, State]:
- current_image = state["current_image_location"]
- result = caption_image_driver.execute(
- ["generated_caption"], inputs={"image_url": current_image}
- )
- updates = {
- "current_image_caption": result["generated_caption"],
- }
- return result, state.update(**updates).append(image_location_history=current_image)
-
-
-# procedural way to do this
-@action(
- reads=["current_image_caption"],
- writes=["current_image_location", "image_caption_history"],
-)
-def image_generation(state: State) -> Tuple[dict, State]:
- current_caption = state["current_image_caption"]
- result = generate_image_driver.execute(
- ["generated_image"], inputs={"image_generation_prompt": current_caption}
- )
- updates = {
- "current_image_location": result["generated_image"],
- }
- return result, state.update(**updates).append(image_caption_history=current_caption)
-
-
-@action(reads=[], writes=[])
-def terminal_step(state: State) -> Tuple[dict, State]:
- return {}, state
-
-
-def regular_action_main():
- """This shows how one might define functions to be nodes."""
- app = (
- ApplicationBuilder()
- .with_state(
- current_image_location="telephone_graph.png",
- current_image_caption="",
- image_location_history=[],
- image_caption_history=[],
- )
- .with_actions(
- caption=image_caption,
- image=image_generation,
- terminal=terminal_step,
- )
- .with_transitions(
- ("caption", "image", default),
- ("image", "terminal", expr("len(image_caption_history) == 2")),
- ("image", "caption", default),
- )
- .with_entrypoint("caption")
- .with_hooks(PrintStepHook())
- .with_tracker(project="image-telephone")
- .build()
- )
- return app
-
-
-def hamilton_action_main():
- """This shows how to use the Hamilton syntactic wrapper for the nodes."""
-
- _caption = hamilton.Hamilton(
- inputs={"image_url": hamilton.from_state("current_image_location")},
- outputs={
- "generated_caption": hamilton.update_state("current_image_caption"),
- "image_url": hamilton.append_state("image_location_history"),
- },
- driver=caption_image_driver,
- )
- _image = hamilton.Hamilton(
- inputs={"image_generation_prompt": hamilton.from_state("current_image_caption")},
- outputs={
- "generated_image": hamilton.update_state("current_image_location"),
- "image_generation_prompt": hamilton.append_state("image_caption_history"),
- },
- driver=generate_image_driver,
- )
- app = (
- ApplicationBuilder()
- .with_state(
- current_image_location="telephone_graph.png",
- current_image_caption="",
- image_location_history=[],
- image_caption_history=[],
- )
- .with_actions(
- caption=_caption,
- image=_image,
- terminal=terminal_step,
- )
- .with_transitions(
- ("caption", "image", default),
- ("image", "terminal", expr("len(image_caption_history) == 2")),
- ("image", "caption", default),
- )
- .with_entrypoint("caption")
- .with_hooks(PrintStepHook())
- .with_tracker(project="image-telephone")
- .build()
- )
- return app
-
-
-if __name__ == "__main__":
- import random
-
- coin_flip = random.choice([True, False])
- if coin_flip:
- app = hamilton_action_main()
- else:
- app = regular_action_main()
- app.visualize(
- output_file_path="telephone_graph", include_conditions=True, view=True, format="png"
- )
- if coin_flip:
- app.run(halt_after=["terminal"])
- else:
- # alternate way to run:
- while True:
- action, result, state = app.step()
- print("action=====\n", action)
- print("result=====\n", result)
- print("state======\n", state)
- if action.name == "terminal":
- break
diff --git a/examples/image_telephone/telephone_graph.png b/examples/image_telephone/telephone_graph.png
deleted file mode 100644
index eacaa87c..00000000
Binary files a/examples/image_telephone/telephone_graph.png and /dev/null differ
diff --git a/examples/corgi_adventure/README.md b/examples/llm-adventure-game/README.md
similarity index 100%
rename from examples/corgi_adventure/README.md
rename to examples/llm-adventure-game/README.md
diff --git a/examples/corgi_adventure/application.py b/examples/llm-adventure-game/application.py
similarity index 100%
rename from examples/corgi_adventure/application.py
rename to examples/llm-adventure-game/application.py
diff --git a/examples/corgi_adventure/digraph.png b/examples/llm-adventure-game/digraph.png
similarity index 100%
rename from examples/corgi_adventure/digraph.png
rename to examples/llm-adventure-game/digraph.png
diff --git a/examples/corgi_adventure/requirements.txt b/examples/llm-adventure-game/requirements.txt
similarity index 100%
rename from examples/corgi_adventure/requirements.txt
rename to examples/llm-adventure-game/requirements.txt
diff --git a/examples/ml_training/application.py b/examples/ml-training/application.py
similarity index 100%
rename from examples/ml_training/application.py
rename to examples/ml-training/application.py
diff --git a/examples/gpt/.DS_Store b/examples/multi-modal-chatbot/.DS_Store
similarity index 100%
rename from examples/gpt/.DS_Store
rename to examples/multi-modal-chatbot/.DS_Store
diff --git a/examples/multi-modal-chatbot/Digraph.gv b/examples/multi-modal-chatbot/Digraph.gv
new file mode 100644
index 00000000..71128c8b
--- /dev/null
+++ b/examples/multi-modal-chatbot/Digraph.gv
@@ -0,0 +1,28 @@
+digraph {
+ graph [compound=false concentrate=false rankdir=TB ranksep=0.4]
+ prompt [label=prompt shape=box style=rounded]
+ input__prompt [label="input: prompt" shape=oval style=dashed]
+ input__prompt -> prompt
+ check_openai_key [label=check_openai_key shape=box style=rounded]
+ check_safety [label=check_safety shape=box style=rounded]
+ decide_mode [label=decide_mode shape=box style=rounded]
+ generate_image [label=generate_image shape=box style=rounded]
+ generate_code [label=generate_code shape=box style=rounded]
+ answer_question [label=answer_question shape=box style=rounded]
+ prompt_for_more [label=prompt_for_more shape=box style=rounded]
+ response [label=response shape=box style=rounded]
+ prompt -> check_openai_key [style=solid]
+ check_openai_key -> check_safety [style=dashed]
+ check_openai_key -> response [style=solid]
+ check_safety -> decide_mode [style=dashed]
+ check_safety -> response [style=solid]
+ decide_mode -> generate_image [style=dashed]
+ decide_mode -> generate_code [style=dashed]
+ decide_mode -> answer_question [style=dashed]
+ decide_mode -> prompt_for_more [style=solid]
+ generate_image -> response [style=solid]
+ answer_question -> response [style=solid]
+ generate_code -> response [style=solid]
+ prompt_for_more -> response [style=solid]
+ response -> prompt [style=solid]
+}
diff --git a/examples/multi-modal-chatbot/Digraph.gv.pdf b/examples/multi-modal-chatbot/Digraph.gv.pdf
new file mode 100644
index 00000000..91eb4aba
Binary files /dev/null and b/examples/multi-modal-chatbot/Digraph.gv.pdf differ
diff --git a/examples/gpt/README.md b/examples/multi-modal-chatbot/README.md
similarity index 100%
rename from examples/gpt/README.md
rename to examples/multi-modal-chatbot/README.md
diff --git a/examples/gpt/application.py b/examples/multi-modal-chatbot/application.py
similarity index 100%
rename from examples/gpt/application.py
rename to examples/multi-modal-chatbot/application.py
diff --git a/examples/gpt/application_with_traces.py b/examples/multi-modal-chatbot/application_with_traces.py
similarity index 100%
rename from examples/gpt/application_with_traces.py
rename to examples/multi-modal-chatbot/application_with_traces.py
diff --git a/examples/gpt/dag.py b/examples/multi-modal-chatbot/dag.py
similarity index 100%
rename from examples/gpt/dag.py
rename to examples/multi-modal-chatbot/dag.py
diff --git a/examples/multi-modal-chatbot/digraph b/examples/multi-modal-chatbot/digraph
new file mode 100644
index 00000000..ea35f895
--- /dev/null
+++ b/examples/multi-modal-chatbot/digraph
@@ -0,0 +1,25 @@
+digraph {
+ graph [compound=false concentrate=false rankdir=TB ranksep=0.4]
+ prompt [label=prompt shape=box style=rounded]
+ input__prompt [label="input: prompt" shape=oval style=dashed]
+ input__prompt -> prompt
+ check_safety [label=check_safety shape=box style=rounded]
+ decide_mode [label=decide_mode shape=box style=rounded]
+ generate_image [label=generate_image shape=box style=rounded]
+ generate_code [label=generate_code shape=box style=rounded]
+ answer_question [label=answer_question shape=box style=rounded]
+ prompt_for_more [label=prompt_for_more shape=box style=rounded]
+ response [label=response shape=box style=rounded]
+ prompt -> check_safety [style=solid]
+ check_safety -> decide_mode [style=dashed]
+ check_safety -> response [style=solid]
+ decide_mode -> generate_image [style=dashed]
+ decide_mode -> generate_code [style=dashed]
+ decide_mode -> answer_question [style=dashed]
+ decide_mode -> prompt_for_more [style=solid]
+ generate_image -> response [style=solid]
+ answer_question -> response [style=solid]
+ generate_code -> response [style=solid]
+ prompt_for_more -> response [style=solid]
+ response -> prompt [style=solid]
+}
diff --git a/examples/gpt/digraph.png b/examples/multi-modal-chatbot/digraph.png
similarity index 100%
rename from examples/gpt/digraph.png
rename to examples/multi-modal-chatbot/digraph.png
diff --git a/examples/gpt/gpt.png b/examples/multi-modal-chatbot/gpt.png
similarity index 100%
rename from examples/gpt/gpt.png
rename to examples/multi-modal-chatbot/gpt.png
diff --git a/examples/gpt/requirements.txt b/examples/multi-modal-chatbot/requirements.txt
similarity index 100%
rename from examples/gpt/requirements.txt
rename to examples/multi-modal-chatbot/requirements.txt
diff --git a/examples/gpt/simple_streamlit_app.py b/examples/multi-modal-chatbot/simple_streamlit_app.py
similarity index 100%
rename from examples/gpt/simple_streamlit_app.py
rename to examples/multi-modal-chatbot/simple_streamlit_app.py
diff --git a/examples/gpt/streamlit_app.py b/examples/multi-modal-chatbot/streamlit_app.py
similarity index 100%
rename from examples/gpt/streamlit_app.py
rename to examples/multi-modal-chatbot/streamlit_app.py
diff --git a/examples/blog_post/README.md b/examples/simple-chatbot-intro/README.md
similarity index 100%
rename from examples/blog_post/README.md
rename to examples/simple-chatbot-intro/README.md
diff --git a/examples/blog_post/blog.ipynb b/examples/simple-chatbot-intro/blog.ipynb
similarity index 100%
rename from examples/blog_post/blog.ipynb
rename to examples/simple-chatbot-intro/blog.ipynb
diff --git a/examples/blog_post/digraph_initial.png b/examples/simple-chatbot-intro/digraph_initial.png
similarity index 100%
rename from examples/blog_post/digraph_initial.png
rename to examples/simple-chatbot-intro/digraph_initial.png
diff --git a/examples/blog_post/digraph_safe.png b/examples/simple-chatbot-intro/digraph_safe.png
similarity index 100%
rename from examples/blog_post/digraph_safe.png
rename to examples/simple-chatbot-intro/digraph_safe.png
diff --git a/examples/streaming_chatbot/README.md b/examples/streaming-overview/README.md
similarity index 100%
rename from examples/streaming_chatbot/README.md
rename to examples/streaming-overview/README.md
diff --git a/examples/streaming_chatbot/application.py b/examples/streaming-overview/application.py
similarity index 100%
rename from examples/streaming_chatbot/application.py
rename to examples/streaming-overview/application.py
diff --git a/examples/streaming_chatbot/streamlit_app.py b/examples/streaming-overview/streamlit_app.py
similarity index 100%
rename from examples/streaming_chatbot/streamlit_app.py
rename to examples/streaming-overview/streamlit_app.py
diff --git a/examples/validate_examples.py b/examples/validate_examples.py
index 0d76a5ac..a68db881 100644
--- a/examples/validate_examples.py
+++ b/examples/validate_examples.py
@@ -12,16 +12,16 @@ REQUIRED_FILES = [
"__init__.py", # included as we want them all to be importable
]
-
FILTERLIST = ["half-baked", "ml-training"]
+
def should_validate(directory: str) -> bool:
"""Return True if the given directory is an example directory."""
return (
- os.path.isdir(os.path.join(EXAMPLES_DIR, directory))
- and not directory.startswith(".")
- and not directory.startswith("_")
- and directory not in FILTERLIST
+ os.path.isdir(os.path.join(EXAMPLES_DIR, directory))
+ and not directory.startswith(".")
+ and not directory.startswith("_")
+ and directory not in FILTERLIST
)