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.

Add DeepSeek chatbot example (#3598)

Srihari Thyagarajan6f914a6c76af
diff --git a/examples/ai/chat/deepseek_example.py b/examples/ai/chat/deepseek_example.py
new file mode 100644
index 0000000000..022b0cfebb
--- /dev/null
+++ b/examples/ai/chat/deepseek_example.py
@@ -0,0 +1,103 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "marimo",
+# "openai==1.60.2",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.10.17"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md(
+ r"""
+ # Using DeepSeek
+
+ This example shows how to use [`mo.ui.chat`](https://docs.marimo.io/api/inputs/chat/?h=mo.ui.chat) to make a chatbot backed by [Deepseek](https://deepseek.com/).
+ """
+ )
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md(
+ r"""
+ <a href="https://api-docs.deepseek.com/" target="_blank" rel="noopener noreferrer">
+ <img
+ src="https://chat.deepseek.com/deepseek-chat.jpeg"
+ alt="Powered by deepseek"
+ width="450"
+ />
+ </a>
+ """
+ ).center()
+ return
+
+
+def _(mo):
+ import os
+
+ os_key = os.environ.get("DEEPSEEK_API_KEY")
+ input_key = mo.ui.text(label="Deepseek API key", kind="password")
+ input_key if not os_key else None
+ return input_key, os, os_key
+
+
+def _(input_key, mo, os_key):
+ key = os_key or input_key.value
+
+ mo.stop(
+ not key,
+ mo.md("Please provide your Deepseek AI API key in the input field."),
+ )
+ return (key,)
+
+
+def _(key, mo):
+ chatbot = mo.ui.chat(
+ mo.ai.llm.openai(
+ model="deepseek-reasoner",
+ system_message="You are a helpful assistant.",
+ api_key=key,
+ base_url="https://api.deepseek.com",
+ ),
+ prompts=[
+ "Hello",
+ "How are you?",
+ "I'm doing great, how about you?",
+ ],
+ )
+ chatbot
+ return (chatbot,)
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""Access the chatbot's historical messages with [`chatbot.value`](https://docs.marimo.io/api/inputs/chat.html#accessing-chat-history).""")
+ return
+
+
+def _(chatbot):
+ # chatbot.value is the list of chat messages
+ chatbot.value
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/examples/ai/chat/groq_example.py b/examples/ai/chat/groq_example.py
index d5cc7be89f..6b527a5527 100644
--- a/examples/ai/chat/groq_example.py
+++ b/examples/ai/chat/groq_example.py
@@ -3,7 +3,6 @@
# dependencies = [
# "marimo",
# "groq==0.11.0",
-# "anthropic==0.37.1",
# ]
# ///