From 92c29efba17e077d414b27e846c4ede07afbd51c Mon Sep 17 00:00:00 2001 From: miro Date: Wed, 13 Nov 2024 16:35:57 +0000 Subject: [PATCH] feat:streaming support stream utterances for speed --- ovos_persona/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ovos_persona/__init__.py b/ovos_persona/__init__.py index 5f1bd38..55153c7 100644 --- a/ovos_persona/__init__.py +++ b/ovos_persona/__init__.py @@ -161,9 +161,10 @@ def chatbox_ask(self, prompt: str, messages.append({"role": "user", "content": prompt}) if stream: yield from self.personas[persona].stream(messages, lang) - ans = self.personas[persona].chat(messages, lang) - if ans: - yield ans + else: + ans = self.personas[persona].chat(messages, lang) + if ans: + yield ans def _build_msg_history(self, message: Message): sess = SessionManager.get(message) @@ -256,7 +257,7 @@ def match_low(self, utterances: List[str], lang: Optional[str] = None, return IntentHandlerMatch(match_type='persona:query', match_data={"utterance": utterances[0], "lang": lang, - "persona": self.active_persona}, + "persona": self.active_persona or self.default_persona}, skill_id="persona.openvoiceos", utterance=utterances[0]) @@ -310,7 +311,8 @@ def handle_persona_release(self, message): print(b.personas) print(b.match_low(["what is the speed of light"])) - + for ans in b.chatbox_ask("what is the speed of light"): + print(ans) # The speed of light has a value of about 300 million meters per second # The telephone was invented by Alexander Graham Bell # Stephen William Hawking (8 January 1942 – 14 March 2018) was an English theoretical physicist, cosmologist, and author who, at the time of his death, was director of research at the Centre for Theoretical Cosmology at the University of Cambridge.