File size: 1,378 Bytes
5a97319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fdc87c
5a97319
 
 
 
 
 
7fdc87c
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
88
89
90
91
92
93
94
95
96
97
98
99
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