将GPT3与Rasa结合使用

3yhwsihp  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(612)

我正在尝试整合Rasa与gpt3,但没有得到适当的回应。可以帮助我看看我的代码,并告诉我的问题。

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()]

无法理解此问题。请帮助我解决此问题。
谢谢

ctrmrzij

ctrmrzij1#

希望这是解决。在情况下有人跟进这一点。由于确切的错误没有提供不确定答案是正确的,但我能够工作很少修改上述代码。

def gpt3(text):
 try:
    response = openai.Completion.create(
        # model="text-davinci-003",
        model="text-ada-001",
        prompt="\n\n" + text + "?",
        temperature=0,
        logprobs=10,
        max_tokens=100,
        top_p=0,
        frequency_penalty=0,
        presence_penalty=0,
        stop=[" \n\n"]
    )

    return response['choices'][0]['text']
 except Exception as e:
    logger.error('openai request failed')

actions.py

class ActionDefaultFallback(Action):
 def init(self):
    super().__init__()

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

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

相关问题