CosmoAI commited on
Commit
6f747e2
·
verified ·
1 Parent(s): 466b57c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -7
app.py CHANGED
@@ -1,4 +1,5 @@
1
- import google.generativeai as genai
 
2
  import gradio as gr
3
  import os
4
  import json
@@ -10,15 +11,23 @@ import re
10
 
11
  # Set your API key
12
  # Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
13
- GOOGLE_API_KEY=os.getenv('GEMINI_KEY')
14
 
15
- genai.configure(api_key=GOOGLE_API_KEY)
16
- model = genai.GenerativeModel('gemini-pro')
17
 
18
  # Select the PaLM 2 model
19
  # model = 'models/text-bison-001'
20
 
21
 
 
 
 
 
 
 
 
 
22
  # contx = """Act as a friendly personal assistant.
23
  # You help users manage their daily tasks by providing them with a variety of features.
24
  # Below are the list of features you have: \n
@@ -65,8 +74,31 @@ def responsenew(data):
65
  # print(query)
66
  # except json.JSONDecodeError as e:
67
  # print("Invalid JSON:", e)
68
- response = model.generate_content(query)
69
- print(f"\n{response.text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  if query is not None:
71
  if "remind me" in query:
72
  values = getValues(query)
@@ -239,7 +271,7 @@ def responsenew(data):
239
  }
240
  else:
241
  respo = {
242
- "message": response.text,
243
  "action": "nothing",
244
  "function": "nothing",
245
  }
 
1
+ # import google.generativeai as genai
2
+ from groq import Groq
3
  import gradio as gr
4
  import os
5
  import json
 
11
 
12
  # Set your API key
13
  # Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
14
+ # GOOGLE_API_KEY=os.getenv('GEMINI_KEY')
15
 
16
+ # genai.configure(api_key=GOOGLE_API_KEY)
17
+ # model = genai.GenerativeModel('gemini-pro')
18
 
19
  # Select the PaLM 2 model
20
  # model = 'models/text-bison-001'
21
 
22
 
23
+ api1 = os.getenv("Groq_key")
24
+
25
+ apis = [
26
+ api1,
27
+ # api1,
28
+ ]
29
+
30
+
31
  # contx = """Act as a friendly personal assistant.
32
  # You help users manage their daily tasks by providing them with a variety of features.
33
  # Below are the list of features you have: \n
 
74
  # print(query)
75
  # except json.JSONDecodeError as e:
76
  # print("Invalid JSON:", e)
77
+ while True:
78
+ for api in apis:
79
+ client = Groq(
80
+ api_key=api,
81
+ ) # Configure the model with the API key
82
+ # query = st.text_input("Enter your query")
83
+ # prmptquery= f"Answer this query with wisdom, love and compassion, in context to bhagwat geeta, provide references of shloks from chapters of bhagwat geeta which is relevant to the query. Query= {query}"
84
+ try:
85
+ response = client.chat.completions.create(
86
+ messages=[
87
+ {
88
+ "role": "user",
89
+ "content": query,
90
+ }
91
+ ],
92
+ model="mixtral-8x7b-32768",
93
+ )
94
+ answer = response.choices[0].message.content
95
+ except Exception as e:
96
+ print(f"API call failed for: {e}")
97
+ if answer:
98
+ break
99
+ if answer:
100
+ break
101
+ print(f"\n{answer}")
102
  if query is not None:
103
  if "remind me" in query:
104
  values = getValues(query)
 
271
  }
272
  else:
273
  respo = {
274
+ "message": answer,
275
  "action": "nothing",
276
  "function": "nothing",
277
  }