From 47781173444d4d8b0239615db2211d6864e283f9 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 25 Mar 2025 10:07:31 -0700 Subject: [PATCH] Implement dynamic import and installation prompt for 'aisuite' package in AISuiteLLM class to ensure required dependencies are met at runtime. --- src/crewai/llms/third_party/ai_suite.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/crewai/llms/third_party/ai_suite.py b/src/crewai/llms/third_party/ai_suite.py index 78185a081..80ae1afb0 100644 --- a/src/crewai/llms/third_party/ai_suite.py +++ b/src/crewai/llms/third_party/ai_suite.py @@ -1,13 +1,33 @@ from typing import Any, Dict, List, Optional, Union -import aisuite as ai - from crewai.llms.base_llm import BaseLLM class AISuiteLLM(BaseLLM): def __init__(self, model: str, temperature: Optional[float] = None, **kwargs): super().__init__(model, temperature, **kwargs) + + try: + import aisuite as ai + except ImportError: + import click + + if click.confirm( + "You are missing the 'aisuite' package. Would you like to install it?" + ): + import subprocess + + try: + subprocess.run(["uv", "add", "aisuite"], check=True) + + import aisuite as ai + except subprocess.CalledProcessError as e: + raise ImportError(f"Failed to install 'aisuite' package: {str(e)}") + else: + raise ImportError( + "The 'aisuite' package is required for this functionality." + ) + self.client = ai.Client() def call(