Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility Issue: ast.literal_eval() Fails to Parse the generated Filepath String #72

Open
Parijat-18 opened this issue Jun 3, 2023 · 4 comments

Comments

@Parijat-18
Copy link

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:

  1. 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"
  1. Note the SyntaxError that is thrown when the ast.literal_eval() function is called with the output of the generate_response function.

Any additional information or suggestions to resolve this issue are appreciated.

@trilloc
Copy link

trilloc commented Jun 4, 2023

change the following from gpt-3.5-turbo to gpt-4 in constants.py

DEFAULT_MODEL = "gpt-4"

@togran
Copy link

togran commented Jun 4, 2023

In 'filepaths_string = generate_response' prompt change 'return them as a python list of strings.' to 'return them as a python array of strings.'

@kufton
Copy link

kufton commented Jun 7, 2023

I'm getting the same issue. changing to python array worked. Thanks!

@Dip707
Copy link

Dip707 commented Jun 12, 2023

Also, specify in the same prompt - "Use only camelCase naming convention and nothing else."
as any other special characters like underscore also give error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants