import openai import os import gradio as gr from langchain.chat_models import ChatOpenAI from langchain.schema import AIMessage, HumanMessage os.environ["OPENAI_API_KEY"] = "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" # Replace with your key llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613') def predict(message, history): history_langchain_format = [] for human, ai in history: history_langchain_format.append(HumanMessage(content=human)) history_langchain_format.append(AIMessage(content=ai)) history_langchain_format.append(HumanMessage(content=message)) gpt_response = llm(history_langchain_format) return gpt_response.content gr.ChatInterface( predict, chatbot=gr.Chatbot(height=300), textbox=gr.Textbox(placeholder="Custom GPT", container=False, scale=7), title="Custom ChatGPT", description="Ask any question", theme="soft", examples=["Hello", "are you GPT-4?", "how can i build my own ChatGPT?"], cache_examples=True, retry_btn=None, undo_btn="Delete Previous", clear_btn="Clear", ).launch()