DSPy: The framework for programming—not prompting—language models
Python
fix(dsp): update imports after mistral migration update
Aman Sharma8669785892e8
diff --git a/dsp/modules/mistral.py b/dsp/modules/mistral.pyindex 33a065ed9..a6865016c 100644--- a/dsp/modules/mistral.py+++ b/dsp/modules/mistral.py@@ -6,11 +6,8 @@ from dsp.modules.lm import LMfrom dsp.utils.settings import settingstry:- import mistralaifrom mistralai.client import MistralClient- from mistralai.exceptions import MistralAPIException- from mistralai.models.chat_completion import ChatCompletionResponse, ChatMessage- mistralai_api_error = MistralAPIException+ from mistralai.models.usermessage import UserMessageexcept ImportError:mistralai_api_error = Exception@@ -57,7 +54,9 @@ class Mistral(LM):super().__init__(model)if mistralai_api_error == Exception:- raise ImportError("Not loading Mistral AI because it is not installed. Install it with `pip install mistralai`.")+ raise ImportError(+ "Not loading Mistral AI because it is not installed. Install it with `pip install mistralai`."+ )self.client = MistralClient(api_key=api_key)@@ -76,14 +75,14 @@ class Mistral(LM):raw_kwargs = kwargskwargs = {**self.kwargs,- "messages": [ChatMessage(role="user", content=prompt)],+ "messages": [UserMessage(role="user", content=prompt)],**kwargs,}# Mistral disallows "n" argumentsn = kwargs.pop("n", None)- if n is not None and n > 1 and kwargs['temperature'] == 0.0:- kwargs['temperature'] = 0.7+ if n is not None and n > 1 and kwargs["temperature"] == 0.0:+ kwargs["temperature"] = 0.7response = self.client.chat(**kwargs)@@ -116,7 +115,6 @@ class Mistral(LM):return_sorted: bool = False,**kwargs,):-assert only_completed, "for now"assert return_sorted is False, "for now"diff --git a/dummy.csv b/dummy.csvnew file mode 100644index 000000000..cc183833a--- /dev/null+++ b/dummy.csv@@ -0,0 +1,3 @@+content,question,answer+"This is content 1","What is this?","This is answer 1"+"This is content 2","What is that?","This is answer 2"