Skip to content

Commit

Permalink
fix: address an issue where rendered result is not displayed when ipy… (
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshpokar authored Oct 8, 2024
1 parent c6ee419 commit ccb1ae4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions maidr/core/maidr.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def show(self, renderer: Literal["auto", "ipython", "browser"] = "auto") -> obje
The renderer to use for the HTML preview.
"""
html = self._create_html_tag()
if Environment.is_interactive_shell() and not Environment.is_notebook():
return html.show("browser")
return html.show(renderer)

def clear(self):
Expand Down
10 changes: 10 additions & 0 deletions maidr/util/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def is_interactive_shell() -> bool:
except ImportError:
return False

@staticmethod
def is_notebook() -> bool:
"""Return True if the environment is a Jupyter notebook."""
try:
from IPython import get_ipython # type: ignore

return get_ipython() is not None and "ipykernel" in str(get_ipython())
except ImportError:
return False

@staticmethod
def initialize_llm_secrets(unique_id: str) -> str:
"""Inject the LLM API keys into the MAIDR instance."""
Expand Down

0 comments on commit ccb1ae4

Please sign in to comment.