Skip to content

fix(api): expose match_materials_to_script in /terms endpoint - #1065

Merged
harry0703 merged 1 commit into
harry0703:mainfrom
kapil971390:fix/terms-api-missing-match-script-order
Jun 23, 2026
Merged

harry0703 merged 1 commit into
harry0703:mainfrom
kapil971390:fix/terms-api-missing-match-script-order

Conversation

@kapil971390

Copy link
Copy Markdown
Contributor

What's the bug

Commit 552f056 added match_materials_to_script to VideoParams and correctly wired it through task.py → material.py. But VideoTermsParams was not updated, and the /terms controller still calls generate_terms() without match_script_order.

Result: calling POST /api/v1/llm/terms with "match_materials_to_script": true silently ignores the flag — generate_terms() always uses the relevance-ordered prompt, never the chronological one.

Root cause

# app/controllers/v1/llm.py — match_script_order never passed
video_terms = llm.generate_terms(
    video_subject=body.video_subject,
    video_script=body.video_script,
    amount=body.amount,
    # match_script_order missing ← always defaults to False
)

VideoTermsParams also has no match_materials_to_script field, so the body field is dropped at parse time even if a caller sends it.

Fix

Two changes:

  1. app/models/schema.py — add match_materials_to_script: bool = False to VideoTermsParams
  2. app/controllers/v1/llm.py — pass match_script_order=body.match_materials_to_script to generate_terms()

Default is False, so existing callers are completely unaffected.

How I found it

I was doing a commit-by-commit review of recent changes using a static analysis tool I built for catching inter-module gaps like this — where a new field added to one schema doesn't get propagated to sibling schemas. The tool flagged that VideoTermsParams was not updated alongside VideoParams in 552f056. I then manually traced the call path (VideoTermsRequest → controller → generate_terms()) to confirm the flag was silently dropped end-to-end.

(Happy to share more about the tool if you're curious.)

Test

# Before fix: flag ignored, relevance-ordered terms always returned
curl -X POST /api/v1/llm/terms \
  -d '{"video_subject":"春天","video_script":"...","amount":5,"match_materials_to_script":true}'

# After fix: generate_terms() receives match_script_order=True,
# uses the chronological prompt and returns script-ordered terms

feat commit 552f056 added match_materials_to_script to VideoParams and
wired it through task.py, but VideoTermsParams was not updated and the
/terms controller still calls generate_terms() without match_script_order.

As a result the /terms REST endpoint always generates relevance-ordered
terms, even when callers set match_materials_to_script=true, and the
chronological prompt branch in generate_terms() is never reachable
through the API.

Add match_materials_to_script: bool = False to VideoTermsParams and
pass it as match_script_order to generate_terms() in the controller.
Default is False so existing callers are unaffected.
@harry0703
harry0703 merged commit f2e6d80 into harry0703:main Jun 23, 2026
1 check passed
@harry0703

Copy link
Copy Markdown
Owner

Thank you for catching this gap and for the clear explanation.

I verified the API path locally with a small FastAPI smoke test: when match_materials_to_script is set to true on POST /api/v1/terms, the controller now passes match_script_order=True into generate_terms(). I also ran the LLM service test suite successfully.

This has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants