Update app.py
Browse files
app.py
CHANGED
|
@@ -44,16 +44,14 @@ def create_embeddings_and_store(chunks):
|
|
| 44 |
st.error(f"Error creating embeddings: {e}")
|
| 45 |
return None
|
| 46 |
|
| 47 |
-
# Groq interaction (with more robust error handling)
|
| 48 |
def query_groq(query, db):
|
| 49 |
try:
|
|
|
|
| 50 |
docs = db.similarity_search(query) # Similarity search
|
| 51 |
context = "\n".join([doc.page_content for doc in docs])
|
| 52 |
|
| 53 |
-
client = Groq(api_key=
|
| 54 |
-
if not client.api_key: # Check if API key is set
|
| 55 |
-
st.error("GROQ_API_KEY environment variable is not set. Set it as a Space secret.")
|
| 56 |
-
return None
|
| 57 |
|
| 58 |
prompt = f"""Use the following context to answer the question: {query}\n\nContext:\n{context}"""
|
| 59 |
|
|
|
|
| 44 |
st.error(f"Error creating embeddings: {e}")
|
| 45 |
return None
|
| 46 |
|
| 47 |
+
# Groq interaction (with more robust error handling and correct secret access)
|
| 48 |
def query_groq(query, db):
|
| 49 |
try:
|
| 50 |
+
groq_api_key = st.secrets["GROQ_API_KEY"] # Use st.secrets for Hugging Face secrets
|
| 51 |
docs = db.similarity_search(query) # Similarity search
|
| 52 |
context = "\n".join([doc.page_content for doc in docs])
|
| 53 |
|
| 54 |
+
client = Groq(api_key=groq_api_key) # Pass the secret to the client
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
prompt = f"""Use the following context to answer the question: {query}\n\nContext:\n{context}"""
|
| 57 |
|