stanfordnlp / dspy

DSPy: The framework for programming—not prompting—language models
https://dspy.ai
MIT License
19.27k stars 1.47k forks source link

ImportError: cannot import name 'Cache' from 'litellm.caching' (unknown location) #1624

Closed HusainMkd closed 4 weeks ago

HusainMkd commented 1 month ago

I can't seem to import DSpy anymore (on Databricks)... I've tried downgrading the DSpy version, restarting the cluster, installing litellm - nothing seems to be working - Is there a breaking change somewhere? Below is my error message

ImportError: cannot import name 'Cache' from 'litellm.caching' (unknown location)
File <command-86610133237801>, line 5
      3 AZ_GPT4o_URI = os.getenv('AZ_GPT4o_URI')
      4 # from litellm.caching import Cache
----> 5 import dspy
      6 import pandas as pd
      7 import mlflow
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-33e20db8-6c63-45a6-a796-81c039e2d548/lib/python3.11/site-packages/dspy/__init__.py:8
      6 from .retrieve import *
      7 from .signatures import *
----> 8 from .utils.logging import logger, set_log_output
     10 # Functional must be imported after primitives, predict and signatures
     11 from .functional import *  # isort: skip
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-33e20db8-6c63-45a6-a796-81c039e2d548/lib/python3.11/site-packages/dspy/utils/__init__.py:1
----> 1 from .dummies import *
      2 from .logging import *
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-33e20db8-6c63-45a6-a796-81c039e2d548/lib/python3.11/site-packages/dspy/utils/dummies.py:11
      9 from dsp.utils.utils import dotdict
     10 from dspy.adapters.chat_adapter import field_header_pattern, format_fields
---> 11 from dspy.clients.lm import LM
     14 class DSPDummyLM(DSPLM):
     15     """Dummy language model for unit testing purposes subclassing DSP LM class."""
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-33e20db8-6c63-45a6-a796-81c039e2d548/lib/python3.11/site-packages/dspy/clients/__init__.py:1
----> 1 from .lm import LM
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-33e20db8-6c63-45a6-a796-81c039e2d548/lib/python3.11/site-packages/dspy/clients/lm.py:9
      7 import litellm
      8 import ujson
----> 9 from litellm.caching import Cache
     11 disk_cache_dir = os.environ.get("DSPY_CACHEDIR") or os.path.join(Path.home(), ".dspy_cache")
     12 litellm.cache = Cache(disk_cache_dir=disk_cache_dir, type="disk")
btebbutt commented 1 month ago

getting this also

btebbutt commented 1 month ago

getting this also

I'm also running on data bricks.

arnavsinghvi11 commented 1 month ago

probably just needs to be fixed to from litellm.caching.caching import Cache from the LiteLLM docs but tagging @chenmoneygithub if this was indeed intended from the PR change #1604

dvd42 commented 1 month ago

It's a litellm problem which should be fixed soon (https://github.com/BerriAI/litellm/issues/6216#issuecomment-2411874662)

ruchiradhar commented 1 month ago

Yes, facing the same problem here as well! from litellm.caching.caching import Cache doesn't work either.

isaacbmiller commented 1 month ago

Temporary fix is pip install litellm==1.49.2 as 1.49.3 is the version that breaks it

krypticmouse commented 1 month ago

Fixed in #1629 but we'll need to hook it back to latest ones once litellm fixes it

okhat commented 1 month ago

Wow sorry I normally check issues faster than today. The fix was easy (pinning older litellm until they fix it).

It sucks that an upstream thing like this could lead to issues for people.

chenmoneygithub commented 4 weeks ago

This should've been fixed: https://github.com/BerriAI/litellm/issues/6216

chenmoneygithub commented 4 weeks ago

Verified with litellm 1.51.0

Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 10:07:17) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import litellm
>>> import dspy
>>>