Aider-AI / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
20.05k stars 1.84k forks source link

Uncaught ImportError in utils.py line 9 #1922

Open Anansitrading opened 2 days ago

Anansitrading commented 2 days ago

Aider version: 0.58.1 Python version: 3.12.4 Platform: Windows-11-10.0.22631-SP0 Python implementation: CPython Virtual environment: Yes OS: Windows 11 (64bit) Git version: git version 2.45.2.windows.1

An uncaught exception occurred:

Traceback (most recent call last):
  File "base_coder.py", line 1129, in send_message
    yield from self.send(messages, functions=self.functions)
  File "base_coder.py", line 1410, in send
    hash_object, completion = send_completion(
                              ^^^^^^^^^^^^^^^^
  File "sendchat.py", line 83, in send_completion
    res = litellm.completion(**kwargs)
          ^^^^^^^^^^^^^^^^^^
  File "llm.py", line 23, in __getattr__
    self._load_litellm()
  File "llm.py", line 30, in _load_litellm
    self._lazy_module = importlib.import_module("litellm")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "__init__.py", line 9, in <module>
    from litellm.caching import Cache
  File "caching.py", line 28, in <module>
    from litellm.types.utils import all_litellm_params
  File "utils.py", line 9, in <module>
    from openai.types.completion_usage import CompletionTokensDetails, CompletionUsage
ImportError: cannot import name 'CompletionTokensDetails' from 'openai.types.completion_usage' (C:\Users\david\Documents\Projects\gpt-pilot\venv\Lib\site-packages\openai\types\completion_usage.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "__main__.py", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "main.py", line 727, in main
    coder.run()
  File "base_coder.py", line 730, in run
    self.run_one(user_message, preproc)
  File "base_coder.py", line 773, in run_one
    list(self.send_message(message))
  File "base_coder.py", line 1131, in send_message
    except retry_exceptions() as err:
           ^^^^^^^^^^^^^^^^^^
  File "sendchat.py", line 24, in retry_exceptions
    litellm.exceptions.APIConnectionError,
    ^^^^^^^^^^^^^^^^^^
  File "llm.py", line 23, in __getattr__
    self._load_litellm()
  File "llm.py", line 30, in _load_litellm
    self._lazy_module = importlib.import_module("litellm")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "__init__.py", line 9, in <module>
    from litellm.caching import Cache
  File "caching.py", line 28, in <module>
    from litellm.types.utils import all_litellm_params
  File "utils.py", line 9, in <module>
    from openai.types.completion_usage import CompletionTokensDetails, CompletionUsage
ImportError: cannot import name 'CompletionTokensDetails' from 'openai.types.completion_usage' (C:\Users\david\Documents\Projects\gpt-pilot\venv\Lib\site-packages\openai\types\completion_usage.py)
fry69 commented 2 days ago

Thank you for filing this issue.

Can you please try to install or reinstall aider in a separate Python environment? Either with venv or pipx?

Please remove the existing environment/aider installation first, e.g. with pipx:

$ pipx uninstall aider-chat
uninstalled aider-chat! ✨ 🌟 ✨
$ pipx install aider-chat
  installed package aider-chat 0.58.1, installed using Python 3.12.7
  These apps are now globally available
    - aider
done! ✨ 🌟 ✨

This document may be helpful -> https://aider.chat/docs/troubleshooting/imports.html