Repository: Giskard-AI/giskard-oss
Issue: Scan is not working with OpenAI when running quickstart_llm.ipynb. AttributeError: module 'openai' has no attribute 'Client'
Root cause: External Dependency Breakage

### Issue Type

Bug

### Source

source

### Giskard Library Version

2.11.0

### Giskard Hub Version

?

### OS Platform and Distribution

_No response_

### Python version

_No response_

### Installed python packages

```shell
aiohttp==3.9.5
aiosignal==1.3.1
annotated-types==0.6.0
anyio==3.7.1
asn1crypto==1.5.1
async-timeout==4.0.3
attrs==23.2.0
bcrypt==3.2.0
bert-score==0.3.13
bokeh==3.4.1
boto3==1.29.1
botocore==1.32.1
Bottleneck==1.3.7
Brotli==1.0.9
certifi==2024.2.2
cffi==1.16.0
chardet==5.2.0
charset-normalizer==2.0.4
click==8.1.7
cloudpickle==3.0.0
colorama==0.4.6
configparser==5.0.2
contourpy==1.2.1
cryptography==41.0.7
cycler==0.12.1
dataclasses-json==0.6.4
datasets==2.19.0
dill==0.3.8
distro==1.9.0
docopt==0.6.2
entrypoints==0.4
evaluate==0.4.1
exceptiongroup==1.2.1
faiss-cpu==1.7.4
filelock==3.13.1
fonttools==4.51.0
frozenlist==1.4.1
fsspec==2024.3.1
future==0.18.3
giskard==2.11.0
gitdb==4.0.11
GitPython==3.1.43
greenlet==3.0.1
griffe==0.44.0
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
huggingface-hub==0.22.2
idna==3.4
importlib_metadata==7.1.0
Jinja2==3.1.3
jmespath==1.0.1
joblib==1.4.0
jsonpatch==1.33
jsonpointer==2.4
kiwisolver==1.4.5
langchain==0.0.301
langdetect==1.0.9
langsmith==0.0.92
llvmlite==0.42.0
Markdown==3.6
markdown-it-py==2.2.0
MarkupSafe==2.1.5
marshmallow==3.21.1
matplotlib==3.8.4
mdurl==0.1.0
mixpanel==4.10.1
mkl-fft==1.3.8
mkl-random==1.2.4
mkl-service==2.4.0
mlflow-skinny==2.12.1
mpmath==1.3.0
multidict==6.0.5
multiprocess==0.70.16
mypy-extensions==1.0.0
networkx==3.3
num2words==0.5.13
numba==0.59.1
numexpr==2.8.7
numpy==1.26.4
openai==0.28.1
packaging==23.2
pandas==2.0.3
paramiko==2.8.1
pillow==10.3.0
pip==23.3.1
platformdirs==3.10.0
protobuf==5.26.1
psutil==5.9.0
pure-sasl==0.6.2
pyarrow==16.0.0
pyarrow-hotfix==0.6
pycparser==2.21
pydantic==1.10.12
pydantic_core==2.18.2
Pygments==2.15.1
PyHive==0.6.1
PyJWT==2.4.0
PyNaCl==1.5.0
pynndescent==0.5.12
pyOpenSSL==23.2.0
pyparsing==3.1.2
pypdf==3.17.0
PySocks==1.7.1
python-dateutil==2.8.2
pytz==2023.3.post1
PyYAML==6.0.1
regex==2024.4.16
requests==2.31.0
requests-toolbelt==1.0.0
responses==0.18.0
rich==13.3.5
s3transfer==0.7.0
safetensors==0.4.3
scikit-learn==1.4.2
scipy==1.11.4
scp==0.14.1
sentry-sdk==1.45.0
setuptools==68.0.0
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
snowflake-connector-python==3.7.0
sortedcontainers==2.4.0
SQLAlchemy==2.0.25
sqlparse==0.5.0
sympy==1.12
tenacity==8.2.3
threadpoolctl==3.4.0
thrift==0.17.0
thrift-sasl==0.4.3
tiktoken==0.5.1
tokenizers==0.19.1
tomlkit==0.11.1
torch==2.2.2
tornado==6.4
tqdm==4.65.0
transformers==4.40.1
typing_extensions==4.11.0
typing-inspect==0.9.0
tzdata==2023.3
umap-learn==0.5.6
urllib3==1.26.18
wheel==0.41.2
xxhash==3.4.1
xyzservices==2024.4.0
yarl==1.9.4
zipp==3.18.1
zstandard==0.22.0
```


### Current Behaviour?

```shell
INFO:giskard.scanner.logger:Running detectors: ['LLMImplausibleOutputDetector', 'LLMBasicSycophancyDetector']
🔎 Running scan…
Estimated calls to your model: ~30
Estimated LLM calls for evaluation: 22

Running detector LLMImplausibleOutputDetector…
ERROR:giskard.scanner.logger:Detector LLMImplausibleOutputDetector failed with error: module 'openai' has no attribute 'Client'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/giskard/scanner/scanner.py", line 152, in _run_detectors
    detected_issues = detector.run(model, dataset, features=features)
  File "/usr/local/lib/python3.10/dist-packages/giskard/scanner/llm/llm_implausible_output_detector.py", line 65, in run
    generator = ImplausibleDataGenerator(llm_temperature=0.1, languages=languages)
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/generators/base.py", line 37, in __init__
    self.llm_client = llm_client or get_default_client()
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/__init__.py", line 61, in get_default_client
    from .openai import OpenAIClient
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/openai.py", line 32, in <module>
    class OpenAIClient(LLMClient):
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/openai.py", line 34, in OpenAIClient
    self, model: str = "gpt-4-turbo-preview", client: openai.Client = None, json_mode: Optional[bool] = None
AttributeError: module 'openai' has no attribute 'Client'
ERROR:giskard.scanner.logger:Detector LLMBasicSycophancyDetector failed with error: module 'openai' has no attribute 'Client'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/giskard/scanner/scanner.py", line 152, in _run_detectors
    detected_issues = detector.run(model, dataset, features=features)
  File "/usr/local/lib/python3.10/dist-packages/giskard/scanner/llm/llm_basic_sycophancy_detector.py", line 84, in run
    generator = SycophancyDataGenerator(languages=languages)
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/generators/base.py", line 37, in __init__
    self.llm_client = llm_client or get_default_client()
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/__init__.py", line 61, in get_default_client
    from .openai import OpenAIClient
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/openai.py", line 32, in <module>
    class OpenAIClient(LLMClient):
  File "/usr/local/lib/python3.10/dist-packages/giskard/llm/client/openai.py", line 34, in OpenAIClient
    self, model: str = "gpt-4-turbo-preview", client: openai.Client = None, json_mode: Optional[bool] = None
AttributeError: module 'openai' has no attribute 'Client'
LLMImplausibleOutputDetector: 0 issue detected. (Took 0:00:00.656150)
Running detector LLMBasicSycophancyDetector…
LLMBasicSycophancyDetector: 0 issue detected. (Took 0:00:00.020114)
Scan completed: no issues found. (Took 0:00:00.686836)
/usr/local/lib/python3.10/dist-packages/giskard/scanner/scanner.py:367: UserWarning: 2 errors were encountered while running detectors. Please check the log to understand what went wrong. You can run the scan again with `raise_exceptions=True` to disable graceful handling.
  warning(
```


### Standalone code OR list down the steps to reproduce the issue

```shell
https://colab.research.google.com/github/giskard-ai/giskard/blob/main/docs/getting_started/quickstart/quickstart_llm.ipynb

I am running this quickstart copied from your website
```


### Relevant log output

_No response_

Hello, 

It seems that you're using `openai` version 0.28.1 however giskard require the version `>=1`.

You can run `pip install openai>1` to fix the error.

Hi @kevinmessiaen,

Just a heads up that your LLM quickstart documentation (https://docs.giskard.ai/en/latest/getting_started/quickstart/quickstart_llm.html) explicitly recommends installing the old versions of openai and langchain! I think that's why @HuaizhengZhang ran into this issue and perhaps others will as well.

Also worth noting that if someone has installed the old versions as listed there, they'll need to update `langchain` to the latest version (mine currently works at `0.1.16`) in addition to `openai`.

@HuaizhengZhang, I am getting same error even after installing 'pip install openai>1'.  Which version are you using?
@kevinmessiaen @fcangialosi  Can you name any specific version?


> @HuaizhengZhang, I am getting same error even after installing 'pip install openai>1'. Which version are you using? @kevinmessiaen @fcangialosi Can you name any specific version?

the below installation works for me. make sure openai, langchain, torch are all on the latest version

```bash
pip install "langchain" "pypdf<=3.17.0" "faiss-cpu<=1.7.4" "openai" "tiktoken<=0.5.1" "tabulate"
pip install -U langchain-community`

pip install torch==2.3.0
```

> I am getting same error even after installing 'pip install openai>1'. Which version are you using?

If you originally installed the old langchain version then that's probably the reason, you need to update langchain in addition to openai. @HuaizhengZhang's versions work for me

Thanks a lot. Finally I was. able to make it work with openai: Version: 1.25.1,  giskard Version: 2.12.0 and python Version: 3.11.9