Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(mistral): Upgrade mistralai dependency from 0.4.2 to 1.0.2 #1437

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

manubhardwaj
Copy link

Following the mistralai package upgrade instructions:

  • change .chat() to .chat.complete()
  • change MistralClient to Mistral (aliased as MistralAI)

Also corrected a problem with @backoff.on_exception where it needs object mistralai_api_error to exist.

@AnnaHubbard5
Copy link

This will solve the current error when trying to import dspy after pip install mistralai:

NameError: name 'mistralai_api_error' is not defined
File <command-182458377210475>, line 1
----> 1 import dspy
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-90e78ca5-1c45-4f00-bfc9-4301f2ce1c16/lib/python3.11/site-packages/dspy/__init__.py:1
----> 1 import dsp
      2 from dsp.modules.hf_client import ChatModuleClient, HFClientSGLang, HFClientVLLM, HFServerTGI
      4 from .predict import *
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-90e78ca5-1c45-4f00-bfc9-4301f2ce1c16/lib/python3.11/site-packages/dsp/__init__.py:1
----> 1 from .modules import *  # noqa
      2 from .primitives import *  # noqa
      3 from .adapters import *  # noqa
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-90e78ca5-1c45-4f00-bfc9-4301f2ce1c16/lib/python3.11/site-packages/dsp/modules/__init__.py:22
     20 from .hf_client import Anyscale, HFClientTGI, Together
     21 from .llama import *
---> 22 from .mistral import *
     23 from .ollama import *
     24 from .multi_openai import MultiOpenAI
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-90e78ca5-1c45-4f00-bfc9-4301f2ce1c16/lib/python3.11/site-packages/dsp/modules/mistral.py:31
     27         return False
     28     return True
---> 31 class Mistral(LM):
     32     """Wrapper around Mistral AI's API.
     33 
     34     Currently supported models include `mistral-small-latest`, `mistral-medium-latest`, `mistral-large-latest`.
     35     """
     37     def __init__(
     38         self,
     39         model: str = "mistral-medium-latest",
     40         api_key: Optional[str] = None,
     41         **kwargs,
     42     ):
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-90e78ca5-1c45-4f00-bfc9-4301f2ce1c16/lib/python3.11/site-packages/dsp/modules/mistral.py:101, in Mistral()
     95     self.history.append(history)
     97     return response
     99 @backoff.on_exception(
    100     backoff.expo,
--> 101     (mistralai_api_error),
    102     max_time=settings.backoff_time,
    103     on_backoff=backoff_hdlr,
    104     giveup=giveup_hdlr,
    105 )
    106 def request(self, prompt: str, **kwargs):
    107     """Handles retrieval of completions from Mistral AI whilst handling API errors."""
    108     prompt = prompt + "Follow the format only once !"

@arnavsinghvi11
Copy link
Collaborator

Thanks @manubhardwaj @AnnaHubbard5 !

@arnavsinghvi11 arnavsinghvi11 merged commit 05c3f90 into stanfordnlp:main Sep 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants