Fix import error handling for optional chromadb dependency using TYPE_CHECKING

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-26 19:12:30 +00:00
parent 86155b4590
commit 2b7b2993ca
2 changed files with 29 additions and 14 deletions

View File

@@ -6,6 +6,13 @@ import os
import shutil
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
if TYPE_CHECKING:
import chromadb
import chromadb.errors
from chromadb.api import ClientAPI
from chromadb.api.types import OneOrMany
from chromadb.config import Settings
else:
try:
import chromadb
import chromadb.errors

View File

@@ -6,11 +6,19 @@ import shutil
import uuid
from typing import TYPE_CHECKING, Any, Dict, List, Optional
if TYPE_CHECKING:
import chromadb
from chromadb.api import ClientAPI
from chromadb.config import Settings
else:
try:
import chromadb
from chromadb.api import ClientAPI
from chromadb.config import Settings
except ImportError:
chromadb = None
ClientAPI = None
Settings = None
raise ImportError(
"ChromaDB is not installed. Please install it with `pip install crewai[chromadb]`."
)