8000 fix up pretty printing · ag-python/screenshot-to-code@0301f24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0301f24

Browse files
committed
fix up pretty printing
1 parent a559cd3 commit 0301f24

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

backend/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Load environment variables first
22
from dotenv import load_dotenv
33

4+
45
load_dotenv()
56

67

@@ -14,6 +15,7 @@
1415
import openai
1516
from llm import stream_openai_response
1617
from mock import mock_completion
18+
from utils import pprint_prompt
1719
from image_generation import create_alt_url_mapping, generate_images
1820
from prompts import assemble_prompt
1921
from routes import screenshot
@@ -183,7 +185,6 @@ async def process_chunk(content):
183185
prompt_messages += [
184186
{"role": "assistant" if index % 2 == 0 else "user", "content": text}
185187
]
186-
187188
image_cache = create_alt_url_mapping(params["history"][-2])
188189

189190
if SHOULD_MOCK_AI_RESPONSE:

backend/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import copy
2+
import json
3+
4+
5+
def pprint_prompt(prompt_messages):
6+
print(json.dumps(truncate_data_strings(prompt_messages), indent=4))
27

38

49
def truncate_data_strings(data):
@@ -10,9 +15,12 @@ def truncate_data_strings(data):
1015
# Recursively call the function if the value is a dictionary or a list
1116
if isinstance(value, (dict, list)):
1217
cloned_data[key] = truncate_data_strings(value)
13-
# Truncate the string if it starts with 'data:'
14-
elif isinstance(value, str) and value.startswith("data:"):
15-
cloned_data[key] = value[:20]
18+
# Truncate the string if it it's long and add ellipsis and length
19+
elif isinstance(value, str):
20+
cloned_data[key] = value[:40]
21+
if len(value) > 40:
22+
cloned_data[key] += "..." + f" ({len(value)} chars)"
23+
1624
elif isinstance(cloned_data, list):
1725
# Process each item in the list
1826
cloned_data = [truncate_data_strings(item) for item in cloned_data]

0 commit comments

Comments
 (0)
0