-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_setup.py
More file actions
48 lines (37 loc) · 1.01 KB
/
1_setup.py
File metadata and controls
48 lines (37 loc) · 1.01 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
43
44
45
46
47
48
# Add comprehensive error handling
import logging
import sys
from functools import wraps
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def handle_errors(func):
"""Decorator for error handling"""
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
logger.error(f"Error in {func.__name__}: {e}")
raise
return wrapper
import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
openai_client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY")
)
def main():
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)
if __name__ == "__main__":
main()