forked from abi/screenshot-to-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.analysis.typeCheckingMode": "strict" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import copy | ||
import json | ||
from typing import List | ||
from openai.types.chat import ChatCompletionMessageParam | ||
|
||
|
||
def pprint_prompt(prompt_messages): | ||
def pprint_prompt(prompt_messages: List[ChatCompletionMessageParam]): | ||
print(json.dumps(truncate_data_strings(prompt_messages), indent=4)) | ||
|
||
|
||
def truncate_data_strings(data): | ||
def truncate_data_strings(data: List[ChatCompletionMessageParam]): # type: ignore | ||
# Deep clone the data to avoid modifying the original object | ||
cloned_data = copy.deepcopy(data) | ||
|
||
if isinstance(cloned_data, dict): | ||
for key, value in cloned_data.items(): | ||
for key, value in cloned_data.items(): # type: ignore | ||
# Recursively call the function if the value is a dictionary or a list | ||
if isinstance(value, (dict, list)): | ||
cloned_data[key] = truncate_data_strings(value) | ||
cloned_data[key] = truncate_data_strings(value) # type: ignore | ||
# Truncate the string if it it's long and add ellipsis and length | ||
elif isinstance(value, str): | ||
cloned_data[key] = value[:40] | ||
cloned_data[key] = value[:40] # type: ignore | ||
if len(value) > 40: | ||
cloned_data[key] += "..." + f" ({len(value)} chars)" | ||
cloned_data[key] += "..." + f" ({len(value)} chars)" # type: ignore | ||
|
||
elif isinstance(cloned_data, list): | ||
elif isinstance(cloned_data, list): # type: ignore | ||
# Process each item in the list | ||
cloned_data = [truncate_data_strings(item) for item in cloned_data] | ||
cloned_data = [truncate_data_strings(item) for item in cloned_data] # type: ignore | ||
|
||
return cloned_data | ||
return cloned_data # type: ignore |