Spaces:
Sleeping
Sleeping
File size: 1,119 Bytes
5ce92d1 |
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 35 36 37 38 39 |
import streamlit as st
import os
from groq import Groq
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Title of the app
st.title("Simple AI Agent with LLaMA 3.1")
# Description
st.markdown("This is an AI agent powered by the LLaMA 3.1 model and Groq API.")
# Input for user queries
user_input = st.text_input("Ask something:")
# Display response area
if st.button("Get Response"):
# Fetch API key from .env file
api_key = os.getenv("GROQ_API_KEY")
if api_key and user_input:
# Set up Groq client
client = Groq(api_key=api_key)
try:
# Send query to LLaMA model
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="llama3-8b-8192",
)
# Display response
st.success(chat_completion.choices[0].message.content)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please ensure the API key is set in the .env file and ask a valid question.")
|