Hi! I am trying to get chatgpt to answer on behalf of my Rasa bot in the event of all fallback, but this code results in no recognised ‘action_default_fallback’. I have registered this action in domains.yml
Can anyone please help?
Config.yml
pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
analyzer: char_wb
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
constrain_similarities: true
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
constrain_similarities: true
- name: FallbackClassifier
threshold: 0.7
ambiguity_threshold: 0.1
policies:
- name: RulePolicy
core_fallback_threshold: 0.4
core_fallback_action_name: "action_default_fallback"
enable_fallback_prediction: True
Actions.py
class ActionDefaultFallback(Action):
def name(self) -> Text:
return "action_default_fallback"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:
# Get user message from Rasa tracker
user_message = tracker.latest_message.get('text')
# def get_chatgpt_response(self, message):
url = 'https://api.openai.com/v1/chat/completions'
headers = {
'Authorization': 'Bearer sk-xxxxxxxxxxxxxxxxxxxxxxXD',
'Content-Type': 'application/json'
}
data = {
'model': "gpt-3.5-turbo",
'messages': [{'role': 'user', 'content': 'You: ' + user_message}],
'max_tokens': 100
}
response = requests.post(url, headers=headers, json=data)
# response = requests.post(api_url, headers=headers, json=data)
if response.status_code == 200:
ai = response.json()['choices'][0]['message']['content']
dispatcher.utter_message(ai)
else:
# Handle error
return "Sorry, I couldn't generate a response at the moment. Please try again later."