Skip to content

ai: Pre-append prompt templates and establish init barrier for Writing Assistance APIs - #62337

Draft
chromium-wpt-export-bot wants to merge 1 commit into
masterfrom
chromium-export-cl-8255743
Draft

ai: Pre-append prompt templates and establish init barrier for Writing Assistance APIs#62337
chromium-wpt-export-bot wants to merge 1 commit into
masterfrom
chromium-export-cl-8255743

Conversation

@chromium-wpt-export-bot

Copy link
Copy Markdown
Collaborator

Pre-append static options and shared context (the system prompt
template) to the on-device session during creation for AISummarizer,
AIWriter, and AIRewriter via OnDeviceSession::SetInput.

Per-request dynamic execution fields (article, instructions,
rewrite_text, and per-request context) are marked as pending on the
initial MultimodalMessage so that template substitution halts at the
static prefix without evaluating empty execution strings or generating
premature control tokens.

This change accomplishes two objectives:

  • crbug.com/540980352: Blocks create() promise resolution until the underlying On-Device Model Service (ODMS) has fully initialized the engine and model weights, eliminating the cold-start penalty currently incurred during the first summarize()/write()/rewrite() call.
  • crbug.com/390006887: Pre-populates and caches the static prompt options and shared context in the session KV cache during session creation, avoiding redundant re-tokenization on every execution call.

Automated tests:

  • Add prompt verification tests across AIWriter, AIRewriter, and
    AISummarizer unit tests to check substituted prompt strings.
  • Add multi-execution session reuse tests to verify shared context
    caching across sequential requests.
  • Add unit test for MultimodalMessage::Merge pending overlay clearance.

Bug: 390006887, 540980352
Change-Id: I199e35e62e6f084f490965a7d8bb7eafda27393c
Reviewed-on: https://chromium-review.googlesource.com/8255743
WPT-Export-Revision: c7515ce5c4491f496cae3140b00af7c68002a01e

…g Assistance APIs

Pre-append static options and shared context (the system prompt
template) to the on-device session during creation for AISummarizer,
AIWriter, and AIRewriter via OnDeviceSession::SetInput.

Per-request dynamic execution fields (article, instructions,
rewrite_text, and per-request context) are marked as pending on the
initial MultimodalMessage so that template substitution halts at the
static prefix without evaluating empty execution strings or generating
premature control tokens.

This change accomplishes two objectives:
- crbug.com/540980352: Blocks create() promise resolution until the underlying On-Device Model Service (ODMS) has fully initialized the engine and model weights, eliminating the cold-start penalty currently incurred during the first summarize()/write()/rewrite() call.
- crbug.com/390006887: Pre-populates and caches the static prompt options and shared context in the session KV cache during session creation, avoiding redundant re-tokenization on every execution call.

Automated tests:
- Add prompt verification tests across AIWriter, AIRewriter, and
  AISummarizer unit tests to check substituted prompt strings.
- Add multi-execution session reuse tests to verify shared context
  caching across sequential requests.
- Add unit test for MultimodalMessage::Merge pending overlay clearance.

Bug: 390006887, 540980352
Change-Id: I199e35e62e6f084f490965a7d8bb7eafda27393c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant