Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
feat: add expandable prompt summary with truncate parameter
Abi Raja9c86bd9abe87
diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.pyindex a10b0cab..31781ace 100644--- a/backend/routes/generate_code.py+++ b/backend/routes/generate_code.py@@ -402,7 +402,7 @@ class PromptCreationStage:params, stack, input_mode)- print_prompt_summary(prompt_messages)+ print_prompt_summary(prompt_messages, truncate=False)return prompt_messages, image_cacheexcept Exception:diff --git a/backend/tests/test_prompt_summary.py b/backend/tests/test_prompt_summary.pyindex e7e10828..6ee5927d 100644--- a/backend/tests/test_prompt_summary.py+++ b/backend/tests/test_prompt_summary.py@@ -80,3 +80,40 @@ def test_print_prompt_summary_long_content():assert "PROMPT SUMMARY" in outputassert "SYSTEM:" in outputassert "USER: short" in output+++def test_format_prompt_summary_no_truncate():+ messages = [+ {"role": "system", "content": "This is a very long message that would normally be truncated at 40 characters but should be shown in full"},+ ]++ # Test with truncation (default)+ summary_truncated = format_prompt_summary(messages)+ assert "..." in summary_truncated+ assert len(summary_truncated.split(": ", 1)[1]) <= 50 # Role + truncated content++ # Test without truncation+ summary_full = format_prompt_summary(messages, truncate=False)+ assert "..." not in summary_full+ assert "shown in full" in summary_full+++def test_print_prompt_summary_no_truncate():+ messages = [+ {"role": "system", "content": "This is a very long message that would normally be truncated but should be shown in full when truncate=False"},+ ]++ # Capture stdout+ captured_output = io.StringIO()+ sys.stdout = captured_output++ print_prompt_summary(messages, truncate=False)++ # Reset stdout+ sys.stdout = sys.__stdout__++ output = captured_output.getvalue()++ # Check that full content is shown+ assert "shown in full when truncate=False" in output+ assert "..." not in outputdiff --git a/backend/utils.py b/backend/utils.pyindex efc04fb9..7ad7190b 100644--- a/backend/utils.py+++ b/backend/utils.py@@ -8,7 +8,7 @@ def pprint_prompt(prompt_messages: List[ChatCompletionMessageParam]):print(json.dumps(truncate_data_strings(prompt_messages), indent=4))-def format_prompt_summary(prompt_messages: List[ChatCompletionMessageParam]) -> str:+def format_prompt_summary(prompt_messages: List[ChatCompletionMessageParam], truncate: bool = True) -> str:parts: list[str] = []for message in prompt_messages:role = message["role"]@@ -26,7 +26,7 @@ def format_prompt_summary(prompt_messages: List[ChatCompletionMessageParam]) ->text = str(content)text = text.strip()- if len(text) > 40:+ if truncate and len(text) > 40:text = text[:40] + "..."img_part = f" + [{image_count} images]" if image_count else ""@@ -35,13 +35,15 @@ def format_prompt_summary(prompt_messages: List[ChatCompletionMessageParam]) ->return "\n".join(parts)-def print_prompt_summary(prompt_messages: List[ChatCompletionMessageParam]):- summary = format_prompt_summary(prompt_messages)+def print_prompt_summary(prompt_messages: List[ChatCompletionMessageParam], truncate: bool = True):+ summary = format_prompt_summary(prompt_messages, truncate)lines = summary.split('\n')- # Find the maximum line length, with a minimum of 20 and maximum of 80+ # Find the maximum line length, with a minimum of 20+ # If truncating, max is 80, otherwise allow up to 120 for full content+ max_allowed = 80 if truncate else 120max_length = max(len(line) for line in lines) if lines else 20- max_length = max(20, min(80, max_length))+ max_length = max(20, min(max_allowed, max_length))# Ensure title fitstitle = "PROMPT SUMMARY"