Spaces:
Sleeping
Sleeping
Commit
·
29f09ab
1
Parent(s):
35926c3
Add better error handling for missing API key
Browse files
app.py
CHANGED
@@ -23,8 +23,19 @@ logger = logging.getLogger(__name__)
|
|
23 |
load_dotenv()
|
24 |
|
25 |
# Initialize OpenAI client for Perplexity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
client = OpenAI(
|
27 |
-
api_key=
|
28 |
base_url="https://api.perplexity.ai"
|
29 |
)
|
30 |
|
|
|
23 |
load_dotenv()
|
24 |
|
25 |
# Initialize OpenAI client for Perplexity
|
26 |
+
api_key = os.getenv('PERPLEXITY_API_KEY')
|
27 |
+
if not api_key:
|
28 |
+
st.error("""
|
29 |
+
⚠️ Perplexity API key not found! Please add your API key to the Space's secrets:
|
30 |
+
1. Go to Space Settings
|
31 |
+
2. Click on 'Repository secrets'
|
32 |
+
3. Add a new secret with name 'PERPLEXITY_API_KEY'
|
33 |
+
4. Add your Perplexity API key as the value
|
34 |
+
""")
|
35 |
+
st.stop()
|
36 |
+
|
37 |
client = OpenAI(
|
38 |
+
api_key=api_key,
|
39 |
base_url="https://api.perplexity.ai"
|
40 |
)
|
41 |
|