Skip to content

Extract catalog, harden AI recommend API with strict matching and local fallback#6

Merged
FenjuFu merged 1 commit into
mainfrom
codex/fix-bug-and-troubleshoot-issues
Mar 6, 2026
Merged

Extract catalog, harden AI recommend API with strict matching and local fallback#6
FenjuFu merged 1 commit into
mainfrom
codex/fix-bug-and-troubleshoot-issues

Conversation

@FenjuFu
Copy link
Copy Markdown
Owner

@FenjuFu FenjuFu commented Mar 6, 2026

Motivation

  • Centralize the static candidate data and reuse the same catalog across UI and API to avoid duplication and accidental divergence.
  • Prevent the AI model from inventing restaurants by strictly constraining model output to the local candidate set and provide robust local fallbacks when the AI fails.
  • Improve client UX by showing local recommendations and clearer error messaging when the AI service is unavailable.
  • Avoid inadvertently disabling API routes during normal builds by making static export opt-in via STATIC_EXPORT.

Description

  • Add lib/bitesCatalog.ts which exports BITES_CATALOG, types BitesRestaurant and AccessibilityFilter, and a reusable filterBitesCatalog function for filtering by location and accessibility.
  • Update app/api/ai/recommend/route.ts to use the new catalog/types, parse request body safely, call the chat model, strictly enforce matching model recommendations to the local catalog via enforceCatalog, and return a local fallback (filterBitesCatalog) when parsing/modeling fails or returns no matches.
  • Improve JSON parsing resilience with safeParseJson and stronger typing for model responses (ModelRecommendation) and request body (RecommendRequestBody).
  • Update components/FoodAIDialog.tsx to import filterBitesCatalog, handle AI fallback on the client by showing local recommendations and a friendly error message, and display the raw error message when appropriate.
  • Make next.config.ts only enable static output: 'export' when STATIC_EXPORT=true to avoid disabling API routes by default.

Testing

  • Ran TypeScript type checking and a Next.js dev build locally, and both completed successfully.
  • Exercised the AI recommend API endpoint with valid and malformed request bodies to verify fallbacks, and verified client dialog shows local recommendations when AI response is empty or the request fails; these checks succeeded.
  • No changes to existing automated unit test suites were required and no new unit tests were added in this PR.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
good-action-hub Ready Ready Preview, Comment Mar 6, 2026 1:12pm

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 6, 2026

Deploy Preview for goodaction-hub ready!

Name Link
🔨 Latest commit 469343a
🔍 Latest deploy log https://app.netlify.com/projects/goodaction-hub/deploys/69aad29326d52000085418e6
😎 Deploy Preview https://deploy-preview-6--goodaction-hub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@FenjuFu FenjuFu merged commit 1a3cbc7 into main Mar 6, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant