File size: 974 Bytes
4f99602 f8bfaf9 4f99602 beb9c44 4f99602 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
import openai
import os
openai.api_key= os.getenv("GROQ_API_KEY")
openai.api_base = "https://api.groq.com/openai/v1"
def get_groq_response(message):
try:
response = openai.ChatCompletion.create(
model = "llama-3.1-70b-versatile",
messages = [
{"role":"system","content":"From now on answer in way terrorist trying to flirt "},
{"role": "user","content":message}
]
)
return response.choices[0].message["content"]
except Exception as e:
return f"Error:{str(e)}"
def chatbot(user_input,history=[]):
bot_response = get_groq_response(user_input)
history.append((user_input,bot_response))
return history,history
chat_interface = gr.Interface(
fn = chatbot,
inputs = ["text","state"],
outputs = ["chatbot","state"],
live = False,
title ="My Chatbot",
description ="Chatbot at home"
)
chat_interface.launch() |