chatBot / app.py
LeeKinXUn's picture
Update app.py
428fda5
import openai,os
import gradio as gr
from gradio.components import Textbox
openai.api_key = 'OPENAI_API_KEY'
messages = [
{"role": "system", "content": "You are a helpful and kind AI Assistant."},
]
def ChatGPT_Bot(input):
if input:
messages.append({"role": "user", "content": input})
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
inputs = Textbox(lines=7, label="请输入你的问题")
outputs = Textbox(lines=7, label="来自ChatGPT的回答")
gr.Interface(fn=ChatGPT_Bot, inputs=inputs, outputs=outputs, title="ChatGPT AI助理",
description="我是您的AI助理,您可以问任何你想知道的问题",
theme=gr.themes.Default()).launch()