thotnd commited on
Commit
3cdddc1
·
verified ·
1 Parent(s): 4434664

Upload test_azure_openai.py

Browse files
Files changed (1) hide show
  1. test_azure_openai.py +49 -0
test_azure_openai.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Quick test script for Azure OpenAI"""
3
+ import os
4
+ import sys
5
+ from langchain_openai import AzureChatOpenAI
6
+
7
+ # Get environment variables
8
+ api_key = os.getenv("AZURE_OPENAI_API_KEY")
9
+ endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
10
+ api_version = os.getenv("OPENAI_API_VERSION", "2024-12-01-preview")
11
+ model = os.getenv("OPENAI_MODEL", "gpt-4.1")
12
+ temperature = float(os.getenv("AZURE_OPENAI_TEMPERATURE", "0.1"))
13
+ max_tokens = int(os.getenv("AZURE_OPENAI_MAX_TOKENS", "8192"))
14
+ timeout = int(os.getenv("AZURE_OPENAI_TIMEOUT", "600"))
15
+
16
+ if not api_key or not endpoint:
17
+ print("❌ Error: AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT are required")
18
+ sys.exit(1)
19
+
20
+ print("🔍 Testing Azure OpenAI connection...")
21
+ print(f" Endpoint: {endpoint}")
22
+ print(f" Model: {model}")
23
+ print(f" API Version: {api_version}")
24
+
25
+ try:
26
+ llm = AzureChatOpenAI(
27
+ model=model,
28
+ azure_deployment=model,
29
+ api_key=api_key,
30
+ temperature=temperature,
31
+ max_tokens=max_tokens,
32
+ timeout=timeout,
33
+ max_retries=1,
34
+ azure_endpoint=endpoint,
35
+ api_version=api_version
36
+ )
37
+
38
+ print("✅ Client initialized successfully")
39
+ print("📤 Sending test message...")
40
+
41
+ response = llm.invoke([{"role": "user", "content": "Say 'Hello' in one word."}])
42
+
43
+ print(f"✅ Success! Response: {response.content}")
44
+ print("🎉 Azure OpenAI is working correctly!")
45
+
46
+ except Exception as e:
47
+ print(f"❌ Error: {e}")
48
+ sys.exit(1)
49
+