[PR #842] [CLOSED] fix: guard against empty choices and None content in memory tutorial apps #11397

Closed
opened 2026-06-16 06:34:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: mainHead: fix/guard-openai-choices-access-memory-tutorials


📝 Commits (1)

  • 23e8bd2 fix: guard against empty choices and None content in memory tutorial apps

📊 Changes

4 files changed (+10 additions, -0 deletions)

View changed files

📝 advanced_llm_apps/llm_apps_with_memory_tutorials/ai_arxiv_agent_memory/ai_arxiv_agent_memory.py (+2 -0)
📝 advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py (+2 -0)
📝 advanced_llm_apps/llm_apps_with_memory_tutorials/llm_app_personalized_memory/llm_app_memory.py (+2 -0)
📝 advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py (+4 -0)

📄 Description

Summary

Fixes #841

Four apps in llm_apps_with_memory_tutorials accessed response.choices[0].message.content without verifying that choices is non-empty and content is not None. This is the same class of bug fixed in PR #820 (DeepSeek) and PR #840 (beifong).

Affected files:

  • ai_arxiv_agent_memory/ai_arxiv_agent_memory.py — arXiv paper search with GPT-4o-mini
  • ai_travel_agent_memory/travel_agent_memory.py — travel agent with OpenAI
  • llm_app_personalized_memory/llm_app_memory.py — personalized memory app
  • multi_llm_memory/multi_llm_memory.py — multi-LLM app (OpenAI GPT-4o and Claude Sonnet)

Root cause: An empty choices list or None content can occur when a content filter is triggered, a quota is exceeded, or a transient API error occurs.

Fix: Add an explicit guard before each choices[0] access in all four files. The ValueError propagates cleanly to any surrounding error handling.

Test plan

  • Normal API responses continue to work correctly
  • ValueError is raised 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/842 **Author:** [@zavoryn](https://github.com/zavoryn) **Created:** 5/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/guard-openai-choices-access-memory-tutorials` --- ### 📝 Commits (1) - [`23e8bd2`](https://github.com/Shubhamsaboo/awesome-llm-apps/commit/23e8bd25a15cd08eb82f6df714f6b2d8edc6d55c) fix: guard against empty choices and None content in memory tutorial apps ### 📊 Changes **4 files changed** (+10 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/ai_arxiv_agent_memory/ai_arxiv_agent_memory.py` (+2 -0) 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py` (+2 -0) 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/llm_app_personalized_memory/llm_app_memory.py` (+2 -0) 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py` (+4 -0) </details> ### 📄 Description ## Summary Fixes #841 Four apps in `llm_apps_with_memory_tutorials` accessed `response.choices[0].message.content` without verifying that `choices` is non-empty and `content` is not `None`. This is the same class of bug fixed in PR #820 (DeepSeek) and PR #840 (beifong). **Affected files:** - `ai_arxiv_agent_memory/ai_arxiv_agent_memory.py` — arXiv paper search with GPT-4o-mini - `ai_travel_agent_memory/travel_agent_memory.py` — travel agent with OpenAI - `llm_app_personalized_memory/llm_app_memory.py` — personalized memory app - `multi_llm_memory/multi_llm_memory.py` — multi-LLM app (OpenAI GPT-4o and Claude Sonnet) **Root cause:** An empty `choices` list or `None` content can occur when a content filter is triggered, a quota is exceeded, or a transient API error occurs. **Fix:** Add an explicit guard before each `choices[0]` access in all four files. The `ValueError` propagates cleanly to any surrounding error handling. ## Test plan - [ ] Normal API responses continue to work correctly - [ ] `ValueError` is raised 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-06-16 06:34:29 -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#11397