Repository: truera/trulens
Issue: Cannot Import name LLMProvider when using Bedrock
Root cause: Environment Incompatibility

Using truelens_eval==0.18.2

I'm trying to import Bedrock using the following line of code:

`
from trulens_eval.feedback.provider.bedrock import Bedrock
`

but when I run the line I get the following error:

```
ImportError                               Traceback (most recent call last)
Cell In[44], line 3
      1 #from trulens_eval import TruChain, Feedback, Tru, Bedrock
      2 #from trulens_eval.feedback.provider import Bedrock
----> 3 from trulens_eval.feedback.provider.bedrock import Bedrock
      4 tru = Tru()
      6 tru.reset_database()

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/trulens_eval/feedback/provider/bedrock.py:7
      4 from typing import Dict, Optional, Sequence
      6 from trulens_eval.feedback import prompts
----> 7 from trulens_eval.feedback.provider.base import LLMProvider
      8 from trulens_eval.feedback.provider.endpoint import BedrockEndpoint
      9 from trulens_eval.feedback.provider.endpoint.base import Endpoint

ImportError: cannot import name 'LLMProvider' from 'trulens_eval.feedback.provider.base' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/trulens_eval/feedback/provider/base.py)
```

Strange; can you show us the output of `pip list` ?

> Strange; can you show us the output of `pip list` ?

Here is the result of pip list

```
Package                       Version
----------------------------- ------------
aiohttp                       3.8.6
aiosignal                     1.3.1
aiostream                     0.5.2
alabaster                     0.7.13
alembic                       1.13.0
altair                        5.2.0
annotated-types               0.6.0
anthropic                     0.7.2
anyio                         3.7.1
appdirs                       1.4.4
argon2-cffi                   23.1.0
argon2-cffi-bindings          21.2.0
arrow                         1.3.0
asn1crypto                    1.5.1
astroid                       2.15.8
astropy                       5.3.4
asttokens                     2.4.1
async-lru                     2.0.4
async-timeout                 4.0.3
atomicwrites                  1.4.1
attrs                         23.1.0
autopep8                      2.0.4
autovizwidget                 0.21.0
awscli                        1.29.76
Babel                         2.13.1
backcall                      0.2.0
backoff                       2.2.1
backports.functools-lru-cache 1.6.5
beautifulsoup4                4.12.2
binaryornot                   0.4.4
bitarray                      2.8.2
black                         23.10.1
bleach                        6.1.0
blinker                       1.6.3
bokeh                         3.3.0
boto3                         1.28.59
botocore                      1.31.76
Bottleneck                    1.3.7
Brotli                        1.1.0
brotlipy                      0.7.0
cached-property               1.5.2
cachetools                    5.3.2
certifi                       2023.7.22
cffi                          1.16.0
chardet                       5.2.0
charset-normalizer            3.3.1
click                         8.1.7
cloudpickle                   2.2.1
cohere                        4.37
colorama                      0.4.4
comm                          0.1.4
contextlib2                   21.6.0
contourpy                     1.1.1
cookiecutter                  2.4.0
coverage                      7.3.2
cryptography                  41.0.5
cycler                        0.12.1
Cython                        3.0.4
cytoolz                       0.12.2
dask                          2023.10.0
dataclasses-json              0.6.2
datasets                      2.15.0
debugpy                       1.8.0
decorator                     5.1.1
defusedxml                    0.7.1
Deprecated                    1.2.14
diff-match-patch              20230430
dill                          0.3.7
distributed                   2023.10.0
distro                        1.8.0
dnspython                     2.4.2
docker                        6.1.3
docstring-to-markdown         0.13
docutils                      0.16
dparse                        0.6.3
entrypoints                   0.4
et-xmlfile                    1.1.0
exceptiongroup                1.1.3
executing                     1.2.0
faiss-cpu                     1.7.4
Faker                         20.1.0
fastavro                      1.9.0
fastcache                     1.1.0
fastjsonschema                2.18.1
favicon                       0.7.0
filelock                      3.12.4
flake8                        6.0.0
Flask                         3.0.0
Flask-Cors                    4.0.0
fonttools                     4.43.1
fqdn                          1.5.1
frozendict                    2.3.10
frozenlist                    1.4.0
fsspec                        2023.10.0
future                        0.18.3
gevent                        23.9.0.post1
gitdb                         4.0.11
GitPython                     3.1.40
gmpy2                         2.1.2
google-pasta                  0.2.0
greenlet                      3.0.1
h11                           0.14.0
h5py                          3.10.0
hdijupyterutils               0.21.0
htbuilder                     0.6.2
html2text                     2020.1.16
httpcore                      1.0.2
httpx                         0.25.1
huggingface-hub               0.19.4
humanize                      4.9.0
idna                          3.4
imagecodecs                   2023.9.18
imageio                       2.31.5
imagesize                     1.4.1
immutables                    0.20
importlib-metadata            6.8.0
importlib-resources           6.1.0
inflection                    0.5.1
iniconfig                     2.0.0
intervaltree                  3.1.0
ipykernel                     6.26.0
ipython                       8.16.1
ipython-genutils              0.2.0
ipywidgets                    8.1.1
isoduration                   20.11.0
isort                         5.12.0
itsdangerous                  2.1.2
jaraco.classes                3.3.0
jedi                          0.18.2
jeepney                       0.8.0
jellyfish                     1.0.1
Jinja2                        3.1.2
jmespath                      1.0.1
joblib                        1.3.2
json5                         0.9.14
jsonpatch                     1.33
jsonpointer                   2.4
jsonschema                    4.19.1
jsonschema-specifications     2023.7.1
jupyter                       1.0.0
jupyter_client                8.5.0
jupyter-console               6.6.3
jupyter_core                  5.4.0
jupyter-events                0.8.0
jupyter-lsp                   2.2.0
jupyter_server                2.9.1
jupyter_server_terminals      0.4.4
jupyterlab                    4.0.7
jupyterlab-pygments           0.2.2
jupyterlab_server             2.25.0
jupyterlab-widgets            3.0.9
kaggle                        1.5.16
keyring                       24.2.0
kiwisolver                    1.4.5
langchain                     0.0.345
langchain-core                0.0.9
langsmith                     0.0.63
lazy_loader                   0.3
lazy-object-proxy             1.9.0
litellm                       1.10.2
llama-index                   0.9.11.post1
llvmlite                      0.40.1
locket                        1.0.0
loguru                        0.7.2
lxml                          4.9.3
lz4                           4.3.2
Mako                          1.3.0
Markdown                      3.5.1
markdown-it-py                3.0.0
markdownlit                   0.0.7
MarkupSafe                    2.1.3
marshmallow                   3.20.1
matplotlib                    3.8.0
matplotlib-inline             0.1.6
mccabe                        0.7.0
mdurl                         0.1.0
merkle-json                   1.0.0
millify                       0.1.1
mistune                       3.0.1
mkl-fft                       1.3.8
mkl-service                   2.4.0
mock                          5.1.0
more-itertools                10.1.0
mpmath                        1.3.0
msgpack                       1.0.6
multidict                     6.0.4
multiprocess                  0.70.15
munch                         4.0.0
munkres                       1.1.4
mypy-extensions               1.0.0
nbclient                      0.8.0
nbconvert                     7.9.2
nbformat                      5.9.2
nest-asyncio                  1.5.8
networkx                      3.2
nltk                          3.8.1
nose                          1.3.7
notebook                      7.0.6
notebook_shim                 0.2.3
numba                         0.57.1
numexpr                       2.8.7
numpy                         1.26.2
numpydoc                      1.5.0
openai                        1.3.7
openpyxl                      3.1.2
opensearch-py                 2.4.2
overrides                     7.4.0
packaging                     21.3
pandas                        2.1.1
pandocfilters                 1.5.0
parso                         0.8.3
partd                         1.4.1
path                          16.7.1
pathlib2                      2.3.7.post1
pathos                        0.3.1
pathspec                      0.11.2
patsy                         0.5.3
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        10.0.1
pinecone-client               2.2.4
pip                           23.3.1
pkginfo                       1.9.6
pkgutil_resolve_name          1.3.10
platformdirs                  3.11.0
plotly                        5.18.0
pluggy                        1.3.0
ply                           3.11
pox                           0.3.3
ppft                          1.7.6.7
prometheus-client             0.17.1
prompt-toolkit                3.0.39
protobuf                      4.25.0
psutil                        5.9.5
psycopg2                      2.9.7
psycopg2-binary               2.9.7
ptyprocess                    0.7.0
pure-eval                     0.2.2
py-cpuinfo                    9.0.0
py4j                          0.10.9.5
pyarrow                       13.0.0
pyarrow-hotfix                0.6
pyasn1                        0.5.0
PyAthena                      3.0.10
pycodestyle                   2.10.0
pycosat                       0.6.6
pycparser                     2.21
pycryptodome                  3.19.0
pycurl                        7.45.1
pydantic                      1.10.13
pydantic_core                 2.10.1
pydeck                        0.8.1b0
pydocstyle                    6.3.0
pyerfa                        2.0.1.1
pyflakes                      3.0.1
Pygments                      2.16.1
PyJWT                         2.8.0
pykerberos                    1.2.4
pylint                        2.17.7
pylint-venv                   3.0.3
pyls-spyder                   0.4.0
pymdown-extensions            10.5
pynvml                        11.5.0
pyodbc                        5.0.1
pyOpenSSL                     23.2.0
pyparsing                     3.1.1
PyQt5                         5.15.9
PyQt5-sip                     12.12.2
PyQtWebEngine                 5.15.4
pyrsistent                    0.19.3
PySocks                       1.7.1
pyspark                       3.3.0
pyspnego                      0.9.1
pytest                        7.4.3
python-dateutil               2.8.2
python-decouple               3.8
python-dotenv                 1.0.0
python-json-logger            2.0.7
python-lsp-black              1.3.0
python-lsp-jsonrpc            1.1.2
python-lsp-server             1.7.4
python-slugify                8.0.1
pytoolconfig                  1.2.5
pytz                          2023.3.post1
PyWavelets                    1.4.1
pyxdg                         0.28
PyYAML                        6.0.1
pyzmq                         25.1.1
QDarkStyle                    3.1
qstylizer                     0.2.2
QtAwesome                     1.2.3
qtconsole                     5.4.4
QtPy                          2.4.1
referencing                   0.30.2
regex                         2023.10.3
requests                      2.31.0
requests-aws4auth             1.2.3
requests-kerberos             0.14.0
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rich                          13.6.0
rope                          1.10.0
rpds-py                       0.10.6
rsa                           4.7.2
Rtree                         1.1.0
ruamel.yaml                   0.18.2
ruamel.yaml.clib              0.2.7
ruamel-yaml-conda             0.15.80
s3fs                          0.4.2
s3transfer                    0.7.0
safetensors                   0.4.1
sagemaker                     2.196.0
sagemaker-pyspark             1.4.5
schema                        0.7.5
scikit-image                  0.22.0
scikit-learn                  1.3.2
scipy                         1.11.3
seaborn                       0.13.0
SecretStorage                 3.3.3
Send2Trash                    1.8.2
setuptools                    68.2.2
shap                          0.43.0
sip                           6.7.12
six                           1.16.0
slack-bolt                    1.18.1
slack-sdk                     3.26.1
slicer                        0.0.7
smdebug-rulesconfig           1.0.1
smmap                         5.0.1
sniffio                       1.3.0
snowballstemmer               2.2.0
snowflake-connector-python    3.4.1
sortedcontainers              2.4.0
soupsieve                     2.5
sparkmagic                    0.21.0
Sphinx                        7.2.6
sphinxcontrib-applehelp       1.0.7
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
sphinxcontrib-websupport      1.2.6
spyder                        5.4.5
spyder-kernels                2.4.4
SQLAlchemy                    2.0.22
st-annotated-text             4.0.1
stack-data                    0.6.2
statsmodels                   0.14.0
streamlit                     1.29.0
streamlit-aggrid              0.3.4.post3
streamlit-camera-input-live   0.2.0
streamlit-card                0.0.61
streamlit-embedcode           0.1.2
streamlit-extras              0.3.5
streamlit-faker               0.0.3
streamlit-image-coordinates   0.1.6
streamlit-javascript          0.1.5
streamlit-keyup               0.2.0
streamlit-toggle-switch       1.0.2
streamlit-vertical-slider     1.0.2
sympy                         1.12
tables                        3.9.1
tblib                         1.7.0
tenacity                      8.2.3
terminado                     0.17.1
testpath                      0.6.0
text-unidecode                1.3
textdistance                  4.5.0
threadpoolctl                 3.2.0
three-merge                   0.1.1
tifffile                      2023.9.26
tiktoken                      0.5.2
tinycss2                      1.2.1
tokenizers                    0.15.0
toml                          0.10.2
tomli                         2.0.1
tomlkit                       0.12.1
toolz                         0.12.0
tornado                       6.3.3
tqdm                          4.66.1
traitlets                     5.12.0
transformers                  4.35.2
trulens-eval                  0.18.2
typed-ast                     1.5.5
types-python-dateutil         2.8.19.14
typing_extensions             4.5.0
typing-inspect                0.8.0
typing-utils                  0.1.0
tzdata                        2023.3
tzlocal                       5.2
ujson                         5.8.0
unicodedata2                  15.1.0
uri-template                  1.3.0
urllib3                       1.26.18
validators                    0.22.0
watchdog                      3.0.0
wcwidth                       0.2.8
webcolors                     1.13
webencodings                  0.5.1
websocket-client              1.6.4
Werkzeug                      3.0.1
whatthepatch                  1.0.5
wheel                         0.41.2
widgetsnbextension            4.0.9
wrapt                         1.15.0
wurlitzer                     3.0.3
XlsxWriter                    3.1.7
xxhash                        3.4.1
xyzservices                   2023.10.1
yapf                          0.40.1
yarl                          1.9.2
zict                          3.0.0
zipp                          3.17.0
zope.event                    5.0
zope.interface                6.1
```

@Josemaria123 I'm not able to reproduce this issue on Python3.10. Does reinstalling trulens-eval seem to help?
`pip uninstall trulens-eval -y && pip install trulens-eval`

If not, can you display the contents of this file on your machine (from your traceback)?
`/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/trulens_eval/feedback/provider/base.py`



``> @Josemaria123 I'm not able to reproduce this issue on Python3.10. Does reinstalling trulens-eval seem to help? `pip uninstall trulens-eval -y && pip install trulens-eval`
> 
> If not, can you display the contents of this file on your machine (from your traceback)? `/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/trulens_eval/feedback/provider/base.py`

The pip uninstall / install didn't work. This are the contents of the file that you mention:
```
from abc import ABC
from abc import abstractmethod
import logging
from typing import Dict, Optional, Sequence, Tuple, Union
import warnings

from trulens_eval.feedback import prompts
from trulens_eval.feedback.provider.endpoint.base import Endpoint
from trulens_eval.utils.generated import re_0_10_rating
from trulens_eval.utils.pyschema import WithClassInfo
from trulens_eval.utils.serial import SerialModel

logger = logging.getLogger(__name__)


class Provider(SerialModel, WithClassInfo):

    class Config:
        arbitrary_types_allowed = True

    endpoint: Optional[Endpoint]

    def __init__(self, name: str = None, **kwargs):
        # for WithClassInfo:
        kwargs['obj'] = self

        super().__init__(name=name, **kwargs)


class LLMProvider(Provider, ABC):

    model_engine: str

    def __init__(self, *args, **kwargs):
        # NOTE(piotrm): pydantic adds endpoint to the signature of this
        # constructor if we don't include it explicitly, even though we set it
        # down below. Adding it as None here as a temporary hack

        # TODO: why was self_kwargs required here independently of kwargs?
        self_kwargs = dict()
        self_kwargs.update(**kwargs)

        super().__init__(
            **self_kwargs
        )  # need to include pydantic.BaseModel.__init__

    @abstractmethod
    def _create_chat_completion(
        self,
        prompt: Optional[str] = None,
        messages: Optional[Sequence[Dict]] = None,
        **kwargs
    ) -> str:
        """
        Chat Completion Model

        Returns:
            str: Completion model response.
        """
        # text
        pass

    def _find_relevant_string(self, full_source: str, hypothesis: str) -> str:
        return self.endpoint.run_me(
            lambda: self._create_chat_completion(
                prompt=str.format(
                    prompts.SYSTEM_FIND_SUPPORTING,
                    prompt=full_source,
                ) + "\n" + str.
                format(prompts.USER_FIND_SUPPORTING, response=hypothesis)
            )
        )

    def _summarized_groundedness(self, premise: str, hypothesis: str) -> float:
        """
        A groundedness measure best used for summarized premise against simple
        hypothesis. This LLM implementation uses information overlap prompts.

        Args:
            premise (str): Summarized source sentences.
            hypothesis (str): Single statement setnece.

        Returns:
            float: Information Overlap
        """
        return re_0_10_rating(
            self.endpoint.run_me(
                lambda: self._create_chat_completion(
                    prompt=str.format(
                        prompts.LLM_GROUNDEDNESS,
                        premise=premise,
                        hypothesis=hypothesis,
                    )
                )
            )
        ) / 10.0

...
```

Now it works. I don't know what happened but I deleted all the modules of my env and install only trulens-eval. Now it works well.