Skip to content

Commit fdbcf43

Browse files
committed
fix: handle missing OpenAI API key gracefully
1 parent 224711c commit fdbcf43

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

backend/job_matcher.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
from typing import List, Dict
44
import json
55

6-
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
6+
# Initialize OpenAI client only if API key is available
7+
client = None
8+
if os.getenv("OPENAI_API_KEY"):
9+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
710

811
def find_matching_jobs(coaching_summary: Dict, num_jobs: int = 5) -> List[Dict]:
912
"""
1013
Use OpenAI to find matching jobs based on the career coaching summary.
1114
Returns a list of job matches with titles, descriptions, and match reasons.
1215
"""
16+
if not client:
17+
print("OpenAI client not initialized - API key not found")
18+
return []
19+
1320
system_prompt = """You are a job matching expert. Your task is to find relevant job opportunities
1421
based on the candidate's career coaching summary. For each job, provide:
1522
1. A realistic job title

0 commit comments

Comments
 (0)