[PR #840] [CLOSED] fix: guard against empty choices and None content in beifong OpenAI API responses #7055

Closed
opened 2026-05-31 14:45:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Shubhamsaboo/awesome-llm-apps/pull/840
Author: @zavoryn
Created: 5/25/2026
Status: Closed

Base: mainHead: fix/guard-openai-choices-access-beifong


📝 Commits (1)

  • 49c683c fix: guard against empty choices and None content in beifong OpenAI API responses

📊 Changes

3 files changed (+6 additions, -0 deletions)

View changed files

📝 advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/processors/ai_analysis_processor.py (+2 -0)
📝 advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/utils/get_articles.py (+2 -0)
📝 advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/utils/translate_podcast.py (+2 -0)

📄 Description

Summary

Fixes #839

Three utilities in the beifong news/podcast multi-agent app accessed response.choices[0].message.content without first verifying that choices is non-empty and content is not None. This mirrors the same class of bug fixed in PR #820 for DeepSeek API responses.

Affected files:

  • processors/ai_analysis_processor.py — article analysis with GPT-4o
  • utils/translate_podcast.py — podcast translation with GPT-4o
  • utils/get_articles.py — search term extraction with GPT-4o-mini

Root cause: OpenAI can return an empty choices list or None content when a content filter is triggered, a quota is exceeded, or a transient API error occurs. Without a guard, this crashes with IndexError or passes None to json.loads().

Fix: Add an explicit guard before accessing choices[0].message.content in all three files, raising a descriptive ValueError that propagates cleanly to the surrounding except block already present in each function.

Test plan

  • Verify normal API responses still parse correctly
  • Verify the ValueError is raised (and caught by the outer except Exception) when choices is empty or content is None

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Shubhamsaboo/awesome-llm-apps/pull/840 **Author:** [@zavoryn](https://github.com/zavoryn) **Created:** 5/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/guard-openai-choices-access-beifong` --- ### 📝 Commits (1) - [`49c683c`](https://github.com/Shubhamsaboo/awesome-llm-apps/commit/49c683c2a66bf461529499d7c4a610326d67d416) fix: guard against empty choices and None content in beifong OpenAI API responses ### 📊 Changes **3 files changed** (+6 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/processors/ai_analysis_processor.py` (+2 -0) 📝 `advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/utils/get_articles.py` (+2 -0) 📝 `advanced_ai_agents/multi_agent_apps/ai_news_and_podcast_agents/beifong/utils/translate_podcast.py` (+2 -0) </details> ### 📄 Description ## Summary Fixes #839 Three utilities in the `beifong` news/podcast multi-agent app accessed `response.choices[0].message.content` without first verifying that `choices` is non-empty and `content` is not `None`. This mirrors the same class of bug fixed in PR #820 for DeepSeek API responses. **Affected files:** - `processors/ai_analysis_processor.py` — article analysis with GPT-4o - `utils/translate_podcast.py` — podcast translation with GPT-4o - `utils/get_articles.py` — search term extraction with GPT-4o-mini **Root cause:** OpenAI can return an empty `choices` list or `None` content when a content filter is triggered, a quota is exceeded, or a transient API error occurs. Without a guard, this crashes with `IndexError` or passes `None` to `json.loads()`. **Fix:** Add an explicit guard before accessing `choices[0].message.content` in all three files, raising a descriptive `ValueError` that propagates cleanly to the surrounding `except` block already present in each function. ## Test plan - [ ] Verify normal API responses still parse correctly - [ ] Verify the `ValueError` is raised (and caught by the outer `except Exception`) when `choices` is empty or `content` is `None` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-31 14:45:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-llm-apps#7055