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.

fix: Fix dep check for nested packages (#2492)

Myles Scolnick1e8e2b04fb91
diff --git a/docs/api/inputs/chat.md b/docs/api/inputs/chat.md
index 746e30347c..203019d8c6 100644
--- a/docs/api/inputs/chat.md
+++ b/docs/api/inputs/chat.md
@@ -145,7 +145,7 @@ import marimo as mo
mo.ui.chat(
mo.ai.llm.anthropic(
- "claude-3-5-sonnet-20240602",
+ "claude-3-5-sonnet-20240620",
system_message="You are a helpful assistant.",
api_key="sk-ant-...",
),
@@ -179,7 +179,7 @@ mo.ui.chat(
Chatbots can be implemented with a function that receives a list of
[`ChatMessage`](#marimo.ai.ChatMessage) objects and a
-[`ChatModelConfig`](#marimo.ai.ChatModelConfig).
+[`ChatModelConfig`](#marimo.ai.ChatModelConfig).
```{eval-rst}
.. autoclass:: marimo.ai.ChatMessage
diff --git a/examples/ai/chat/README.md b/examples/ai/chat/README.md
index 518f3706f9..a40afe28fe 100644
--- a/examples/ai/chat/README.md
+++ b/examples/ai/chat/README.md
@@ -3,9 +3,9 @@
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.py` shows how to make a chatbot powered by OpenAI models
-- `anthropic.py` shows how to make a chatbot powered by Anthropic models
-- `google.py` shows how to make a chatbot powered by Google models like Gemini
+- `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
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/anthropic.py b/examples/ai/chat/anthropic_example.py
similarity index 95%
rename from examples/ai/chat/anthropic.py
rename to examples/ai/chat/anthropic_example.py
index 8d73258bc3..3e9f056295 100644
--- a/examples/ai/chat/anthropic.py
+++ b/examples/ai/chat/anthropic_example.py
@@ -7,7 +7,7 @@
import marimo
-__generated_with = "0.8.22"
+__generated_with = "0.9.0"
app = marimo.App(width="medium")
@@ -54,7 +54,7 @@ def __(input_key, mo, os_key):
def __(key, mo):
chatbot = mo.ui.chat(
mo.ai.llm.anthropic(
- "claude-3-5-sonnet-20240602",
+ "claude-3-5-sonnet-20240620",
system_message="You are a helpful assistant.",
api_key=key,
),
diff --git a/examples/ai/chat/openai.py b/examples/ai/chat/openai_example.py
similarity index 100%
rename from examples/ai/chat/openai.py
rename to examples/ai/chat/openai_example.py
diff --git a/marimo/_dependencies/dependencies.py b/marimo/_dependencies/dependencies.py
index 982ca09015..9102939caf 100644
--- a/marimo/_dependencies/dependencies.py
+++ b/marimo/_dependencies/dependencies.py
@@ -18,9 +18,13 @@ class Dependency:
def has(self) -> bool:
"""Return True if the dependency is installed."""
- for pkg in self.pkg.split("."):
- if importlib.util.find_spec(pkg) is None:
+ try:
+ has_dep = importlib.util.find_spec(self.pkg) is not None
+ if not has_dep:
return False
+ except ModuleNotFoundError:
+ # Could happen for nested imports (e.g. foo.bar)
+ return False
if self.min_version or self.max_version:
self.warn_if_mismatch_version(self.min_version, self.max_version)
@@ -51,8 +55,7 @@ class Dependency:
"""
if not self.has():
raise ModuleNotFoundError(
- f"{self.pkg} is required {why}. "
- + f"You can install it with 'pip install {self.pkg}'."
+ f"{self.pkg} is required {why}."
) from None
def require_at_version(