Skip to content

Commit

Permalink
Fix text representation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Apr 5, 2024
1 parent a0c7d16 commit 90ad374
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions js/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export type RawData = {
*
*
* The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
* as a string, and the result can contain multiple types of data. The text representation is always present, and
* the other representations are optional.
* as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
* for the actual result the representation is always present for the result, the other representations are always optional.
*/
export class Result {
/**
* Text representation of the result. Always present.
* Text representation of the result.
*/
readonly text: string
readonly text?: string
/**
* HTML representation of the data.
*/
Expand Down
29 changes: 14 additions & 15 deletions python/e2b_code_interpreter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ class Result:
The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
as a string, and the result can contain multiple types of data. The text representation is always present, and
the other representations are optional.
as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
for the actual result the representation is always present for the result, the other representations are always optional.
The class also provides methods to display the data in a Jupyter notebook.
"""

text: str
"Text representation of the result. Always present."
text: Optional[str] = None
html: Optional[str] = None
markdown: Optional[str] = None
svg: Optional[str] = None
Expand All @@ -68,7 +67,7 @@ def __init__(self, is_main_result: bool, data: [MIMEType, str]):
self.is_main_result = is_main_result
self.raw = copy.deepcopy(data)

self.text = data.pop("text/plain")
self.text = data.pop("text/plain", None)
self.html = data.pop("text/html", None)
self.markdown = data.pop("text/markdown", None)
self.svg = data.pop("image/svg+xml", None)
Expand Down Expand Up @@ -111,79 +110,79 @@ def formats(self) -> Iterable[str]:

return formats

def __str__(self) -> str:
def __str__(self) -> Optional[str]:
"""
Returns the text representation of the data.
:return: The text representation of the data.
"""
return self.text

def _repr_html_(self) -> str:
def _repr_html_(self) -> Optional[str]:
"""
Returns the HTML representation of the data.
:return: The HTML representation of the data.
"""
return self.html

def _repr_markdown_(self) -> str:
def _repr_markdown_(self) -> Optional[str]:
"""
Returns the Markdown representation of the data.
:return: The Markdown representation of the data.
"""
return self.markdown

def _repr_svg_(self) -> str:
def _repr_svg_(self) -> Optional[str]:
"""
Returns the SVG representation of the data.
:return: The SVG representation of the data.
"""
return self.svg

def _repr_png_(self) -> str:
def _repr_png_(self) -> Optional[str]:
"""
Returns the base64 representation of the PNG data.
:return: The base64 representation of the PNG data.
"""
return self.png

def _repr_jpeg_(self) -> str:
def _repr_jpeg_(self) -> Optional[str]:
"""
Returns the base64 representation of the JPEG data.
:return: The base64 representation of the JPEG data.
"""
return self.jpeg

def _repr_pdf_(self) -> str:
def _repr_pdf_(self) -> Optional[str]:
"""
Returns the PDF representation of the data.
:return: The PDF representation of the data.
"""
return self.pdf

def _repr_latex_(self) -> str:
def _repr_latex_(self) -> Optional[str]:
"""
Returns the LaTeX representation of the data.
:return: The LaTeX representation of the data.
"""
return self.latex

def _repr_json_(self) -> dict:
def _repr_json_(self) -> Optional[dict]:
"""
Returns the JSON representation of the data.
:return: The JSON representation of the data.
"""
return self.json

def _repr_javascript_(self) -> str:
def _repr_javascript_(self) -> Optional[str]:
"""
Returns the JavaScript representation of the data.
Expand Down

0 comments on commit 90ad374

Please sign in to comment.