Spaces:
Sleeping
Sleeping
Download tests/test_openai_mini.py from UWRFR/UWaterlooRFRChatBot: direct link, hf CLI and curl.
- Browser
- Download file 871 Bytes
-
https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/tests/test_openai_mini.py
- Command line
-
hf download hf://spaces/UWRFR/UWaterlooRFRChatBot/tests/test_openai_mini.py
-
curl -L -o test_openai_mini.py https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/tests/test_openai_mini.py
871 Bytes
| """Quick smoke test for OpenAI gpt-4o-mini API call.""" | |
| import os | |
| from openai import OpenAI | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def test_basic_completion(): | |
| client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) | |
| response = client.chat.completions.create( | |
| model="gpt-4o-mini", | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": "Say 'API connection successful' and nothing else."}, | |
| ], | |
| max_tokens=20, | |
| ) | |
| reply = response.choices[0].message.content.strip() | |
| print(f"Response: {reply}") | |
| print(f"Model: {response.model}") | |
| print(f"Tokens used: {response.usage.total_tokens}") | |
| assert "successful" in reply.lower(), f"Unexpected response: {reply}" | |
| print("Test passed.") | |
| if __name__ == "__main__": | |
| test_basic_completion() | |