ReizenO8 commited on
Commit
9598e3b
·
verified ·
1 Parent(s): d79dcaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
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
- 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)
 
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)