import os import openai import gradio as gr openai.api_key = os.getenv("OPENAI_API_KEY") prompt = "La siguiente es una conversación con un asistente de IA."\ "El asistente es útil, creativo, inteligente y muy amigable.\n"\ "\nHumano: Hola, ¿quién eres??"\ "\nIA: Soy una IA creada por NEO Consulting. ¿Cómo puedo ayudarte hoy?"\ "\nHumano: " def openai_create(prompt): response = openai.Completion.create( model="text-davinci-003", prompt=prompt, temperature=0, max_tokens=300, stop=[" Human:", " AI:"] ) return response.choices[0].text def chatgpt_clone(input, history): history = history or [] s = list(sum(history, ())) s.append(input) inp = ' '.join(s) output = openai_create(inp) history.append((input, output)) return history, history block = gr.Blocks() with block: gr.Markdown("""