Spaces:
Build error
Build error
Download utils/api_utils.py from atoye1/busan_data_navigator: direct link, hf CLI and curl.
- Browser
- Download file 569 Bytes
-
https://huggingface.co/spaces/atoye1/busan_data_navigator/resolve/main/utils/api_utils.py
- Command line
-
hf download hf://spaces/atoye1/busan_data_navigator/utils/api_utils.py
-
curl -L -o api_utils.py https://huggingface.co/spaces/atoye1/busan_data_navigator/resolve/main/utils/api_utils.py
569 Bytes
| import openai | |
| import os | |
| def check_openai_api_key(): | |
| try: | |
| openai.api_key = os.get_env("OPENAI_API_KEY") | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": "Hello, OpenAI!"} | |
| ] | |
| ) | |
| print(response) | |
| if response and "choices" in response: | |
| return True | |
| else: | |
| return False | |
| except Exception as e: | |
| return False |