run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.75k stars 5.27k forks source link

[Bug]: MistralAI as_chat_engine() broken after upgrade to llama-index-llms-mistralai 0.1.5 #11926

Closed fariazz closed 8 months ago

fariazz commented 8 months ago

Bug Description

After upgrading llama-index-llms-mistralai to 0.1.5, the most simple chat example for Mistral models no longer works.

Version

llama-index-core 0.10.19, llama-index-llms-mistralai 0.1.5

Steps to Reproduce

Run this code using llama-index-llms-mistralai version 0.1.5:

from llama_index.core import Document, VectorStoreIndex, Settings
from llama_index.core.llms import ChatMessage
from llama_index.llms.mistralai import MistralAI

# Evaluator
llm = MistralAI(model="mistral-tiny")
Settings.llm = llm

# Index
document = Document.example()
index = VectorStoreIndex([document])
engine = index.as_chat_engine(
    chat_mode='context',
)

# Test case
query = "tell me a joke"
response = engine.chat(message=query)
print(response)

Expected: completion of the script, printing output

Observed: script doesn't run, error:

Traceback (most recent call last):
  File "c:\projects\mistralexample\issue_mistralai.py", line 18, in <module>
    response = engine.chat(message=query)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\callbacks\utils.py", line 41, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\chat_engine\context.py", line 172, in chat
    chat_response = self._llm.chat(all_messages)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\llms\callbacks.py", line 93, in wrapped_llm_chat
    f_return_val = f(_self, messages, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\llms\mistralai\base.py", line 176, in chat
    from mistralai.client import ChatMessage as mistral_chatmessage
ImportError: cannot import name 'ChatMessage' from 'mistralai.client' (c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\mistralai\client.py)  

Output of pip list:

Package                            Version
---------------------------------- ----------
aiohttp                            3.9.3
aiosignal                          1.3.1
annotated-types                    0.6.0
anyio                              4.2.0
attrs                              23.2.0
azure-common                       1.1.28
azure-core                         1.30.0
azure-identity                     1.15.0
azure-mgmt-core                    1.4.0
azure-mgmt-media                   10.2.0
azure-storage-blob                 12.19.0
beautifulsoup4                     4.12.3
blinker                            1.7.0
bs4                                0.0.2
cachetools                         5.3.2
certifi                            2024.2.2
cffi                               1.16.0
charset-normalizer                 3.3.2
click                              8.1.7
colorama                           0.4.6
cryptography                       42.0.3
cssselect                          1.2.0
dataclasses-json                   0.6.4
Deprecated                         1.2.14
dirtyjson                          1.0.8
distro                             1.9.0
dnspython                          2.6.1
email_validator                    2.1.1
feedfinder2                        0.0.4
feedparser                         6.0.11
filelock                           3.13.1
Flask                              3.0.2
frozenlist                         1.4.1
fsspec                             2024.2.0
google-ai-generativelanguage       0.4.0
google-api-core                    2.17.1
google-auth                        2.28.1
google-generativeai                0.3.2
googleapis-common-protos           1.62.0
greenlet                           3.0.3
grpcio                             1.62.0
grpcio-status                      1.62.0
h11                                0.14.0
httpcore                           1.0.2
httpx                              0.25.2
huggingface-hub                    0.21.4
idna                               3.6
isodate                            0.6.1
itsdangerous                       2.1.2
jieba3k                            0.35.1
Jinja2                             3.1.3
joblib                             1.3.2
jwt                                1.3.1
llama-index-agent-openai           0.1.5
llama-index-core                   0.10.19
llama-index-embeddings-huggingface 0.1.4
llama-index-embeddings-openai      0.1.6
llama-index-llms-mistralai         0.1.5
llama-index-llms-openai            0.1.9
llama-index-readers-file           0.1.9
llamaindex-py-client               0.1.13
lxml                               5.1.0
MarkupSafe                         2.1.5
marshmallow                        3.21.1
mistralai                          0.1.6
mpmath                             1.3.0
msal                               1.27.0
msal-extensions                    1.1.0
msrest                             0.7.1
multidict                          6.0.5
mypy-extensions                    1.0.0
nest-asyncio                       1.6.0
networkx                           3.2.1
newspaper3k                        0.2.8
nltk                               3.8.1
numpy                              1.26.4
oauthlib                           3.2.2
openai                             1.14.0
orjson                             3.9.15
packaging                          23.2
pandas                             2.2.1
pillow                             10.2.0
pip                                24.0
portalocker                        2.8.2
proto-plus                         1.23.0
protobuf                           4.25.3
pyarrow                            15.0.1
pyasn1                             0.5.1
pyasn1-modules                     0.3.0
pycparser                          2.21
pydantic                           2.6.1
pydantic_core                      2.16.2
PyJWT                              2.8.0
PyMuPDF                            1.23.26
PyMuPDFb                           1.23.22
pypdf                              4.1.0
python-dateutil                    2.8.2
python-http-client                 3.3.7
pytz                               2024.1
pywin32                            306
PyYAML                             6.0.1
regex                              2023.12.25
requests                           2.31.0
requests-file                      2.0.0
requests-oauthlib                  1.3.1
rsa                                4.9
safetensors                        0.4.2
sendgrid                           6.11.0
sgmllib3k                          1.0.0
six                                1.16.0
sniffio                            1.3.0
soupsieve                          2.5
SQLAlchemy                         2.0.28
starkbank-ecdsa                    2.2.0
striprtf                           0.0.26
sympy                              1.12
tenacity                           8.2.3
tiktoken                           0.6.0
tinysegmenter                      0.3
tldextract                         5.1.1
tokenizers                         0.15.2
torch                              2.2.1
tqdm                               4.66.1
transformers                       4.38.2
typing_extensions                  4.9.0
typing-inspect                     0.9.0
tzdata                             2024.1
urllib3                            2.2.0
Werkzeug                           3.0.1
wrapt                              1.16.0
yarl                               1.9.4

Relevant Logs/Tracbacks

Traceback (most recent call last):
  File "c:\projects\mistralexample\issue_mistralai.py", line 18, in <module>
    response = engine.chat(message=query)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\callbacks\utils.py", line 41, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\chat_engine\context.py", line 172, in chat
    chat_response = self._llm.chat(all_messages)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\core\llms\callbacks.py", line 93, in wrapped_llm_chat
    f_return_val = f(_self, messages, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\llama_index\llms\mistralai\base.py", line 176, in chat
    from mistralai.client import ChatMessage as mistral_chatmessage
ImportError: cannot import name 'ChatMessage' from 'mistralai.client' (c:\Users\my_username\AppData\Local\Programs\Python\Python312\Lib\site-packages\mistralai\client.py)  
logan-markewich commented 8 months ago

@fariazz I just published the fix to this.

pip install -U llama-index-llms-mistralai

fariazz commented 8 months ago

@logan-markewich thank you for the super fast action here! that fixed it!