I am developing a chatbot using rasa. To response out of scope question I implemented an openAI functions in actions.py file. I got a token as well. Here is the code ,
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') print(user_message) # def get_chatgpt_response(self, message): url = ' ' headers = { 'Authorization': 'Bearer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■rYMurEXC', 'Content-Type': 'application/json' } data = { 'model': "gpt-3.5-turbo", 'messages': [ {'role': 'system', 'content': 'You are an AI assistant for the user. You help to solve user query'}, {'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: chatgpt_response = response.json() message = chatgpt_response['choices'][0]['message']['content'] dispatcher.utter_message(message) else: # Handle error return "Sorry, I couldn't generate a response at the moment. Please try again later." # Revert user message which led to fallback. return [UserUtteranceReverted()]
and in config.yml file I have the code below,
The config recipe.
recipe: default.v1
The assistant project unique identifier
This default value must be replaced with a unique assistant name within your deployment
assistant_id: 20230531-120857-some-blowfish
Configuration for Rasa NLU.
language: en
pipeline:
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: “char_wb”
min_ngram: 1
max_ngram: 4- name: DIETClassifier
epochs: 120
entity_recognition: False- name: ResponseSelector
epochs: 100- name: FallbackClassifier
threshold: 0.85policies:
- name: TEDPolicy
max_history: 10
epochs: 20- name: AugmentedMemoizationPolicy
max_history: 6- name: RulePolicy
core_fallback_threshold: 0.4
core_fallback_action_name: “action_default_fallback”
enable_fallback_prediction: True
When is ask a question it give an error,
2023-06-22 08:26:32 ERROR rasa_sdk.executor - Your action’s ‘action_default_fallback’ run method returned an invalid event. Event will be ignored. what is the reason for that.