Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 835 Bytes
970eef1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import os
from openai import OpenAI
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def test_openai_connection():
try:
# Initialize OpenAI client
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
# Make a simple request
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Say 'Hello World'"}
]
)
print("✅ OpenAI API connection successful!")
print(f"Response: {response.choices[0].message.content}")
return True
except Exception as e:
print("❌ OpenAI API connection failed!")
print(f"Error: {str(e)}")
return False
if __name__ == "__main__":
test_openai_connection() |