Spaces:
Sleeping
Sleeping
Download utils/util.py from zhtet/RegBotBeta: direct link, hf CLI and curl.
- Browser
- Download file 674 Bytes
-
https://huggingface.co/spaces/zhtet/RegBotBeta/resolve/refs%2Fpr%2F1/utils/util.py
- Command line
-
hf download hf://spaces/zhtet/RegBotBeta@refs/pr/1/utils/util.py
-
curl -L -o util.py https://huggingface.co/spaces/zhtet/RegBotBeta/resolve/refs%2Fpr%2F1/utils/util.py
674 Bytes
| import requests | |
| from typing import Dict | |
| def validate_openai_api_key(token: str) -> Dict[str, str]: | |
| api_endpoint = "https://api.openai.com/v1/chat/completions" | |
| api_key = token | |
| headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"} | |
| messages = [{"role": "user", "content": "Say this is a test!"}] | |
| data = {"model": "gpt-3.5-turbo", "messages": messages} | |
| response = requests.post(api_endpoint, json=data, headers=headers) | |
| if response.status_code == 200: | |
| return {"status": "success", "message": "API key is valid"} | |
| else: | |
| return {"status": "error", "message": response.json()["error"]["message"]} | |