import json
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
def extract_names(text: str) -> list[str]:
system_prompt = "You are a name extractor. The user will give you text, and you must return a JSON array of names mentioned in the text. Do not include any explanation or formatting."
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": text}
]
)
response = response.choices[0].message["content"]
return json.loads(response)