Skip to content

Commit 07baa29

Browse files
fix:better_stop (#643)
* fix:better_stop * requirements.txt * python versions * requirements.txt * 📝 Add docstrings to `stop` (#644) Docstrings generation was requested by @JarbasAl. * #643 (comment) The following files were modified: * `ovos_core/intent_services/__init__.py` * `ovos_core/intent_services/converse_service.py` * `ovos_core/intent_services/stop_service.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: stop DRY no need for 2 handlers, decrease complexity the only difference is an emitted event that is not listened too anywhere * requirements.txt * tests * tests * tests * tests --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 83ba17d commit 07baa29

File tree

13 files changed

+260
-118
lines changed

13 files changed

+260
-118
lines changed

.github/workflows/build_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
max-parallel: 2
1818
matrix:
19-
python-version: [3.8, 3.9, "3.10", "3.11"]
19+
python-version: ["3.10", "3.11"]
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v2

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Python
1616
uses: actions/setup-python@master
1717
with:
18-
python-version: 3.9
18+
python-version: "3.10"
1919
- name: Install System Dependencies
2020
run: |
2121
sudo apt-get update

.github/workflows/license_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
requirements: 'requirements-all.txt'
3838
fail: 'Copyleft,Other,Error'
3939
fails-only: true
40-
exclude: '^(precise-runner|fann2|ovos-adapt-parser|ovos-padatious|tqdm|bs4|sonopy|caldav|recurring-ical-events|x-wr-timezone|zeroconf|mutagen).*'
40+
exclude: '^(precise-runner|fann2|ovos-adapt-parser|ovos-padatious|tqdm|bs4|sonopy|caldav|recurring-ical-events|x-wr-timezone|zeroconf|mutagen|attrs).*'
4141
exclude-license: '^(Mozilla).*$'
4242
- name: Print report
4343
if: ${{ always() }}

.github/workflows/pipaudit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
max-parallel: 2
1313
matrix:
14-
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]
14+
python-version: [3.9, "3.10", "3.11"]
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2

.github/workflows/sync_tx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Python
1919
uses: actions/setup-python@v1
2020
with:
21-
python-version: 3.9
21+
python-version: "3.10"
2222

2323
- name: Run script if merged by gitlocalize-app[bot]
2424
if: github.event_name == 'push' && github.event.head_commit.author.username == 'gitlocalize-app[bot]'

ovos_core/intent_services/__init__.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,34 @@ def _handle_deactivate(self, message):
268268
self._deactivations[sess.session_id].append(skill_id)
269269

270270
def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], message: Message):
271-
"""Update the message data with the matched utterance information and
272-
activate the corresponding skill if available.
273-
271+
"""
272+
Emit a reply message for a matched intent, updating session and skill activation.
273+
274+
This method processes matched intents from either a pipeline matcher or an intent handler,
275+
creating a reply message with matched intent details and managing skill activation.
276+
274277
Args:
275-
match (IntentHandlerMatch): The matched utterance object.
276-
message (Message): The messagebus data.
278+
match (Union[IntentHandlerMatch, PipelineMatch]): The matched intent object containing
279+
utterance and matching information.
280+
message (Message): The original messagebus message that triggered the intent match.
281+
282+
Details:
283+
- Handles two types of matches: PipelineMatch and IntentHandlerMatch
284+
- Creates a reply message with matched intent data
285+
- Activates the corresponding skill if not previously deactivated
286+
- Updates session information
287+
- Emits the reply message on the messagebus
288+
289+
Side Effects:
290+
- Modifies session state
291+
- Emits a messagebus event
292+
- Can trigger skill activation events
293+
294+
Returns:
295+
None
277296
"""
278297
reply = None
279-
sess = SessionManager.get(message)
298+
sess = match.updated_session or SessionManager.get(message)
280299

281300
# utterance fully handled by pipeline matcher
282301
if isinstance(match, PipelineMatch):
@@ -303,13 +322,34 @@ def _emit_match_message(self, match: Union[IntentHandlerMatch, PipelineMatch], m
303322
was_deactivated = match.skill_id in self._deactivations[sess.session_id]
304323
if not was_deactivated:
305324
sess.activate_skill(match.skill_id)
306-
reply.context["session"] = sess.serialize()
307325
# emit event for skills callback -> self.handle_activate
308326
self.bus.emit(reply.forward(f"{match.skill_id}.activate"))
309327

328+
# update Session if modified by pipeline
329+
reply.context["session"] = sess.serialize()
330+
331+
# finally emit reply message
310332
self.bus.emit(reply)
311333

312334
def send_cancel_event(self, message):
335+
"""
336+
Emit events and play a sound when an utterance is canceled.
337+
338+
Logs the cancellation with the specific cancel word, plays a predefined cancel sound,
339+
and emits multiple events to signal the utterance cancellation.
340+
341+
Parameters:
342+
message (Message): The original message that triggered the cancellation.
343+
344+
Events Emitted:
345+
- 'mycroft.audio.play_sound': Plays a cancel sound from configuration
346+
- 'ovos.utterance.cancelled': Signals that the utterance was canceled
347+
- 'ovos.utterance.handled': Indicates the utterance processing is complete
348+
349+
Notes:
350+
- Uses the default cancel sound path 'snd/cancel.mp3' if not specified in configuration
351+
- Ensures events are sent as replies to the original message
352+
"""
313353
LOG.info("utterance canceled, cancel_word:" + message.context.get("cancel_word"))
314354
# play dedicated cancel sound
315355
sound = Configuration().get('sounds', {}).get('cancel', "snd/cancel.mp3")

ovos_core/intent_services/converse_service.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,29 @@ def converse(self, utterances: List[str], skill_id: str, lang: str, message: Mes
313313
return False
314314

315315
def converse_with_skills(self, utterances: List[str], lang: str, message: Message) -> Optional[PipelineMatch]:
316-
"""Give active skills a chance at the utterance
317-
316+
"""
317+
Attempt to converse with active skills for a given set of utterances.
318+
319+
Iterates through active skills to find one that can handle the utterance. Filters skills based on timeout and blacklist status.
320+
318321
Args:
319-
utterances (list): list of utterances
320-
lang (string): 4 letter ISO language code
321-
message (Message): message to use to generate reply
322-
322+
utterances (List[str]): List of utterance strings to process
323+
lang (str): 4-letter ISO language code for the utterances
324+
message (Message): Message context for generating a reply
325+
323326
Returns:
324-
IntentMatch if handled otherwise None.
327+
PipelineMatch: Match details if a skill successfully handles the utterance, otherwise None
328+
- handled (bool): Whether the utterance was fully handled
329+
- match_data (dict): Additional match metadata
330+
- skill_id (str): ID of the skill that handled the utterance
331+
- updated_session (Session): Current session state after skill interaction
332+
- utterance (str): The original utterance processed
333+
334+
Notes:
335+
- Standardizes language tag
336+
- Filters out blacklisted skills
337+
- Checks for skill conversation timeouts
338+
- Attempts conversation with each eligible skill
325339
"""
326340
lang = standardize_lang_tag(lang)
327341
session = SessionManager.get(message)
@@ -342,6 +356,7 @@ def converse_with_skills(self, utterances: List[str], lang: str, message: Messag
342356
# handled == True -> emit "ovos.utterance.handled"
343357
match_data={},
344358
skill_id=skill_id,
359+
updated_session=session,
345360
utterance=utterances[0])
346361
return None
347362

0 commit comments

Comments
 (0)