smol-ai / developer

the first library to let you embed a developer agent in your own app!
https://twitter.com/SmolModels
MIT License
11.79k stars 1.03k forks source link

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

Open Parijat-18 opened 1 year ago

Parijat-18 commented 1 year ago

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"
  2. 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 commented 1 year ago

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

DEFAULT_MODEL = "gpt-4"

togran commented 1 year ago

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 commented 1 year ago

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

Dip707 commented 1 year ago

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