Update app.py
Browse files
app.py
CHANGED
@@ -71,26 +71,24 @@ def initialize_api_keys():
|
|
71 |
initialize_api_keys()
|
72 |
|
73 |
|
74 |
-
def is_openai_api_key_valid(
|
75 |
"""
|
76 |
-
|
77 |
"""
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
}
|
82 |
-
response = requests.get(
|
83 |
-
"https://api.openai.com/v1/models", headers=headers
|
84 |
-
)
|
85 |
-
|
86 |
return response.status_code == 200
|
87 |
|
88 |
|
89 |
-
|
|
|
90 |
"""
|
91 |
-
|
92 |
"""
|
93 |
-
|
94 |
if not bing_subscription_key:
|
95 |
return False
|
96 |
try:
|
@@ -99,11 +97,11 @@ def is_bing_subscription_key_valid(bing_subscription_key: str) -> bool:
|
|
99 |
bing_search_url="https://api.bing.microsoft.com/v7.0/search",
|
100 |
k=1
|
101 |
)
|
102 |
-
bing_search.run("
|
103 |
-
except:
|
104 |
return False
|
105 |
-
|
106 |
-
|
107 |
|
108 |
|
109 |
def check_api_keys() -> None:
|
|
|
71 |
initialize_api_keys()
|
72 |
|
73 |
|
74 |
+
def is_openai_api_key_valid():
|
75 |
"""
|
76 |
+
Validate the OpenAI API key from Hugging Face secrets.
|
77 |
"""
|
78 |
+
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
79 |
+
if not openai_api_key:
|
80 |
+
return False
|
81 |
+
headers = {"Authorization": f"Bearer {openai_api_key}"}
|
82 |
+
response = requests.get("https://api.openai.com/v1/models", headers=headers)
|
|
|
|
|
|
|
83 |
return response.status_code == 200
|
84 |
|
85 |
|
86 |
+
|
87 |
+
def is_bing_subscription_key_valid():
|
88 |
"""
|
89 |
+
Validate the Bing Subscription key from Hugging Face secrets.
|
90 |
"""
|
91 |
+
bing_subscription_key = os.environ.get("BING_SUBSCRIPTION_KEY")
|
92 |
if not bing_subscription_key:
|
93 |
return False
|
94 |
try:
|
|
|
97 |
bing_search_url="https://api.bing.microsoft.com/v7.0/search",
|
98 |
k=1
|
99 |
)
|
100 |
+
bing_search.run("Test Query")
|
101 |
+
except Exception:
|
102 |
return False
|
103 |
+
return True
|
104 |
+
|
105 |
|
106 |
|
107 |
def check_api_keys() -> None:
|