@@ -13,7 +13,6 @@ class MistralAILLM(BaseLLM):
1313 """LLM for MistralAI. Requires a MistralAI API key from https://console.mistral.ai/api-keys/"""
1414
1515 _client : Any = PrivateAttr ()
16- _mistralai : Any = PrivateAttr ()
1716
1817 def __init__ (
1918 self ,
@@ -36,7 +35,7 @@ def __init__(
3635 if name is None :
3736 name = EncoderDefault .MISTRAL .value ["language_model" ]
3837 super ().__init__ (name = name )
39- self ._client , self . _mistralai = self ._initialize_client (mistralai_api_key )
38+ self ._client = self ._initialize_client (mistralai_api_key )
4039 self .temperature = temperature
4140 self .max_tokens = max_tokens
4241
@@ -46,11 +45,10 @@ def _initialize_client(self, api_key):
4645 :param api_key: The MistralAI API key.
4746 :type api_key: Optional[str]
4847 :return: The MistralAI client.
49- :rtype: MistralClient
48+ :rtype: Mistral
5049 """
5150 try :
52- import mistralai
53- from mistralai .client import MistralClient
51+ from mistralai import Mistral
5452 except ImportError :
5553 raise ImportError (
5654 "Please install MistralAI to use MistralAI LLM. "
@@ -61,12 +59,12 @@ def _initialize_client(self, api_key):
6159 if api_key is None :
6260 raise ValueError ("MistralAI API key cannot be 'None'." )
6361 try :
64- client = MistralClient (api_key = api_key )
62+ client = Mistral (api_key = api_key )
6563 except Exception as e :
6664 raise ValueError (
6765 f"MistralAI API client failed to initialize. Error: { e } "
6866 ) from e
69- return client , mistralai
67+ return client
7068
7169 def __call__ (self , messages : List [Message ]) -> str :
7270 """Call the MistralAILLM.
@@ -78,14 +76,9 @@ def __call__(self, messages: List[Message]) -> str:
7876 """
7977 if self ._client is None :
8078 raise ValueError ("MistralAI client is not initialized." )
81- chat_messages = [
82- self ._mistralai .models .chat_completion .ChatMessage (
83- role = m .role , content = m .content
84- )
85- for m in messages
86- ]
79+ chat_messages = [{"role" : m .role , "content" : m .content } for m in messages ]
8780 try :
88- completion = self ._client .chat (
81+ completion = self ._client .chat . complete (
8982 model = self .name ,
9083 messages = chat_messages ,
9184 temperature = self .temperature ,
0 commit comments