Spaces:
Runtime error
Runtime error
import openai,os | |
import gradio as gr | |
from gradio.components import Textbox | |
os.environ["http_proxy"] = "http://localhost:7890" | |
os.environ["https_proxy"] = "http://localhost:7890" | |
openai.api_key = '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' | |
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(share=True) |