Я выполняю вывод имени/пола и хочу использовать модель gpt-5-nano, потому что она быстрая. Проблема в том, что я не могу отключить рассуждение даже с флагом Reasoning=None. Кажется, я даже не могу установить лимит в ~100 токенов для рассуждений. Я могу заставить работать 4o-mini, но он медленнее и намного дороже в тех масштабах, в которых я хочу его использовать.
У кого-нибудь есть такая же проблема?
Вот вся моя функция, надеюсь, я сделал что-то глупое, что легко найти, это будет не в первый раз
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
Подробнее здесь: https://stackoverflow.com/questions/798 ... -reasoning
Отключите рассуждение gpt-5-nano ⇐ Python
Программы на Python
1764835869
Anonymous
Я выполняю вывод имени/пола и хочу использовать модель gpt-5-nano, потому что она быстрая. Проблема в том, что я не могу отключить рассуждение даже с флагом Reasoning=None. Кажется, я даже не могу установить лимит в ~100 токенов для рассуждений. Я могу заставить работать 4o-mini, но он медленнее и намного дороже в тех масштабах, в которых я хочу его использовать.
У кого-нибудь есть такая же проблема?
Вот вся моя функция, надеюсь, я сделал что-то глупое, что легко найти, это будет не в первый раз
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
Подробнее здесь: [url]https://stackoverflow.com/questions/79837650/turn-off-gpt-5-nano-reasoning[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия