Skip to content

Commit 71a55c7

Browse files
cpsievertCopilot
andauthored
Improve streaming output experience in Positron notebook (#131)
* Improve streaming output experience in Positron notebook * Update chatlas/_chat.py Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent c0cc2b4 commit 71a55c7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

chatlas/_chat.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,10 +2170,10 @@ def _markdown_display(self, echo: EchoOptions) -> ChatMarkdownDisplay:
21702170
return ChatMarkdownDisplay(MockMarkdownDisplay(), self)
21712171

21722172
# rich does a lot to detect a notebook environment, but it doesn't
2173-
# detect Quarto (at least not yet).
2173+
# detect Quarto, or a Positron notebook
21742174
from rich.console import Console
21752175

2176-
is_web = Console().is_jupyter or os.getenv("QUARTO_PYTHON", None) is not None
2176+
is_web = Console().is_jupyter or is_quarto() or is_positron_notebook()
21772177

21782178
opts = self._echo_options
21792179

@@ -2421,3 +2421,17 @@ class ToolFailureWarning(RuntimeWarning):
24212421

24222422
# By default warnings are shown once; we want to always show them.
24232423
warnings.simplefilter("always", ToolFailureWarning)
2424+
2425+
2426+
def is_quarto():
2427+
return os.getenv("QUARTO_PYTHON", None) is not None
2428+
2429+
2430+
def is_positron_notebook():
2431+
try:
2432+
get_ipython # type: ignore[name-defined]
2433+
except NameError:
2434+
return False
2435+
ipython = get_ipython() # type: ignore[name-defined]
2436+
session_mode = getattr(ipython, "session_mode", None)
2437+
return session_mode == "notebook"

0 commit comments

Comments
 (0)