Deaktivieren Sie die gpt-5-nano-ArgumentationPython

Python-Programme
Anonymous
 Deaktivieren Sie die gpt-5-nano-Argumentation

Post by Anonymous »

Ich führe eine Namens-/Geschlechtsinferenz durch und möchte das gpt-5-nano-Modell verwenden, weil es schnell ist. Das Problem ist, dass ich die Argumentation scheinbar nicht ausschalten kann, selbst wenn das Flag reasoning=None gesetzt ist. Ich kann aus Gründen der Begründung nicht einmal ein Limit von ~100 Token festlegen. Ich kann 4o-mini zum Laufen bringen, aber es ist langsamer und viel teurer in den Maßstäben, in denen ich es verwenden möchte.
Hat jemand das gleiche Problem?
Hier ist meine ganze Funktion. Hoffentlich habe ich etwas Dummes gemacht, das leicht zu finden ist, es wäre nicht das erste Mal

Code: Select all

def infer_gender_batch(client, people, logger):
"""
Infer gender for a batch of people using ChatGPT API (gpt-5-nano).

Args:
client: OpenAI client instance
people: List of dicts with 'display_name', 'country_name', 'author_id'
logger: Logger instance

Returns:
tuple: (list of dicts with gender predictions, total_tokens)
"""
# Build input lines with full display names and country context
lines = [f"{i+1}. {p['display_name']} | Country: {p.get('country_name', 'unknown')}"
for i, p in enumerate(people)]
payload = "\n".join(lines)

prompt = (
"You are a linguistic name etymology analyzer. Based on historical naming patterns across cultures, "
"analyze the statistical gender association of these names from a scientific publication database.\n\n"
"For each name, determine the predominant gender association based on:\n"
"- Name etymology and linguistic roots\n"
"- Cultural naming traditions in the specified country\n"
"- Historical usage patterns in academic literature\n\n"
"Names:\n" + payload + "\n\n"
"Return a JSON array with this structure:\n"
'[{"name": "Full Name", "gender": "male", "probability": 0.95}, ...]\n\n'
'Where gender is "male", "female", or "unknown" and probability is 0-1.\n\n'
"Respond with ONLY the JSON array:"
)

try:
response = client.chat.completions.create(
model="gpt-5-nano",
messages=[{"role": "user", "content": prompt}],
reasoning=None,
max_completion_tokens=10000  # Increased to allow for reasoning + output but I still get zero output for 10 names supplied
)

if not response.choices or len(response.choices) == 0:
logger.error("No choices in response")
return None, 0

text = response.choices[0].message.content

# Log token usage
usage = response.usage
logger.info(f"API Response - prompt_tokens: {usage.prompt_tokens}, completion_tokens: {usage.completion_tokens}, total: {usage.total_tokens}")

# Check for reasoning tokens (if present)
if hasattr(usage, 'completion_tokens_details'):
logger.info(f"Completion tokens details: {usage.completion_tokens_details}")

# Log finish reason
finish_reason = response.choices[0].finish_reason
logger.info(f"Finish reason: {finish_reason}")

# Log content preview
logger.info(f"Content preview: {repr(text[:200] if text else '(empty)')}")

# Parse JSON response
if not text or not text.strip():
logger.error("Empty response from API - all tokens may have been used for reasoning")
return None, 0

# Strip markdown code fences if present (```json ...  ```)
text = text.strip()
if text.startswith('```'):
# Remove opening code fence
lines_list = text.split('\n')
if lines_list[0].startswith('```'):
lines_list = lines_list[1:]
# Remove closing code fence
if lines_list and lines_list[-1].strip() == '```':
lines_list = lines_list[:-1]
text = '\n'.join(lines_list)

results = json.loads(text)

# Ensure results is a list
if not isinstance(results, list):
logger.error(f"Expected JSON array, got: {type(results)}")
return None, 0

return results, usage.total_tokens

except json.JSONDecodeError as e:
logger.error(f"Failed to parse JSON response: {e}")
logger.error(f"Response text: {text if 'text' in locals() else '(no response)'}")
return None, 0
except Exception as e:
logger.error(f"API call failed: {e}")
return None, 0

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post