| from strands.models.mistral import MistralModel |
| from strands import Agent |
| from config.settings import settings |
| import logging |
|
|
| logger = logging.getLogger(__name__) |
|
|
| class AIService: |
| """Centralized AI service for managing Mistral model instances""" |
| |
| _instance = None |
| _model = None |
| |
| def __new__(cls): |
| if cls._instance is None: |
| cls._instance = super(AIService, cls).__new__(cls) |
| return cls._instance |
| |
| @property |
| def model(self) -> MistralModel: |
| """Get or create the Mistral model instance (singleton pattern)""" |
| if self._model is None: |
| logger.info("Initializing Mistral model...") |
| self._model = MistralModel( |
| api_key=settings.MISTRAL_API_KEY, |
| model_id=settings.MISTRAL_MODEL_ID, |
| ) |
| return self._model |
| |
| def create_agent(self, tools, system_prompt: str) -> Agent: |
| """Create an Agent instance with the shared model""" |
| return Agent( |
| model=self.model, |
| tools=tools, |
| system_prompt=system_prompt |
| ) |
|
|
| |
| ai_service = AIService() |
|
|