-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_openai_simple.py
More file actions
42 lines (34 loc) · 1.1 KB
/
Copy pathtest_openai_simple.py
File metadata and controls
42 lines (34 loc) · 1.1 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
42
#!/usr/bin/env python3
"""
Simple test to demonstrate OpenAI usage
"""
import sys
import os
try:
# Import directly (PYTHONPATH should include /app)
from openai_client import get_openai_client
print("=== OpenAI Test ===")
print("")
# Initialize client
print("Initializing OpenAI client...")
client = get_openai_client()
print("✓ Client initialized")
print("")
# Simple chat completion
print("Sending a simple message...")
messages = [
{"role": "system", "content": "You are a helpful assistant. Keep responses brief."},
{"role": "user", "content": "Say hello in one sentence."}
]
response = client.chat_completion(messages, max_tokens=50)
print(f"Response: {response['content']}")
print(f"Tokens used: {response['usage']['total_tokens']}")
print("")
print("✓ OpenAI is working correctly!")
except ImportError as e:
print(f"Error importing: {e}")
print("Make sure the container is rebuilt with OpenAI installed")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)