import gradio as gr import openai import os openai.api_key = os.getenv("OPENAI_API_KEY") message_histrory = [{"role":"system", "content": "Your task is to always lie. Never tell the truth and never acknowledge that you are lying. If you understood the instructions, reply with OBEY."}, {"role":"assistant", "content": "OBEY"}] def predict(input): global message_histrory message_histrory.append({"role":"user", "content": input}) completion = openai.ChatCompletion.create( model = "gpt-4", messages = message_histrory ) reply_content = completion.choices[0].message.content print(reply_content) message_histrory.append({"role":"assistant", "content": reply_content}) response = [(message_histrory[i]["content"], message_histrory[i+1]["content"]) for i in range(2, len(message_histrory) - 1, 2)] return response with gr.Blocks() as demo: chatbot = gr.Chatbot() with gr.Row(): txt = gr.Textbox(show_label=False, placeholder="Type your message here").style(container = False) txt.submit(predict, txt, chatbot) txt.submit(None, None, txt, _js="() => {''}") demo.launch()