/
githubmirror
/
devika
Обзор
Документация
Войти
/
githubmirror
/
devika
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/llm/mistral_client.py
26 строк
999 B
Athulkrishna S
Update mistral_client.py (#633)
28 авг 2024, 19:51
Не верифицирован
28 авг 2024, 19:51
9efea57
Код
Авторство
О чём код?
import os from mistralai import Mistral, UserMessage # Updated import from mistralai from src.config import Config class MistralAi: def __init__(self): config = Config() 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()) # 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() } ], ) # Access the response using the new structure return chat_response.choices[0].message.content # Extract content from the response