Skip to content

Commit

Permalink
made completion more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
matt200-ok committed Nov 20, 2024
1 parent eb8d8a3 commit 420c337
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions recipes/llm-voice-assistant/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def __init__(self, stop_phrases: list) -> None:
self.stop_phrases = stop_phrases
self.start: int = 0
self.text: str = ''
self.new_tokens: str = ''

def append(self, text: str) -> str:
def append(self, text: str) -> None:
self.text += text
end = len(self.text)

Expand All @@ -84,7 +85,11 @@ def append(self, text: str) -> str:

start = self.start
self.start = end
return self.text[start:end]
self.new_tokens = self.text[start:end]

def get_new_tokens(self) -> str:
return self.new_tokens



def orca_worker(access_key: str, connection, warmup_sec: float, stream_frame_sec: int = 0.03) -> None:
Expand Down Expand Up @@ -330,13 +335,14 @@ def llm_task(dialog, user_request, utterance_end_sec, main_connection):

def llm_callback(text: str) -> None:
picollm_profiler.tock()
diff = completion.append(text)
if len(diff) > 0:
completion.append(text)
new_tokens = completion.get_new_tokens()
if len(new_tokens) > 0:
main_connection.send({
'command': 'synthesize',
'text': diff.replace('\n', ' . '),
'text': new_tokens.replace('\n', ' . '),
'utterance_end_sec': utterance_end_sec})
print(f'{diff}', end='', flush=True)
print(f'{new_tokens}', end='', flush=True)

print(
f"\nLLM (say {'`Picovoice`' if keyword_model_path is None else 'the wake word'} to interrupt) > ",
Expand Down

0 comments on commit 420c337

Please sign in to comment.