|
import openai |
|
|
|
openai.api_key = "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 |
|
" |
|
|
|
|
|
import os |
|
import openai |
|
import gradio as gr |
|
|
|
openai.api_key = os.getenv("OPENAI_API_KEY") |
|
|
|
def chat_with_synthia(user_message, chat_history): |
|
messages = [{"role": "system", "content": "You are SYNTHIA, a helpful and friendly AI assistant."}] |
|
for user, bot in chat_history: |
|
messages.append({"role": "user", "content": user}) |
|
messages.append({"role": "assistant", "content": bot}) |
|
messages.append({"role": "user", "content": user_message}) |
|
|
|
response = openai.ChatCompletion.create( |
|
model="gpt-4o-mini", |
|
messages=messages, |
|
max_tokens=150, |
|
temperature=0.7, |
|
) |
|
reply = response.choices[0].message['content'] |
|
chat_history.append((user_message, reply)) |
|
return "", chat_history |
|
|
|
with gr.Blocks() as app: |
|
gr.Markdown("# SYNTHIA β Your smart AI assistant π€π") |
|
chatbot = gr.Chatbot() |
|
msg = gr.Textbox(placeholder="Say something to SYNTHIA...") |
|
clear = gr.Button("Clear") |
|
|
|
msg.submit(chat_with_synthia, [msg, chatbot], [msg, chatbot]) |
|
clear.click(lambda: None, None, chatbot, queue=False) |
|
|
|
if __name__ == "__main__": |
|
app.launch() |
|
|