File size: 717 Bytes
a62dfe7
0a03a03
a62dfe7
388cecc
a62dfe7
0a03a03
a62dfe7
 
 
 
 
 
0a03a03
a62dfe7
 
 
 
 
 
 
 
0a03a03
a62dfe7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()