Kashaf10 commited on
Commit
fbb0f74
·
verified ·
1 Parent(s): e5cfc3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -13,15 +13,14 @@ import os
13
  # GLOBAL VARIABLES
14
  # -----------------------------------------------------
15
  GROQ_API_KEY = os.getenv("Projectkey")
16
- client = Groq(api_key=GROQ_API_KEY)
17
 
18
  embedder = SentenceTransformer("all-MiniLM-L6-v2")
19
  faiss_index = None
20
  stored_chunks = []
21
- client = None # Will be initialized after API key input
22
 
23
  # -----------------------------------------------------
24
- # SIMPLE TEXT SPLITTER (No Langchain)
25
  # -----------------------------------------------------
26
  def simple_text_splitter(text, chunk_size=600, overlap=100):
27
  chunks = []
@@ -32,14 +31,13 @@ def simple_text_splitter(text, chunk_size=600, overlap=100):
32
  start += chunk_size - overlap
33
  return chunks
34
 
35
- # -----------------------------------------------------
36
  # -----------------------------------------------------
37
  # SAFE LLM CALL
38
  # -----------------------------------------------------
39
  def ask_llm(prompt):
40
  global client
41
  if client is None:
42
- return "⚠ Please set your GROQ API key first."
43
  try:
44
  response = client.chat.completions.create(
45
  model="llama-3.1-8b-instant",
@@ -100,10 +98,8 @@ def query_rag(question):
100
 
101
  prompt = f"""
102
  Use ONLY the context below to answer.
103
-
104
  CONTEXT:
105
  {retrieved}
106
-
107
  QUESTION:
108
  {question}
109
  """
 
13
  # GLOBAL VARIABLES
14
  # -----------------------------------------------------
15
  GROQ_API_KEY = os.getenv("Projectkey")
16
+ client = Groq(api_key=GROQ_API_KEY) # <-- use your environment variable directly
17
 
18
  embedder = SentenceTransformer("all-MiniLM-L6-v2")
19
  faiss_index = None
20
  stored_chunks = []
 
21
 
22
  # -----------------------------------------------------
23
+ # SIMPLE TEXT SPLITTER
24
  # -----------------------------------------------------
25
  def simple_text_splitter(text, chunk_size=600, overlap=100):
26
  chunks = []
 
31
  start += chunk_size - overlap
32
  return chunks
33
 
 
34
  # -----------------------------------------------------
35
  # SAFE LLM CALL
36
  # -----------------------------------------------------
37
  def ask_llm(prompt):
38
  global client
39
  if client is None:
40
+ return "⚠ GROQ API key not set in environment variable."
41
  try:
42
  response = client.chat.completions.create(
43
  model="llama-3.1-8b-instant",
 
98
 
99
  prompt = f"""
100
  Use ONLY the context below to answer.
 
101
  CONTEXT:
102
  {retrieved}
 
103
  QUESTION:
104
  {question}
105
  """