chat / app.py
HusseinBashir's picture
Update app.py
a62dfe7 verified
raw
history blame contribute delete
717 Bytes
import openai
import gradio as gr
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
def chat(user_input, history=[]):
messages = [{"role": "system", "content": "Ka jawaab su’aalaha af Soomaali"}]
for q, a in history:
messages.append({"role": "user", "content": q})
messages.append({"role": "assistant", "content": a})
messages.append({"role": "user", "content": user_input})
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=messages,
temperature=0.7
)
reply = response.choices[0].message.content
history.append((user_input, reply))
return history, history
gr.ChatInterface(chat, title="Chatbot Af Soomaali").launch()