-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console: ASCII control characters not correctly handled for chatlas responses in Python #5819
Comments
For reference, he's an explanation of the chars involved:
|
Here's a simpler repro using the very popular rich package (which is what chatlas uses): import rich.live as Live
import time
with Live.Live() as live:
for line in ["a", "a\nb", "a\nb\nc"]:
live.update(line)
time.sleep(0.5) With "Run Python File in Terminal" the result is correct:
but with "Run Python File in Console" the result is:
|
It looks to me like the console actually does know how to handle these characters to some degree. But they are only correctly handled within an
|
Aha, there's code that combines consecutive ActivityItemStreams. It's choosing to return additional items in this case, maybe that's what's wrong? |
Rewriting public addActivityItemStream(activityItemStream: this): this | undefined {
// If this ActivityItemStream is terminated, copy its styles to the ActivityItemStream being
// added and return it as the remainder ActivityItemStream to be processed.
if (this.terminated) {
activityItemStream.ansiOutput.copyStylesFrom(this.ansiOutput);
return activityItemStream;
}
this.activityItemStreams.push(activityItemStream);
return undefined;
} But #1635 intentionally moved away from this approach, breaking output into separate little activity item streams to make it easy to trim large amounts of uninterrupted console output. Not sure how to reconcile these two requirements. (Maybe scan for cursor movement ANSI codes and always combine in that case? Even that might not be enough though, you might emit (Maybe console trimming needs to be handled differently? Implementation here) @softwarenerd, any thoughts? |
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: