codebind 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codebind-0.1.1 → codebind-0.1.2}/PKG-INFO +1 -1
- {codebind-0.1.1 → codebind-0.1.2}/pyproject.toml +1 -1
- {codebind-0.1.1 → codebind-0.1.2}/pyproject.toml.orig +1 -1
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/execution.py +4 -0
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/prompts.py +10 -0
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/rendering.py +6 -3
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/session.py +2 -5
- {codebind-0.1.1 → codebind-0.1.2}/LICENSE +0 -0
- {codebind-0.1.1 → codebind-0.1.2}/README.md +0 -0
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/__init__.py +0 -0
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/cli.py +0 -0
- {codebind-0.1.1 → codebind-0.1.2}/src/codebind/py.typed +0 -0
|
@@ -39,14 +39,18 @@ class IPythonExecutor:
|
|
|
39
39
|
raise ValueError("cell must be a non-empty string")
|
|
40
40
|
|
|
41
41
|
original_prompts = getattr(self.shell, "prompts", None)
|
|
42
|
+
displayhook = self.shell.displayhook
|
|
43
|
+
original_output_prompt = displayhook.write_output_prompt
|
|
42
44
|
if prompts is not None and original_prompts is not None:
|
|
43
45
|
self.shell.prompts = prompts
|
|
46
|
+
displayhook.write_output_prompt = lambda: None
|
|
44
47
|
try:
|
|
45
48
|
with capture_output() as captured:
|
|
46
49
|
result = self.shell.run_cell(cell, store_history=False)
|
|
47
50
|
finally:
|
|
48
51
|
if prompts is not None and original_prompts is not None:
|
|
49
52
|
self.shell.prompts = original_prompts
|
|
53
|
+
displayhook.write_output_prompt = original_output_prompt
|
|
50
54
|
|
|
51
55
|
displays: list[str] = []
|
|
52
56
|
for output in captured.outputs:
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import sys
|
|
6
|
+
|
|
5
7
|
from IPython.terminal.prompts import Prompts
|
|
6
8
|
from IPython.terminal.ptutils import IPythonPTLexer
|
|
7
9
|
from prompt_toolkit.document import Document
|
|
@@ -44,6 +46,7 @@ def render_cell(shell: object, cell: str, prompts: CellPrompts) -> None:
|
|
|
44
46
|
lexer = IPythonPTLexer().lex_document(Document(cell))
|
|
45
47
|
pt_app = getattr(shell, "pt_app", None)
|
|
46
48
|
style = pt_app.app.style if pt_app is not None else None
|
|
49
|
+
sys.stdout.write(getattr(shell, "separate_in", "\n"))
|
|
47
50
|
|
|
48
51
|
for index, _line in enumerate(cell.split("\n")):
|
|
49
52
|
prompt_tokens = (
|
|
@@ -53,3 +56,10 @@ def render_cell(shell: object, cell: str, prompts: CellPrompts) -> None:
|
|
|
53
56
|
)
|
|
54
57
|
print_formatted_text(PygmentsTokens(prompt_tokens), style=style, end="")
|
|
55
58
|
print_formatted_text(FormattedText(lexer(index)), style=style)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def render_output_prompt(shell: object, prompts: CellPrompts) -> None:
|
|
62
|
+
"""Render an output prompt with IPython's terminal style."""
|
|
63
|
+
pt_app = getattr(shell, "pt_app", None)
|
|
64
|
+
style = pt_app.app.style if pt_app is not None else None
|
|
65
|
+
print_formatted_text(PygmentsTokens(prompts.out_prompt_tokens()), style=style, end="")
|
|
@@ -10,9 +10,10 @@ from rich.segment import Segments
|
|
|
10
10
|
from rich.text import Text
|
|
11
11
|
|
|
12
12
|
from .execution import ExecutionReport
|
|
13
|
+
from .prompts import CellPrompts, render_output_prompt
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
_MAXIMUM_OUTPUT_LINES = 10
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def _visible_output(report: ExecutionReport) -> str:
|
|
@@ -32,7 +33,7 @@ class TerminalRenderer:
|
|
|
32
33
|
def __init__(self) -> None:
|
|
33
34
|
self.console = Console()
|
|
34
35
|
|
|
35
|
-
def tool_output(self, report: ExecutionReport) -> None:
|
|
36
|
+
def tool_output(self, report: ExecutionReport, shell: object, prompts: CellPrompts) -> None:
|
|
36
37
|
"""Show a bounded preview while leaving the report itself intact for the model."""
|
|
37
38
|
visible = _visible_output(report)
|
|
38
39
|
if not visible:
|
|
@@ -40,7 +41,9 @@ class TerminalRenderer:
|
|
|
40
41
|
output = Text.from_ansi(visible)
|
|
41
42
|
options = self.console.options
|
|
42
43
|
complete = self.console.render_lines(output, options, pad=False, new_lines=True)
|
|
43
|
-
preview = complete[:
|
|
44
|
+
preview = complete[:_MAXIMUM_OUTPUT_LINES]
|
|
45
|
+
if report.ok:
|
|
46
|
+
render_output_prompt(shell, prompts)
|
|
44
47
|
self.console.print(Segments(chain.from_iterable(preview)), end="")
|
|
45
48
|
if len(complete) > len(preview):
|
|
46
49
|
self.console.print(
|
|
@@ -77,7 +77,6 @@ class Session:
|
|
|
77
77
|
self.instructions = instructions.strip() if instructions else None
|
|
78
78
|
self.messages: list[BaseMessage] = []
|
|
79
79
|
self.last_response: AIMessage | None = None
|
|
80
|
-
self.cell_number = 0
|
|
81
80
|
if self.instructions:
|
|
82
81
|
self.messages.append(SystemMessage(self.instructions))
|
|
83
82
|
|
|
@@ -85,7 +84,6 @@ class Session:
|
|
|
85
84
|
"""Clear conversation history without clearing the shared Python namespace."""
|
|
86
85
|
self.messages.clear()
|
|
87
86
|
self.last_response = None
|
|
88
|
-
self.cell_number = 0
|
|
89
87
|
if self.instructions:
|
|
90
88
|
self.messages.append(SystemMessage(self.instructions))
|
|
91
89
|
|
|
@@ -136,12 +134,11 @@ class Session:
|
|
|
136
134
|
return _tool_error("InvalidArguments", "ipython requires a string cell argument")
|
|
137
135
|
|
|
138
136
|
cell = arguments["cell"]
|
|
139
|
-
self.
|
|
140
|
-
prompts = CellPrompts(self.shell, self.cell_number)
|
|
137
|
+
prompts = CellPrompts(self.shell, self.shell.execution_count - 1)
|
|
141
138
|
render_cell(self.shell, cell, prompts)
|
|
142
139
|
try:
|
|
143
140
|
report = self.executor.execute(cell, prompts=prompts)
|
|
144
141
|
except Exception as error: # The failure must be returned to the model, not end the session.
|
|
145
142
|
report = _tool_error(type(error).__name__, str(error))
|
|
146
|
-
self.renderer.tool_output(report)
|
|
143
|
+
self.renderer.tool_output(report, self.shell, prompts)
|
|
147
144
|
return report
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|