|
|
@ -87,6 +87,9 @@ Remember: You can run Python code. Be very concise. Ensure that you actually run
|
|
|
|
# This is the name that will appear to the LLM.
|
|
|
|
# This is the name that will appear to the LLM.
|
|
|
|
name = "python"
|
|
|
|
name = "python"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.halt = False
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, code):
|
|
|
|
def run(self, code):
|
|
|
|
"""Generator that yields a dictionary in LMC Format."""
|
|
|
|
"""Generator that yields a dictionary in LMC Format."""
|
|
|
|
|
|
|
|
|
|
|
@ -98,17 +101,18 @@ Remember: You can run Python code. Be very concise. Ensure that you actually run
|
|
|
|
response = requests.post(f"http://localhost:{computer_port}/run", json=data, stream=True)
|
|
|
|
response = requests.post(f"http://localhost:{computer_port}/run", json=data, stream=True)
|
|
|
|
# Stream the response
|
|
|
|
# Stream the response
|
|
|
|
for chunk in response.iter_content(chunk_size=100000000):
|
|
|
|
for chunk in response.iter_content(chunk_size=100000000):
|
|
|
|
|
|
|
|
if self.halt:
|
|
|
|
|
|
|
|
self.halt = False
|
|
|
|
|
|
|
|
break
|
|
|
|
if chunk: # filter out keep-alive new lines
|
|
|
|
if chunk: # filter out keep-alive new lines
|
|
|
|
yield json.loads(chunk.decode())
|
|
|
|
yield json.loads(chunk.decode())
|
|
|
|
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
def stop(self):
|
|
|
|
"""Stops the code."""
|
|
|
|
self.halt = True
|
|
|
|
# Not needed here, because e2b.run_code isn't stateful.
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def terminate(self):
|
|
|
|
def terminate(self):
|
|
|
|
"""Terminates the entire process."""
|
|
|
|
"""Terminates the entire process."""
|
|
|
|
# Not needed here, because e2b.run_code isn't stateful.
|
|
|
|
# dramatic!!
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
interpreter.computer.languages = [Python]
|
|
|
|
interpreter.computer.languages = [Python]
|
|
|
|