Don Rishabh Claude Opus 4.7 (1M context) commited on
Commit
da41c85
·
1 Parent(s): e8bf76c

demo(new-tab): expose the raw chat-templated string sent to target

Browse files

Adds a collapsible accordion under the new-task tab showing the exact
text the Llama target sees for both the verbose and the trained-agent
prompt — i.e. what apply_chat_template() returns with the prompt as
system and the test input as user. Lets users copy-paste the literal
API call.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. space-demo/app.py +36 -2
space-demo/app.py CHANGED
@@ -491,6 +491,13 @@ def compress_and_run(description: str, budget_str: str, test_input: str):
491
  trained_tok = count_tokens(trained_prompt)
492
  verbose_tok = count_tokens(description)
493
 
 
 
 
 
 
 
 
494
  if test_input:
495
  # One batched forward pass with both prompts.
496
  outs = run_target_batch([description, trained_prompt], test_input)
@@ -506,7 +513,8 @@ def compress_and_run(description: str, budget_str: str, test_input: str):
506
  f"verbose: {verbose_tok} tok → trained: {trained_tok} tok")
507
 
508
  return (trained_prompt, str(trained_tok), str(verbose_tok),
509
- verbose_output, trained_output, msg)
 
510
 
511
 
512
  # ---------------------------------------------------------------------------
@@ -668,6 +676,30 @@ def build_app() -> gr.Blocks:
668
  )
669
  custom_status = gr.Textbox(label="status", interactive=False)
670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  gr.Markdown(
672
  "---\n"
673
  "**About**: this is the demo artifact for "
@@ -703,7 +735,9 @@ def build_app() -> gr.Blocks:
703
  compress_and_run,
704
  inputs=[custom_desc, custom_budget, custom_input],
705
  outputs=[custom_prompt_out, custom_tok, custom_verbose_tok,
706
- custom_verbose_out, custom_target_out, custom_status],
 
 
707
  )
708
  app.load(select_task, inputs=[task_dd], outputs=select_outputs)
709
 
 
491
  trained_tok = count_tokens(trained_prompt)
492
  verbose_tok = count_tokens(description)
493
 
494
+ # Build the exact chat-templated strings the target actually sees,
495
+ # so the user can read what we send to Llama. Empty test_input
496
+ # still produces a valid string (just an empty user turn).
497
+ load_target()
498
+ verbose_chat = _build_target_chat(description, test_input or "")
499
+ trained_chat = _build_target_chat(trained_prompt, test_input or "")
500
+
501
  if test_input:
502
  # One batched forward pass with both prompts.
503
  outs = run_target_batch([description, trained_prompt], test_input)
 
513
  f"verbose: {verbose_tok} tok → trained: {trained_tok} tok")
514
 
515
  return (trained_prompt, str(trained_tok), str(verbose_tok),
516
+ verbose_output, trained_output,
517
+ verbose_chat, trained_chat, msg)
518
 
519
 
520
  # ---------------------------------------------------------------------------
 
676
  )
677
  custom_status = gr.Textbox(label="status", interactive=False)
678
 
679
+ with gr.Accordion(
680
+ "🔍 Exact chat-templated string sent to the target "
681
+ "(the full Llama API call)",
682
+ open=False,
683
+ ):
684
+ gr.Markdown(
685
+ "Each prompt becomes a `system` message and the "
686
+ "test input a `user` message; we apply the target "
687
+ "tokenizer's chat template (`apply_chat_template`) "
688
+ "with `add_generation_prompt=True`. Below is the "
689
+ "exact text fed to Llama for each side."
690
+ )
691
+ with gr.Row():
692
+ custom_verbose_chat = gr.Textbox(
693
+ label="Verbose call",
694
+ lines=10, interactive=False,
695
+ show_copy_button=True,
696
+ )
697
+ custom_trained_chat = gr.Textbox(
698
+ label="Trained call",
699
+ lines=10, interactive=False,
700
+ show_copy_button=True,
701
+ )
702
+
703
  gr.Markdown(
704
  "---\n"
705
  "**About**: this is the demo artifact for "
 
735
  compress_and_run,
736
  inputs=[custom_desc, custom_budget, custom_input],
737
  outputs=[custom_prompt_out, custom_tok, custom_verbose_tok,
738
+ custom_verbose_out, custom_target_out,
739
+ custom_verbose_chat, custom_trained_chat,
740
+ custom_status],
741
  )
742
  app.load(select_task, inputs=[task_dd], outputs=select_outputs)
743