File size: 891 Bytes
2345f47
 
 
 
5029b93
2345f47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428fda5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()