You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our Console handling of line clearing ASCII control sequences is not quite right, leaving superfluous newlines / whitespace.
Steps to reproduce the issue:
Note: this scenario relies on an OpenAPI key to reproduce live, though with some logging information below you may not need to run this to devise a fix. Setup an env var for OPENAI_API_KEY. Ensure the key is permissioned for the model selected.
Run this Python in Positron's Console. It uses the chatlas package to chat with OpenAPI:
from chatlas import ChatOpenAI
import os
# Setup your Open API key in an env var
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def chat_with_chatlas(prompt: str):
chatlas_client = ChatOpenAI(api_key=OPENAI_API_KEY, model="gpt-4o-mini")
try:
response = chatlas_client.chat(prompt)
return response
except Exception as e:
return f"An error occurred: {e}"
prompt = "What is the capital of France?"
response = chat_with_chatlas(prompt)
Note the extra whitespace in the output in the console:
>>> %run "chatlastest.py"
The capital of France is Paris.
>>>
Expected or desired behavior:
Here's what the same program run in an ipython Terminal looks like:
In [1]: %run chatlastest.py
The capital of France is Paris.
In [2]:
Were there any error messages in the UI, Output panel, or Developer Tools console?
The chatlas package responds with partially complete lines as tokens are streamed from Open AI, replacing the output content using ASCII control chars. Here's the rough jupyter output message sequence, including escaped ASCII control chars in the JSON representation of messages:
2024-12-18 17:07:13.692 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\u001b[?25l"}
2024-12-18 17:07:14.167 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\nThe "}
2024-12-18 17:07:14.170 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital "}
2024-12-18 17:07:14.181 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of "}
2024-12-18 17:07:14.183 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of France "}
2024-12-18 17:07:14.215 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of France is "}
2024-12-18 17:07:14.217 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of France is Paris "}
2024-12-18 17:07:14.223 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of France is Paris. "}
2024-12-18 17:07:14.225 [debug] <<< RECV stream [iopub]: {"name":"stdout","text":"\r\u001b[2K\u001b[1A\u001b[2K\nThe capital of France is Paris. \n\u001b[?25h"}
The text was updated successfully, but these errors were encountered:
petetronic
changed the title
Console: ASCII control escape characters not correctly handled for chat turns using chatlas in Python
Console: ASCII control characters not correctly handled for chat turns using chatlas in Python
Dec 18, 2024
petetronic
changed the title
Console: ASCII control characters not correctly handled for chat turns using chatlas in Python
Console: ASCII control characters not correctly handled for chatlas responses in Python
Dec 18, 2024
System details:
Positron and OS details:
Positron Version: 2025.01.0 (Universal) build 39
Code - OSS Version: 1.93.0
Commit: c7ef34f
Interpreter details:
Python 3.11.7
Describe the issue:
Our Console handling of line clearing ASCII control sequences is not quite right, leaving superfluous newlines / whitespace.
Steps to reproduce the issue:
Note: this scenario relies on an OpenAPI key to reproduce live, though with some logging information below you may not need to run this to devise a fix. Setup an env var for OPENAI_API_KEY. Ensure the key is permissioned for the model selected.
Run this Python in Positron's Console. It uses the
chatlas
package to chat with OpenAPI:Expected or desired behavior:
Here's what the same program run in an
ipython
Terminal looks like:Were there any error messages in the UI, Output panel, or Developer Tools console?
The
chatlas
package responds with partially complete lines as tokens are streamed from Open AI, replacing the output content using ASCII control chars. Here's the rough jupyter output message sequence, including escaped ASCII control chars in the JSON representation of messages:The text was updated successfully, but these errors were encountered: