-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_openai.py
More file actions
41 lines (31 loc) · 1.18 KB
/
Copy pathtest_openai.py
File metadata and controls
41 lines (31 loc) · 1.18 KB
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
32
33
34
35
36
37
38
39
40
41
# test_openai.py
import os
from dotenv import load_dotenv
import logging
# Configure detailed logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def test_openai_connection():
"""Test the OpenAI connection with detailed logging"""
try:
# Log environment check
logger.info("Checking environment variables...")
api_key = os.getenv("AZURE_OPENAI_KEY")
logger.info(f"API key present: {bool(api_key)}")
from dashboard.services.openai import AIChatService
logger.info("Creating AIChatService instance...")
service = AIChatService()
test_message = "Hello, what services does this hospital provide?"
logger.info(f"Sending test message: {test_message}")
response = service.get_chat_response(test_message)
logger.info("Response received:")
print("\nAI Response:", response)
except Exception as e:
logger.error(f"Test failed with error: {str(e)}")
raise
if __name__ == "__main__":
load_dotenv()
test_openai_connection()