利用目前超火、超强大的ChatGPT后台模型,构建一个属于自己的聊天机器人。废话不多说,马上上干货。具体如下:
import os
import openai
import gradio as gr
# 注意:这是在openAI官网上获取得到的API_key,每个人的API_Key不同
openai.api_key = "sk-979MyBdHAtuL9c33DSSeVY4T23233BlbkFJDV3aqP7zH7VfdRyoHrUm"
start_sequence = "AI:"
restart_sequence = "Human: "
prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.\n\nHuman: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?\nHuman: "
def openai_create(prompt):
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
return response.choices[0].