DSPy: The framework for programming—not prompting—language models
Python
(feature) Adding support for Mistral AI's API
Franck Stephane Ndzomgae57194d8f78e
diff --git a/dsp/modules/__init__.py b/dsp/modules/__init__.pyindex eceabc3c4..737c7c795 100644--- a/dsp/modules/__init__.py+++ b/dsp/modules/__init__.py@@ -9,8 +9,8 @@ from .google import *from .gpt3 import *from .hf import HFModelfrom .hf_client import Anyscale, HFClientTGI, Together+from .mistral import *from .ollama import *from .pyserini import *from .sbert import *from .sentence_vectorizer import *-from .mistral import *diff --git a/dsp/modules/lm.py b/dsp/modules/lm.pyindex 40eab49fb..e01524cc1 100644--- a/dsp/modules/lm.py+++ b/dsp/modules/lm.py@@ -57,8 +57,8 @@ class LM(ABC):printed.append((prompt,- x['response'].choices- )+ x['response'].choices,+ ),)else:printed.append(diff --git a/dsp/modules/mistral.py b/dsp/modules/mistral.pyindex 7c36e0b80..6c9573cbf 100644--- a/dsp/modules/mistral.py+++ b/dsp/modules/mistral.py@@ -1,13 +1,13 @@from typing import Any, Optional+import backofffrom dsp.modules.lm import LMtry:from mistralai.client import MistralClient- from mistralai.models.chat_completion import ChatMessage- from mistralai.models.chat_completion import ChatCompletionResponsefrom mistralai.exceptions import MistralAPIException+ from mistralai.models.chat_completion import ChatCompletionResponse, ChatMessagemistralai_api_error = MistralAPIExceptionexcept ImportError:mistralai_api_error = Exception@@ -19,7 +19,7 @@ def backoff_hdlr(details):print("Backing off {wait:0.1f} seconds after {tries} tries ""calling function {target} with kwargs "- "{kwargs}".format(**details)+ "{kwargs}".format(**details),)@@ -40,7 +40,7 @@ class Mistral(LM):self,model: str = "mistral-medium-latest",api_key: Optional[str] = None,- **kwargs+ **kwargs,):"""Parameters@@ -60,7 +60,7 @@ class Mistral(LM):"model": model,"temperature": 0.17,"max_tokens": 150,- **kwargs+ **kwargs,}self.history: list[dict[str, Any]] = []@@ -108,7 +108,7 @@ class Mistral(LM):prompt: str,only_completed: bool = True,return_sorted: bool = False,- **kwargs+ **kwargs,):assert only_completed, "for now"