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

UnboundLocalError: cannot access local variable 'text' where it is not associated with a value #183

Closed
dholakashyap opened this issue Aug 7, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@dholakashyap
Copy link

dholakashyap commented Aug 7, 2023

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\ProgramData\anaconda3\envs\aider\Scripts\aider.exe\__main__.py", line 7, in <module>
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\main.py", line 523, in main
    coder.run()
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\coders\base_coder.py", line 339, in run
    new_user_message = self.run_loop()
                       ^^^^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\coders\base_coder.py", line 423, in run_loop
    return self.send_new_user_message(inp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\coders\base_coder.py", line 456, in send_new_user_message
    interrupted = self.send(messages, functions=self.functions)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\coders\base_coder.py", line 580, in send
    self.show_send_output_stream(completion)
  File "C:\ProgramData\anaconda3\envs\aider\Lib\site-packages\aider\coders\base_coder.py", line 680, in show_send_output_stream
    sys.stdout.write(text)
                     ^^^^
UnboundLocalError: cannot access local variable 'text' where it is not associated with a value

I don't know what error this is but and how it's coming
Someone please guide me this is my error while installing aider or it's from source

Python 3.11.4 with conda

@joshuavial
Copy link
Contributor

Thanks for submitting the issue. I'm happy to try and reproduce this, it looks like a piece of the code which needs a bit more error handling added. Can you share any more information about the steps you took before it happened or what flags you ran aider with?

Looking at the code I'm guessing that an AttributeError fired because choices[0].delta.content wasn't defined in base_coder.

@dholakashyap
Copy link
Author

i don't know why error is coming but I added

base_cider.py
def show_send_output_stream(self, completion):
**text = ""**
live = None
if self.pretty:

And Temporarily my problem solved
and then I tried aider with azure openai I have access of gpt-3.5-turbo-16k but aider detects it as gpt for but I think that is the glitch but I got error is writing code in files

Error while writing code

Malformed response #1, retrying...
InvalidEditBlock: edit failed!

snake.py does not contain the exact sequence of ORIGINAL lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The ORIGINAL block needs to be EXACTLY the same as the lines in snake.py with nothing missing!

snake.py does not contain these 5 exact lines in a row:

    # import pygame module
    import pygame

    # initialize pygame
    pygame.init()

@dholakashyap
Copy link
Author

text = chunk.choices[0].delta.content line 671

is defined in base_coder.py

the steps you took before it happened or what flags you ran aider with?

I have Just installed aider with the conda environment and created .aider.conf.yml within my project directory and added Azure Openai Credentials according to docs. and than just run aider with

aider FirePlus.java

@dholakashyap
Copy link
Author

i think now actual problem is

Malformed response #2, retrying...
InvalidEditBlock: edit failed!

snake.py does not contain the exact sequence of ORIGINAL lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The ORIGINAL block needs to be EXACTLY the same as the lines in snake.py with nothing missing!

snake.py does not contain these 5 exact lines in a row:

    # import pygame module
    import pygame

    # initialize pygame
    pygame.init()

@joshuavial
Copy link
Contributor

InvalidEditBlock: edit failed!

snake.py does not contain the exact sequence of ORIGINAL lines you specified. Try again. DO NOT skip blank lines, comments, docstrings, etc! The ORIGINAL block needs to be EXACTLY the same as the lines in snake.py with nothing missing!

snake.py does not contain these 5 exact lines in a row:

that problem is what happens when the LLM outputs a diff that isn't correct (misses some lines etc.) gpt-3.5 is a bit under powered when using diff edit format so if aider is detecting 3.5 as 4 as you mentioned then I'd expect to see the errors you're seeing.

Does forcing it to the wholefile coder using --edit-format whole (or similar in the config file) change its behaviour?

@paul-gauthier paul-gauthier added the bug Something isn't working label Aug 8, 2023
@paul-gauthier
Copy link
Collaborator

Thanks for trying aider and reporting this issue.

It should be fixed in the main branch: 3c0720f

You can get it by installing the latest version from github:

python -m pip install git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

@dholakashyap
Copy link
Author

i have shared complete error log as mentioned

@paul-gauthier
Copy link
Collaborator

This fix just went out in v0.11.1. I'm going to close this issue for now, but feel free to re-open or file a new issue any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants