Spaces:
Sleeping
Sleeping
Download llm_check.py from rachelmkim/study-interface: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/spaces/rachelmkim/study-interface/resolve/main/llm_check.py
- Command line
-
hf download hf://spaces/rachelmkim/study-interface/llm_check.py
-
curl -L -o llm_check.py https://huggingface.co/spaces/rachelmkim/study-interface/resolve/main/llm_check.py
943 Bytes
| import yaml | |
| import openai | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def main(): | |
| with open("config.yaml", "r") as f: | |
| data = yaml.safe_load(f) | |
| models = data['models'] | |
| for i, model in enumerate(models): | |
| try: | |
| client = openai.OpenAI( | |
| base_url="https://openrouter.ai/api/v1", | |
| api_key=os.getenv("OPENROUTER_API_KEY") | |
| ) | |
| response = client.chat.completions.create( | |
| model=model, | |
| messages=[{"role": "user", "content": "Hi"}], | |
| timeout=60, | |
| max_tokens=20 | |
| ) | |
| except openai.APITimeoutError: | |
| print(f"Error: Request timed out after 60 seconds") | |
| continue | |
| except Exception as e: | |
| print(f"{model} Error: {str(e)}") | |
| continue | |
| print(f"{i} Success: {model}") | |
| if __name__ == '__main__': | |
| main() |