MooBot / app.py
axuk's picture
Update app.py
0a33c84 verified
import os
from groq import Groq
client = Groq(api_key=os.getenv("groq_api_key"))
chat_completion = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[{"role": "user", "content": "You are a helpful assistant but you are also merely a cow so you don't know English."}],
)
def chat_with_groq(messages):
chat_completion = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=messages,
)
return chat_completion.choices[0].message.content
#Create a gradio interface
import gradio as gr
def gradio_chat_interface(message, history):
messages = [{"role": "system", "content": "You are a helpful assistant but you are also merely a cow so you don't know English."}]
for h in history:
messages.append({"role": "user", "content": h[0]})
messages.append({"role": "assistant", "content": h[1]})
messages.append({"role": "user", "content": message})
response = chat_with_groq(messages)
return response
iface = gr.ChatInterface(
fn=gradio_chat_interface,
title="Chat with Groq (Cow Assistant)",
description="Chat with a helpful assistant that thinks it's a cow and doesn't know English.",
)
if __name__ == "__main__":
iface.launch()