Skip to content

Commit

Permalink
output_writer: fix bug introduced in avoiding shell invocation callin…
Browse files Browse the repository at this point in the history
…g clear
  • Loading branch information
charles-dyfis-net committed Aug 15, 2023
1 parent 0a0f7b3 commit 31110f4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lmql/runtime/output_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def add_decoder_state(*args, **kwargs):
async def add_interpreter_head_state(self, variable, head, prompt, where, trace, is_valid, is_final, mask, num_tokens, program_variables):
if head == 0:
if self.clear:
sys.stderr.write('\033c', flush=True)
sys.stderr.write('\033c')
sys.stderr.flush()
if self.print_output:
print(f"{prompt}\n\n valid={is_valid}, final={is_final}")

def add_compiler_output(self, code): pass

class StreamingOutputWriter:
def __init__(self, variable=None):
def __init__(self, variable=None, clear=True):
self.clear = clear
self.variable = variable
self.last_value = None

Expand All @@ -87,8 +89,10 @@ async def add_interpreter_head_state(self, variable, head, prompt, where, trace,
print(value[len(self.last_value):], end="", flush=True)
self.last_value = value
return

sys.stderr.write('\033c', flush=True) # clear screen

if clear:
sys.stderr.write('\033c')
sys.stderr.flush()
print(f"{prompt}\n", end="\r")

def add_compiler_output(self, code): pass
Expand Down

0 comments on commit 31110f4

Please sign in to comment.