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_KEY") apis = [ api1, # 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