grock_chat / app.py
reshav1's picture
Update app.py
7fdc87c verified
raw
history blame
1.38 kB
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
def make_call(api):
"""Calls the Groq API (assuming API key auth) and handles potential errors."""
try:
client = Groq(
api_key=api,
) # Configure the model with the API key
query = st.text_input("Enter your query")
prmptquery= f"give the answer of given query in context to bhagwat geeta: {query}"
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prmptquery,
}
],
model="mixtral-8x7b-32768",
)
# print(response.text) # Return the response for further processing
return chat_completion.choices[0].message.content
except Exception as e:
print(f"API call failed for: {e}")
return None # Indicate failur
api1 = os.getenv("GROQ_API_KEY1")
apis = [
GROQ_API_KEY1,
# api1,
]
# Loop indefinitely
data = None
# while True: # Loop indefinitely
for api in apis:
data = make_call(api)
if data: # Check for a successful response
st.write(data)
break # Exit both the for loop and while loop
else:
st.write(f"Failed to retrieve data from.")
# if data: # If a successful response was found, break the outer while loop
# break