Spaces:
Runtime error
Runtime error
File size: 924 Bytes
fcbc5f6 8f90d15 f9b0a5e 8f90d15 f9b0a5e 8f90d15 b484394 8f90d15 |
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 28 29 30 31 32 33 34 |
# -*- coding: utf-8-*-
import openai
import gradio as gr
import os
#机器人女友
openai.api_key = os.environ.get("OPENAI_API_KEY")
prompt= "You are a helpful assistant."
messages = [
{"role": "system", "content": prompt},
]
def chatbot(input):
if input:
global messages
messages.append({"role": "user", "content": input})
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
messages = [{"role": "system", "content": prompt}]
return reply
inputs = gr.inputs.Textbox(lines=7, label="通用机器人")
outputs = gr.outputs.Textbox(label="通用机器人")
app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人",
description="你面前的是一个通用机器人,你可以向他提问。",
theme="compact")
app.launch() |