-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (26 loc) · 872 Bytes
/
test.py
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
from openai import OpenAI
from config import MY_OPENAI_API_KEY, MY_IMG_MODEL
def test_openai_api():
# 클라이언트 초기화
client = OpenAI(api_key=MY_OPENAI_API_KEY)
try:
# 간단한 API 요청 보내기
response = client.chat.completions.create(
model=MY_IMG_MODEL,
messages=[
{"role": "user", "content": "Hello, OpenAI!"}
]
)
# 응답 확인
if response.choices[0].message.content:
print("API 테스트 성공!")
print("응답:", response.choices[0].message.content)
return True
else:
print("API 응답이 비어 있습니다.")
return False
except Exception as e:
print(f"오류 발생: {str(e)}")
return False
if __name__ == "__main__":
test_openai_api()