Skip to content

armgit / dspy

Public Imported from GitHub
0

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.py
index 33a065ed9..a6865016c 100644
--- a/dsp/modules/mistral.py
+++ b/dsp/modules/mistral.py
@@ -6,11 +6,8 @@ from dsp.modules.lm import LM
from dsp.utils.settings import settings
try:
- import mistralai
from 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 UserMessage
except 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 = kwargs
kwargs = {
**self.kwargs,
- "messages": [ChatMessage(role="user", content=prompt)],
+ "messages": [UserMessage(role="user", content=prompt)],
**kwargs,
}
# Mistral disallows "n" arguments
n = 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.7
response = 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.csv
new file mode 100644
index 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"