带有 SQLite-DB 的 Rasa

Rasa with SQLite-DB

提问人:b0sna 提问时间:11/9/2023 更新时间:11/9/2023 访问量:29

问:

我想制作一个保存信息的 rasa 聊天机器人,如果我说“记住......”。

不知何故,它不会给我反馈,如果它保存了信息,如果我要求提供信息,它也不会回答。

这是我 actions.py:

# actions.py
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, UserUtteranceReverted
from rasa_sdk.executor import CollectingDispatcher
from typing import Text, List, Dict, Any, Union

class SpeicherInfoAction(Action):
    def name(self) -> Text:
        return "action_speicher_info"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]:
        # Intent aus dem aktuellen Zustand abrufen
        intent = tracker.latest_message['intent'].get('name')

        # Slots aus dem aktuellen Zustand abrufen und speichern
        slots_to_set = []
        for slot_name, slot_value in tracker.current_slot_values().items():
            if slot_value is not None:
                slots_to_set.append(SlotSet(slot_name, slot_value))

        if slots_to_set:
            # Wenn Slots gefunden wurden, werden diese zurückgegeben
            dispatcher.utter_message("Ich habe die Informationen gespeichert.")
            return slots_to_set
        else:
            dispatcher.utter_message("Ich konnte keine neuen Informationen speichern.")
            return []

这是我nlu.yml(它是德语的,但它实际上以“记住......”开头:

version: "2.0"

nlu:
- intent: greet
  examples: |
    - hey
    - hello
    - hi
    - hello there
    - good morning
    - good evening
    - moin
    - hey there
    - let's go
    - hey dude
    - goodmorning
    - goodevening
    - good afternoon

- intent: goodbye
  examples: |
    - good afternoon
    - cu
    - good by
    - cee you later
    - good night
    - bye
    - goodbye
    - have a nice day
    - see you around
    - bye bye
    - see you later

- intent: affirm
  examples: |
    - yes
    - y
    - indeed
    - of course
    - that sounds good
    - correct

- intent: deny
  examples: |
    - no
    - n
    - never
    - I don't think so
    - don't like that
    - no way
    - not really

- intent: mood_great
  examples: |
    - perfect
    - great
    - amazing
    - feeling like a king
    - wonderful
    - I am feeling very good
    - I am great
    - I am amazing
    - I am going to save the world
    - super stoked
    - extremely good
    - so so perfect
    - so good
    - so perfect

- intent: mood_unhappy
  examples: |
    - my day was horrible
    - I am sad
    - I don't feel very well
    - I am disappointed
    - super sad
    - I'm so sad
    - sad
    - very sad
    - unhappy
    - not good
    - not very good
    - extremly sad
    - so saad
    - so sad

- intent: bot_challenge
  examples: |
    - are you a bot?
    - are you a human?
    - am I talking to a bot?
    - am I talking to a human?

- intent: speicher_info
  examples: |
    - Merk dir, dass meine Lieblingsfarbe [blau](lieblingsfarbe) ist
    - Speicher, dass am Freitag [Döner](freitag_info) kommt
    - Merk dir, dass [Sarma](lieblingsessen) mein Lieblingsessen ist

这是我domain.yml:

version: "2.0"

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge
  - speicher_info

entities:
  - lieblingsfarbe
  - freitag_info

slots:
  lieblingsfarbe:
    type: text
    influence_conversation: false
    mappings:
      - type: from_entity
        entity: lieblingsfarbe
  freitag_info:
    type: text
    influence_conversation: false
    mappings:
      - type: from_entity
        entity: freitag_info
  lieblingsessen:
    type: text
    influence_conversation: false
    mappings:
      - type: from_entity
        entity: lieblingsessen


responses:
  utter_greet:
    - text: "Hey! How are you?"

  utter_cheer_up:
    - text: "Here is something to cheer you up:"
      image: "https://i.imgur.com/nGF1K8f.jpg"

  utter_did_that_help:
    - text: "Did that help you?"

  utter_happy:
    - text: "Great, carry on!"

  utter_goodbye:
    - text: "Bye"

  utter_iamabot:
    - text: "I am a bot, powered by Rasa."

actions:
  - action_speicher_info

session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true

我的数据库叫做:rasa_db.db。config.yml是:

language: de

pipeline:
  - name: SpacyNLP
    model: "de_core_news_md"  # Verwendet das deutsche Spacy-Modell
  - name: SpacyTokenizer
  - name: SpacyFeaturizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
  - name: FallbackClassifier
    threshold: 0.7
    ambiguity_threshold: 0.1

store_db:
  type: SQL
  dialect: "sqlite"
  url: "sqlite:///rasa_db.db"

policies:
  - name: MemoizationPolicy
  - name: TEDPolicy
    max_history: 5
    epochs: 100
  - name: RulePolicy

assistant_id: 20231109-043132-frayed-mole

有人有想法吗?多谢!

python sqlite bots chatbot rasa

评论

0赞 Leo Guagenti 11/12/2023
你忘了包括任何故事/规则吗?如果您没有,则您的操作将永远不会运行。action_speicher_info

答: 暂无答案