Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Updates LLM adventure game to be compliant
elijahbenizzy1815c23f46ee
diff --git a/examples/llm-adventure-game/__init__.py b/examples/llm-adventure-game/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/examples/llm-adventure-game/application.py b/examples/llm-adventure-game/application.pyindex 4a9f7fd7..5a5b96e6 100644--- a/examples/llm-adventure-game/application.py+++ b/examples/llm-adventure-game/application.py@@ -1,12 +1,11 @@import json-from typing import List, Optional, Tuple+from typing import Optional, Tuplefrom openai import Clientimport burr.corefrom burr.core import Application, State, default, whenfrom burr.core.action import action-from burr.lifecycle import LifecycleAdapterRESTRICTIONS = """You're a small corgi with short legs. You can't jump high,you can't run fast, you can't perform feats of athleticism in general@@ -107,7 +106,6 @@ def win(state: State) -> Tuple[dict, State]:def application(app_id: Optional[str] = None,storage_dir: Optional[str] = "~/.burr",- hooks: Optional[List[LifecycleAdapter]] = None,) -> Application:return (burr.core.ApplicationBuilder()diff --git a/examples/llm-adventure-game/notebook.ipynb b/examples/llm-adventure-game/notebook.ipynbnew file mode 100644index 00000000..9618de44--- /dev/null+++ b/examples/llm-adventure-game/notebook.ipynb@@ -0,0 +1,183 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "id": "00d77a51-a6ec-40d6-ae20-01f5ab2e6981",+ "metadata": {},+ "source": [+ "# LLM-based adventure game\n",+ "\n",+ "This is a simple example of an LLM-based adventure game. You can see the code in [application.py](application.py)."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 1,+ "id": "d6c1f3b5-620c-46f6-bf11-dac98b80ce10",+ "metadata": {},+ "outputs": [],+ "source": [+ "from application import application as llm_adventure_game_app"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "id": "a4320dc7-2232-4d78-b197-b18c2d51b002",+ "metadata": {},+ "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 8.1.0 (20230707.0739)\n",+ " -->\n",+ "<!-- Pages: 1 -->\n",+ "<svg width=\"182pt\" height=\"328pt\"\n",+ " viewBox=\"0.00 0.00 181.50 327.50\" 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 323.5)\">\n",+ "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-323.5 177.5,-323.5 177.5,4 -4,4\"/>\n",+ "<!-- start -->\n",+ "<g id=\"node1\" class=\"node\">\n",+ "<title>start</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M110.5,-319.5C110.5,-319.5 80.5,-319.5 80.5,-319.5 74.5,-319.5 68.5,-313.5 68.5,-307.5 68.5,-307.5 68.5,-295.5 68.5,-295.5 68.5,-289.5 74.5,-283.5 80.5,-283.5 80.5,-283.5 110.5,-283.5 110.5,-283.5 116.5,-283.5 122.5,-289.5 122.5,-295.5 122.5,-295.5 122.5,-307.5 122.5,-307.5 122.5,-313.5 116.5,-319.5 110.5,-319.5\"/>\n",+ "<text text-anchor=\"middle\" x=\"95.5\" y=\"-296.45\" font-family=\"Times,serif\" font-size=\"14.00\">start</text>\n",+ "</g>\n",+ "<!-- prompt_for_challenge -->\n",+ "<g id=\"node2\" class=\"node\">\n",+ "<title>prompt_for_challenge</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M151.88,-252.5C151.88,-252.5 39.12,-252.5 39.12,-252.5 33.12,-252.5 27.12,-246.5 27.12,-240.5 27.12,-240.5 27.12,-228.5 27.12,-228.5 27.12,-222.5 33.12,-216.5 39.12,-216.5 39.12,-216.5 151.88,-216.5 151.88,-216.5 157.88,-216.5 163.88,-222.5 163.88,-228.5 163.88,-228.5 163.88,-240.5 163.88,-240.5 163.88,-246.5 157.88,-252.5 151.88,-252.5\"/>\n",+ "<text text-anchor=\"middle\" x=\"95.5\" y=\"-229.45\" font-family=\"Times,serif\" font-size=\"14.00\">prompt_for_challenge</text>\n",+ "</g>\n",+ "<!-- start->prompt_for_challenge -->\n",+ "<g id=\"edge1\" class=\"edge\">\n",+ "<title>start->prompt_for_challenge</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M95.5,-283.08C95.5,-277.11 95.5,-270.26 95.5,-263.65\"/>\n",+ "<polygon fill=\"black\" stroke=\"black\" points=\"99,-263.97 95.5,-253.97 92,-263.97 99,-263.97\"/>\n",+ "</g>\n",+ "<!-- evaluate_attempt -->\n",+ "<g id=\"node3\" class=\"node\">\n",+ "<title>evaluate_attempt</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M97,-185.5C97,-185.5 12,-185.5 12,-185.5 6,-185.5 0,-179.5 0,-173.5 0,-173.5 0,-161.5 0,-161.5 0,-155.5 6,-149.5 12,-149.5 12,-149.5 97,-149.5 97,-149.5 103,-149.5 109,-155.5 109,-161.5 109,-161.5 109,-173.5 109,-173.5 109,-179.5 103,-185.5 97,-185.5\"/>\n",+ "<text text-anchor=\"middle\" x=\"54.5\" y=\"-162.45\" font-family=\"Times,serif\" font-size=\"14.00\">evaluate_attempt</text>\n",+ "</g>\n",+ "<!-- prompt_for_challenge->evaluate_attempt -->\n",+ "<g id=\"edge2\" class=\"edge\">\n",+ "<title>prompt_for_challenge->evaluate_attempt</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M84.51,-216.08C80.47,-209.67 75.79,-202.25 71.35,-195.21\"/>\n",+ "<polygon fill=\"black\" stroke=\"black\" points=\"73.81,-193.56 65.52,-186.97 67.89,-197.29 73.81,-193.56\"/>\n",+ "</g>\n",+ "<!-- maybe_progress -->\n",+ "<g id=\"node4\" class=\"node\">\n",+ "<title>maybe_progress</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M136.12,-118.5C136.12,-118.5 54.88,-118.5 54.88,-118.5 48.88,-118.5 42.88,-112.5 42.88,-106.5 42.88,-106.5 42.88,-94.5 42.88,-94.5 42.88,-88.5 48.88,-82.5 54.88,-82.5 54.88,-82.5 136.12,-82.5 136.12,-82.5 142.12,-82.5 148.12,-88.5 148.12,-94.5 148.12,-94.5 148.12,-106.5 148.12,-106.5 148.12,-112.5 142.12,-118.5 136.12,-118.5\"/>\n",+ "<text text-anchor=\"middle\" x=\"95.5\" y=\"-95.45\" font-family=\"Times,serif\" font-size=\"14.00\">maybe_progress</text>\n",+ "</g>\n",+ "<!-- evaluate_attempt->maybe_progress -->\n",+ "<g id=\"edge3\" class=\"edge\">\n",+ "<title>evaluate_attempt->maybe_progress</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M65.49,-149.08C69.53,-142.67 74.21,-135.25 78.65,-128.21\"/>\n",+ "<polygon fill=\"black\" stroke=\"black\" points=\"82.11,-130.29 84.48,-119.97 76.19,-126.56 82.11,-130.29\"/>\n",+ "</g>\n",+ "<!-- maybe_progress->prompt_for_challenge -->\n",+ "<g id=\"edge5\" class=\"edge\">\n",+ "<title>maybe_progress->prompt_for_challenge</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M105.54,-118.65C110.17,-127.53 115.15,-138.75 117.5,-149.5 120.91,-165.13 120.91,-169.87 117.5,-185.5 115.96,-192.55 113.29,-199.81 110.32,-206.48\"/>\n",+ "<polygon fill=\"black\" stroke=\"black\" points=\"106.75,-204.83 105.54,-215.35 113.05,-207.87 106.75,-204.83\"/>\n",+ "</g>\n",+ "<!-- win -->\n",+ "<g id=\"node5\" class=\"node\">\n",+ "<title>win</title>\n",+ "<path fill=\"none\" stroke=\"black\" d=\"M110.5,-36C110.5,-36 80.5,-36 80.5,-36 74.5,-36 68.5,-30 68.5,-24 68.5,-24 68.5,-12 68.5,-12 68.5,-6 74.5,0 80.5,0 80.5,0 110.5,0 110.5,0 116.5,0 122.5,-6 122.5,-12 122.5,-12 122.5,-24 122.5,-24 122.5,-30 116.5,-36 110.5,-36\"/>\n",+ "<text text-anchor=\"middle\" x=\"95.5\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">win</text>\n",+ "</g>\n",+ "<!-- maybe_progress->win -->\n",+ "<g id=\"edge4\" class=\"edge\">\n",+ "<title>maybe_progress->win</title>\n",+ "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M95.5,-82.03C95.5,-71.91 95.5,-58.91 95.5,-47.35\"/>\n",+ "<polygon fill=\"black\" stroke=\"black\" points=\"99,-47.43 95.5,-37.43 92,-47.43 99,-47.43\"/>\n",+ "<text text-anchor=\"middle\" x=\"134.5\" y=\"-54.2\" font-family=\"Times,serif\" font-size=\"14.00\">did_win=True</text>\n",+ "</g>\n",+ "</g>\n",+ "</svg>\n"+ ],+ "text/plain": [+ "<graphviz.graphs.Digraph at 0x107fdcb50>"+ ]+ },+ "execution_count": 2,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "app = llm_adventure_game_app()\n",+ "app.visualize(include_conditions=True)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "id": "7a0081cb-1574-44ad-8b0e-8ecbe062eefc",+ "metadata": {},+ "outputs": [+ {+ "name": "stdin",+ "output_type": "stream",+ "text": [+ "There is a dish of dog food on the floor. You want to eat it. What do you do?\n",+ " $ I eat it\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "What happened: You waddle over to the dish and eagerly start feasting on the kibble. It's delicious!\n"+ ]+ },+ {+ "name": "stdin",+ "output_type": "stream",+ "text": [+ "There is a dish of dog food on a table. You want to eat it. What do you do?\n",+ " $ I jump on the table\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "What happened: You tried to jump on the table in order to get the dog food, but your short corgi legs don't allow you to jump high enough. You're not able to reach the food.\n"+ ]+ }+ ],+ "source": [+ "app.run(halt_after=['win'])"+ ]+ }+ ],+ "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.11.6"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 5+}diff --git a/examples/llm-adventure-game/digraph.png b/examples/llm-adventure-game/statemachine.pngsimilarity index 100%rename from examples/llm-adventure-game/digraph.pngrename to examples/llm-adventure-game/statemachine.png