Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -352,26 +352,26 @@ with st.sidebar:
|
|
| 352 |
api_key = st.text_input("Groq API Key", value=hf_api_key, type="password", placeholder="gsk_...", help="Get free key at console.groq.com")
|
| 353 |
|
| 354 |
if api_key:
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
st.session_state.api_configured = True
|
| 364 |
-
st.session_state.groq_client = groq_client
|
| 365 |
-
st.success("✅ API Connected")
|
| 366 |
-
except Exception as e:
|
| 367 |
-
if "invalid_api_key" in str(e).lower() or "401" in str(e):
|
| 368 |
-
st.error("❌ Invalid API key")
|
| 369 |
-
else:
|
| 370 |
-
# Key is valid but other error — still connect
|
| 371 |
st.session_state.api_configured = True
|
| 372 |
-
st.session_state.groq_client =
|
| 373 |
st.success("✅ API Connected")
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
# Mode selection
|
| 377 |
st.markdown('<div class="section-head">Knowledge Source</div>', unsafe_allow_html=True)
|
|
|
|
| 352 |
api_key = st.text_input("Groq API Key", value=hf_api_key, type="password", placeholder="gsk_...", help="Get free key at console.groq.com")
|
| 353 |
|
| 354 |
if api_key:
|
| 355 |
+
try:
|
| 356 |
+
groq_client = Groq(api_key=api_key)
|
| 357 |
+
# Test the connection with a simple call
|
| 358 |
+
test = groq_client.chat.completions.create(
|
| 359 |
+
model="llama-3.1-8b-instant",
|
| 360 |
+
messages=[{"role": "user", "content": "hi"}],
|
| 361 |
+
max_tokens=5
|
| 362 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
st.session_state.api_configured = True
|
| 364 |
+
st.session_state.groq_client = groq_client
|
| 365 |
st.success("✅ API Connected")
|
| 366 |
+
except Exception as e:
|
| 367 |
+
if "invalid_api_key" in str(e).lower() or "401" in str(e):
|
| 368 |
+
st.error("❌ Invalid API key")
|
| 369 |
+
else:
|
| 370 |
+
# Key is valid but other error — still connect
|
| 371 |
+
st.session_state.api_configured = True
|
| 372 |
+
st.session_state.groq_client = Groq(api_key=api_key)
|
| 373 |
+
st.success("✅ API Connected")
|
| 374 |
+
st.session_state.api_configured = False
|
| 375 |
|
| 376 |
# Mode selection
|
| 377 |
st.markdown('<div class="section-head">Knowledge Source</div>', unsafe_allow_html=True)
|