File size: 1,512 Bytes
5a97319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d144cd
5a97319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fdc87c
192716b
5a97319
 
 
 
 
bf3fbda
192716b
5a97319
 
 
 
 
 
 
 
 
 
a431ac7
5a97319
 
 
 
a431ac7
5a97319
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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"Act as bhagwan Krishna and answer this query in context to bhagwat geeta, you may also provide reference to shloks from chapters of bhagwat geeta which is relevant to the query. Query= {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")
api2 = os.getenv("GROQ_API_KEY2")



apis = [

    api1,
    api2

]




# 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