Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

example: add recipe bot (#2768)

Myles Scolnicke8bc70c5a70f
diff --git a/examples/ai/chat/README.md b/examples/ai/chat/README.md
index d0771f363a..fe28e9889d 100644
--- a/examples/ai/chat/README.md
+++ b/examples/ai/chat/README.md
@@ -2,13 +2,15 @@
These examples show how to make chatbots with marimo, using [`mo.ui.chat`](https://docs.marimo.io/api/inputs/chat.html#marimo.ui.chat).
-- `custom.py` shows how to make a custom chatbot
-- `openai_example.py` shows how to make a chatbot powered by OpenAI models
-- `anthropic_example.py` shows how to make a chatbot powered by Anthropic models
-- `gemini.py` shows how to make a chatbot powered by Google models like Gemini
+- `custom.py` shows how to make a custom chatbot.
+- `openai_example.py` shows how to make a chatbot powered by OpenAI models.
+- `anthropic_example.py` shows how to make a chatbot powered by Anthropic models.
+- `gemini.py` shows how to make a chatbot powered by Google models like Gemini.
- `mlx_chat.py` shows a simple chatbot using local on-device models with Apple's [MLX](https://github.com/ml-explore/mlx), a machine learning framework from Apple that is similar to JAX and PyTorch. This specific example uses the [mlx-lm](https://github.com/ml-explore/mlx-examples/tree/main/llms) library. Note that Apple Silicon chips are required for using MLX.
-- `llm_datasette.py` shows how to make a chatbot powered by Simon W's LLM library
+- `llm_datasette.py` shows how to make a chatbot powered by Simon W's LLM library.
- `dagger_code_interpreter.py` shows how to make a basic code-interpreter chatbot powered by Dagger containers.
+- `recipe_bot.py` shows how to make a chatbot that can parse recipes from images.
+- `simplemind_example.py` shows how to integrate [simplemind](https://github.com/kennethreitz/simplemind).
Chatbot's in marimo are _reactive_: when the chatbot responds with a message,
all other cells referencing the chatbot are automatically run or marked
diff --git a/examples/ai/chat/recipe_bot.py b/examples/ai/chat/recipe_bot.py
new file mode 100644
index 0000000000..7eddb453b2
--- /dev/null
+++ b/examples/ai/chat/recipe_bot.py
@@ -0,0 +1,39 @@
+import marimo
+
+__generated_with = "0.9.10"
+app = marimo.App(width="medium")
+
+
+def __():
+ import marimo as mo
+
+ chat = mo.ui.chat(
+ mo.ai.llm.openai(
+ "gpt-4o",
+ system_message="""You are a helpful assistant that can
+ parse my recipe and summarize them for me.
+ Give me a title in the first line.""",
+ ),
+ allow_attachments=["image/png", "image/jpeg"],
+ prompts=["What is the recipe?"],
+ )
+ chat
+ return chat, mo
+
+
+def __(chat, mo):
+ mo.stop(not chat.value)
+
+ last_message: str = chat.value[-1].content
+ title = last_message.split("\n")[0]
+ summary = "\n".join(last_message.split("\n")[1:])
+ with open(f"{title}.md", "w") as f:
+ f.write(summary)
+ mo.status.toast("Receipt summary saved!", description=title)
+ return f, last_message, summary, title
+
+
+if __name__ == "__main__":
+ app.run()