developer
developer copied to clipboard
Incompatibility Issue: ast.literal_eval() Fails to Parse the generated Filepath String
The script main_no_modal.py
encounters a SyntaxError
when attempting to parse the string returned by generate_response
using Python's ast.literal_eval()
function.
The AI's generate_response
function currently returns a string representing a list of files in the following format:
- manifest.json
- popup.html
- popup.js
- background.js
- style.css
- words.json (or any other file containing the sentences for typing)
Unfortunately, ast.literal_eval()
expects a string formatted as a valid Python expression, which the current output is not. The incompatibility leads to a SyntaxError
during the execution of ast.literal_eval(filepaths_string)
. The error message is as follows:
File "C:\Users\parij\AppData\Local\Programs\Python\Python39\lib\ast.py", line 62, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "C:\Users\parij\AppData\Local\Programs\Python\Python39\lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 2
- popup.html
^
SyntaxError: invalid syntax
The issue can potentially be resolved by modifying the output of generate_response
to be a valid Python list string or by transforming the AI's output into a format that ast.literal_eval()
can process correctly before calling the function.
Steps to reproduce:
- Run the following prompt
python main_no_modal.py "a Manifest V3 Chrome extension that offers a pop-up, distraction-free environment for typing practice. It should generate varied, random sentences for typing and start a one-minute timer as the user begins. After the timer expires, display the user's typing speed in words per minute and add a reset button for a new round. Make sure the size of the pop-up is minimum 500 height * 600 width"
- Note the
SyntaxError
that is thrown when theast.literal_eval()
function is called with the output of thegenerate_response
function.
Any additional information or suggestions to resolve this issue are appreciated.
change the following from gpt-3.5-turbo to gpt-4 in constants.py
DEFAULT_MODEL = "gpt-4"
In 'filepaths_string = generate_response' prompt change 'return them as a python list of strings.' to 'return them as a python array of strings.'
I'm getting the same issue. changing to python array worked. Thanks!
Also, specify in the same prompt - "Use only camelCase naming convention and nothing else." as any other special characters like underscore also give error.