Combine GPT3 with RASA

I am using RASA forms to take information from user. I need to combine GPT3 chatbot feature for any out of scope question ask by user inside form filling. I created a custom action which uses GPT3 chatbot. I add a rule for out of scope intent, which will activate custom function and use will chat with gpt3 bot. But rule is not getting trigger when I enter out of scope query while chatting with bot. Is anybody already use combination of RASA and GPT3. Can you help me how we can create a rule for this.

2 Likes

Hello!

Thank you for your question, you could try this:

rules:
- rule: Handle out of scope
  condition:
  - active_loop: user_info_form
  steps:
  - intent: out_of_scope
  - action: action_call_gpt3
  - action: user_info_form
  - active_loop: user_info_form

Also you could check my tutorial about Rasa and Blenderbot integration to see different options. I will add your case later, thank you.

hello @rupesh2306 ,

I am trying to integrate rasa with gpt3, but not getting the proper response. Can help me out to look at my code and tell me issue.

def gpt3(text):
    response = openai.Completion.create(
        model="code-cushman-001",
        # engine="ada",
        prompt="\n\n" + text,
        temperature=0,
        logprobs=10,
        max_tokens=150,
        top_p=0,
        frequency_penalty=0,
        presence_penalty=0,
        stop=[" \n\n"]
    ) 
    return response['choices'][0]['text']

action.py

class ActionDefaultFallback(Action):
    def init(self):
        # self.gpt3 = gpt3()
        super()._init_()

    def name(self) -> Text:
        return "action_default_fallback"

    async def run(self, dispatcher, tracker, domain):
        query = tracker.latest_message['text']
        dispatcher.utter_message(text=gpt3(query))

        return [UserUtteranceReverted()]

Not able to understand the issue. Help me out to solve this.

Thanks

@artemsnegirev

Hello!

Could you expand the problem in “the proper response”? Action seems ok to me. I’ve never used GPT-3. Does you gpt3 function respond okay?

Thanks @artemsnegirev for your response.

If I separately run the def gpt3(text) function than getting the proper response. But using rasa server it not giving proper response, some meaning less response. I guess because of execution time of gpt-3 api in rasa server. Do you have any solution how we can solve this issue.

Do i correctly understand that if you send to gpt3 function separately some text (for example “hello how are you”), then you get a proper answer and if you send to gpt3 function using rasa the same text you don’t get proper answer?

@artemsnegirev Yes, exactly

Have you tried to check you get equal query text as you input text to Rasa? If they are equal, i have no idea.

yes, both are equal.

Hi, wondering if you found a solution here. Thank you!