HugMeBytes commited on
Commit
ec73a76
·
verified ·
1 Parent(s): 7723293

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -15,13 +15,13 @@ if not os.getenv("GROQ_API_KEY"):
15
  vectorizer = TfidfVectorizer(stop_words='english')
16
 
17
  # === UTILITY FUNCTIONS ===
18
- def call_groq_api(prompt):
19
  api_key = os.getenv("GROQ_API_KEY")
20
  if not api_key:
21
  return "Error: GROQ_API_KEY environment variable not set."
22
 
23
  headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
24
- data = {"model": "mixtral-8x7b-32768", "messages": [{"role": "user", "content": prompt}]}
25
 
26
  try:
27
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", json=data, headers=headers)
@@ -33,6 +33,35 @@ def call_groq_api(prompt):
33
  return f"API Error: {str(e)}"
34
  except (KeyError, IndexError) as e:
35
  return f"Error parsing API response: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  def extract_text_from_pdfs(pdf_files):
38
  chunks, pages, file_names = [], [], []
 
15
  vectorizer = TfidfVectorizer(stop_words='english')
16
 
17
  # === UTILITY FUNCTIONS ===
18
+ """ def call_groq_api(prompt):
19
  api_key = os.getenv("GROQ_API_KEY")
20
  if not api_key:
21
  return "Error: GROQ_API_KEY environment variable not set."
22
 
23
  headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
24
+ data = {"model": "llama-3.1-70b-versatile", "messages": [{"role": "user", "content": prompt}]}
25
 
26
  try:
27
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", json=data, headers=headers)
 
33
  return f"API Error: {str(e)}"
34
  except (KeyError, IndexError) as e:
35
  return f"Error parsing API response: {str(e)}"
36
+ """
37
+
38
+ def call_groq_api(prompt):
39
+ api_key = os.getenv("GROQ_API_KEY")
40
+ if not api_key:
41
+ return "Error: GROQ_API_KEY environment variable not set."
42
+
43
+ headers = {
44
+ "Authorization": f"Bearer {api_key}",
45
+ "Content-Type": "application/json"
46
+ }
47
+
48
+ data = {
49
+ "model": "llama-3.1-70b-versatile", # ✅ updated model
50
+ "messages": [{"role": "user", "content": prompt}],
51
+ "temperature": 0.7
52
+ }
53
+
54
+ try:
55
+ response = requests.post("https://api.groq.com/openai/v1/chat/completions", json=data, headers=headers)
56
+ if response.status_code != 200:
57
+ return f"API Error {response.status_code}: {response.text}"
58
+ result = response.json()
59
+ return result["choices"][0]["message"]["content"]
60
+ except requests.exceptions.RequestException as e:
61
+ return f"Network Error: {e}"
62
+ except Exception as e:
63
+ return f"Unexpected Error: {e}"
64
+
65
 
66
  def extract_text_from_pdfs(pdf_files):
67
  chunks, pages, file_names = [], [], []