Skip to content

Devika is the first open-source implementation of an Agentic Software Engineer. Initially started as an open-source alternative to Devin.

Python

Update mistral_client.py (#633)

Athulkrishna S9efea578c6aa
diff --git a/src/llm/mistral_client.py b/src/llm/mistral_client.py
index ee019c4..e4f3216 100644
--- a/src/llm/mistral_client.py
+++ b/src/llm/mistral_client.py
@@ -1,5 +1,5 @@
-from mistralai.client import MistralClient
-from mistralai.models.chat_completion import ChatMessage
+import os
+from mistralai import Mistral, UserMessage # Updated import from mistralai
from src.config import Config
@@ -7,16 +7,20 @@ from src.config import Config
class MistralAi:
def __init__(self):
config = Config()
- api_key = config.get_mistral_api_key()
- self.client = MistralClient(api_key=api_key)
+ api_key = config.get_mistral_api_key() # Retrieve API key using the existing Config class
+ self.client = Mistral(api_key=api_key) # Initialize Mistral client with the new class
def inference(self, model_id: str, prompt: str) -> str:
print("prompt", prompt.strip())
- chat_completion = self.client.chat(
- model=model_id,
- messages=[
- ChatMessage(role="user", content=prompt.strip())
+ # Use the new method for chat completion
+ chat_response = self.client.chat.complete(
+ model=model_id, # Model ID remains the same
+ messages=[ # Update to use dictionary format for messages
+ {
+ "role": "user",
+ "content": prompt.strip()
+ }
],
- temperature=0
)
- return chat_completion.choices[0].message.content
+ # Access the response using the new structure
+ return chat_response.choices[0].message.content # Extract content from the response