little things

pull/11/head
killian 11 months ago
parent 63ab616082
commit a4fcac8926

@ -93,21 +93,19 @@ def queue_listener():
to_user.put(chunk) to_user.put(chunk)
# Speak full sentences out loud # Speak full sentences out loud
accumulated_text += chunk["content"] if chunk["type"] == "assistant":
sentences = split_into_sentences(accumulated_text) accumulated_text += chunk["content"]
if is_full_sentence(sentences[-1]): sentences = split_into_sentences(accumulated_text)
for sentence in sentences: if is_full_sentence(sentences[-1]):
for audio_chunk in tts(sentence): for sentence in sentences:
to_user.put(audio_chunk) for audio_chunk in tts(sentence):
accumulated_text = "" to_user.put(audio_chunk)
else: accumulated_text = ""
for sentence in sentences[:-1]: else:
for audio_chunk in tts(sentence): for sentence in sentences[:-1]:
to_user.put(audio_chunk) for audio_chunk in tts(sentence):
accumulated_text = sentences[-1] to_user.put(audio_chunk)
accumulated_text = sentences[-1]
if chunk["type"] == "message" and "content" in sentence:
sentence += chunk.get("content")
# If we have a new message, save our progress and go back to the top # If we have a new message, save our progress and go back to the top
if not to_assistant.empty(): if not to_assistant.empty():

@ -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]

Loading…
Cancel
Save