Implement dynamic import and installation prompt for 'aisuite' package in AISuiteLLM class to ensure required dependencies are met at runtime.

This commit is contained in:
Lorenze Jay
2025-03-25 10:07:31 -07:00
parent 773da3f994
commit 4778117344

View File

@@ -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(