demo / backend /tests /test_openai.py
tfrere's picture
first commit
970eef1
raw
history blame
835 Bytes
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()