Skip to content

Commit

Permalink
default session managed by core (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Sep 29, 2023
1 parent 5af1c23 commit cf131fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions ovos_core/intent_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __init__(self, bus):
self.common_qa = CommonQAService(bus)
self.utterance_plugins = UtteranceTransformersService(bus, config=config)
self.metadata_plugins = MetadataTransformersService(bus, config=config)
# connection SessionManager to the bus,
# this will sync default session across all components
SessionManager.connect_to_bus(self.bus)

self.bus.on('register_vocab', self.handle_register_vocab)
self.bus.on('register_intent', self.handle_register_intent)
Expand Down Expand Up @@ -273,11 +276,18 @@ def handle_utterance(self, message):

stopwatch = Stopwatch()

# get session
sess = SessionManager.get(message)
if sess.session_id == "default":
# Default session, check if it needs to be (re)-created
if sess.expired():
sess = SessionManager.reset_default_session()
sess.lang = lang

# match
match = None
with stopwatch:
# Loop through the matching functions until a match is found.
sess = SessionManager.get(message)
for match_func in self.get_pipeline(session=sess):
match = match_func(utterances, lang, message)
if match:
Expand All @@ -287,7 +297,7 @@ def handle_utterance(self, message):
message.data["utterance"] = match.utterance

if match.skill_id:
self.converse.activate_skill(match.skill_id)
self.converse.activate_skill(match.skill_id, message=message)
message.context["skill_id"] = match.skill_id
# If the service didn't report back the skill_id it
# takes on the responsibility of making the skill "active"
Expand All @@ -306,6 +316,9 @@ def handle_utterance(self, message):
# Ask politely for forgiveness for failing in this vital task
self.send_complete_intent_failure(message)

# sync any changes made to the default session, eg by ConverseService
if sess.session_id == "default":
SessionManager.sync()
return match, message.context, stopwatch

except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ combo-lock>=0.2.2, <0.3
padacioso~=0.2, >=0.2.1a8
adapt-parser>=1.0.0, <2.0.0

ovos_bus_client~=0.0,>=0.0.6a7
ovos_bus_client~=0.0,>=0.0.6a8
ovos-utils<0.1.0, >=0.0.35a7
ovos-plugin-manager<0.1.0, >=0.0.24a5
ovos-config~=0.0,>=0.0.11a9
Expand Down

0 comments on commit cf131fe

Please sign in to comment.