I have ran the below code and getting correct output without error still I am getting error as script exited with non-zero status code.
import os
import json
from openai import OpenAI
API_KEY = os.environ.get(“OPENAI_API_KEY”)
API_BASE = os.environ.get(“OPENAI_API_BASE”)
client = OpenAI(api_key=API_KEY, base_url=API_BASE)
MODEL = “openai/gpt-4.1-mini”
def generate_press_release(brief_path: str, output_path: str) → str:
“”"
Reads a product brief, asks the model to write an exciting 150-word
press release based on it, and saves the result to output_path.
“”"
with open(brief_path, “r”, encoding=“utf-8”) as f:
brief_content = f.read()
response = client.chat.completions.create(
model=MODEL,
temperature=0.7,
max_tokens=200,
messages=[
{
"role": "system",
"content": (
"You are a PR specialist. Based on this product brief, "
"write an exciting, 150-word professional press release."
),
},
{"role": "user", "content": brief_content},
],
)
press_release_text = response.choices[0].message.content.strip()
with open(output_path, "w", encoding="utf-8") as f:
f.write(press_release_text)
return press_release_text
def analyze_press_release(pr_path: str) → str:
“”"
Reads the generated press release and asks the model, acting as a
skeptical journalist, to return the top 3 toughest questions as a
raw JSON object (no markdown fences, no extra text).
“”"
with open(pr_path, “r”, encoding=“utf-8”) as f:
press_release_content = f.read()
response = client.chat.completions.create(
model=MODEL,
temperature=0.5,
max_tokens=200,
messages=[
{
"role": "system",
"content": (
"You are a cynical, skeptical tech journalist. Read the "
"following press release. Identify the 'Top 3 Toughest "
"Questions' a journalist would ask about this product. "
"Return a JSON object with a single key `tough_questions`, "
"which is a list of strings. Return only the raw JSON "
"object, with no additional text, explanations, or "
"Markdown code fences."
),
},
{"role": "user", "content": press_release_content},
],
)
return response.choices[0].message.content.strip()
if name == “main”:
brief_file = “product_brief.txt”
press_release_file = “press_release.txt”
generate_press_release(brief_file, press_release_file)
final_json = analyze_press_release(press_release_file)
print(final_json)