mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
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:
24
src/crewai/llms/third_party/ai_suite.py
vendored
24
src/crewai/llms/third_party/ai_suite.py
vendored
@@ -1,13 +1,33 @@
|
|||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
import aisuite as ai
|
|
||||||
|
|
||||||
from crewai.llms.base_llm import BaseLLM
|
from crewai.llms.base_llm import BaseLLM
|
||||||
|
|
||||||
|
|
||||||
class AISuiteLLM(BaseLLM):
|
class AISuiteLLM(BaseLLM):
|
||||||
def __init__(self, model: str, temperature: Optional[float] = None, **kwargs):
|
def __init__(self, model: str, temperature: Optional[float] = None, **kwargs):
|
||||||
super().__init__(model, temperature, **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()
|
self.client = ai.Client()
|
||||||
|
|
||||||
def call(
|
def call(
|
||||||
|
|||||||
Reference in New Issue
Block a user