stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy.ai
MIT License
18.72k stars 1.43k forks source link

ModuleNotFoundError: No module named 'openai.error' #220

Closed mBerezovskyy closed 12 months ago

mBerezovskyy commented 1 year ago

When running colab example

the first cell, containing the below code results in

ModuleNotFoundError: No module named 'openai.error'.

%load_ext autoreload
%autoreload 2

import sys
import os

try: # When on google Colab, let's clone the notebook so we download the cache.
    import google.colab
    repo_path = 'dspy'
    !git -C $repo_path pull origin || git clone https://github.com/stanfordnlp/dspy $repo_path
except:
    repo_path = '.'

if repo_path not in sys.path:
    sys.path.append(repo_path)

# Set up the cache for this notebook
os.environ["DSP_NOTEBOOK_CACHEDIR"] = os.path.join(repo_path, 'cache')

import pkg_resources # Install the package if it's not installed
if not "dspy-ai" in {pkg.key for pkg in pkg_resources.working_set}:
    !pip install -U pip
    !pip install dspy-ai
    # !pip install -e $repo_path

import dspy

Running pip install -U openai does not help. Does the DSPy relies on some concrete openai library version or am I missing something?

lawliet19189 commented 1 year ago

Could you please try installing with openai==0.28.1 and let me know if this fixes the issue?

The newer versions from openai makes some breaking changes and that is causing the issue. Thanks for flagging this. We will fix it soon.

lawliet19189 commented 12 months ago

Hey @mBerezovskyy, This should be fixed now with our latest dspy-ai package release. You do not have to make any changes in the colab notebook and can run as-is. Please re-open the ticket if you are facing any difficulty.

Once again, Thanks for reporting!

mBerezovskyy commented 12 months ago

@lawliet19189 Thanks! I can confirm that it is working now

baibaipangpang-bbpp commented 11 months ago

running into the same error from https://github.com/cgpotts/cs224u/ with hw_openqa.ipynb adding the openai api version seems to have solved it.