import gradio as gr import openai openai.api_key = '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' def chat(message,history): history = history or [] messages = [{'role':'system','content':'you are a helpful assistant'}] for user_ask,gpt_answer in history: messages.append({'role':'user','content':user_ask}) messages.append({'role':'assistant','content':gpt_answer}) messages.append({'role':'user','content':message}) get_response = openai.ChatCompletion.create( model = 'gpt-3.5-turbo', messages = messages, temperature = 0.7, max_tokens = 1000 ) real_response = get_response['choices'][0]['message']['content'] history.append((message,real_response)) return history,history # seafoam = gr.Theme.from_hub('gradio/seafoam') with gr.Blocks() as demo: gr.Markdown('