File size: 833 Bytes
4f8d0ad | 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 | from langchain_openai import OpenAIEmbeddings
from config.settings import Settings
import requests
def test_connection():
"""Test OpenAI API connection"""
print("Testing OpenAI API connection...")
# First test general internet connectivity
try:
response = requests.get("https://api.openai.com")
print(f"OpenAI API reachable: {response.status_code}")
except Exception as e:
print(f"Cannot reach OpenAI API: {e}")
# Test with embeddings
try:
embeddings = OpenAIEmbeddings(
openai_api_key=Settings.OPENAI_API_KEY
)
result = embeddings.embed_query("test")
print(f"Embeddings working! Vector size: {len(result)}")
except Exception as e:
print(f"Embeddings error: {e}")
if __name__ == "__main__":
test_connection() |