Repository navigation
Python: provide actionable install-extra errors for missing connector dependencies (#14328) - #14659
Conversation
|
Hi Eduard van Valkenburg (@eavanvalkenburg), Could you please take a look at this pull request when you have a moment? It addresses #14328 by adding actionable install-extra error messages for optional connector dependencies ( All Ruff checks and unit tests are passing cleanly. Thank you! |
Eduard van Valkenburg (eavanvalkenburg)
left a comment
There was a problem hiding this comment.
The new Chroma test fails on Python 3.12; see the inline comment. The pre-commit job also rewrites the redundant parentheses around the new Chroma error-message strings with pyupgrade. Please apply the existing hooks and address the Python 3.12 import before rerunning CI.
|
|
||
| def test_chroma_memory_store_missing_dependency(): | ||
| """ChromaMemoryStore raises ServiceInitializationError naming semantic-kernel[chroma].""" | ||
| from semantic_kernel.connectors.memory_stores.chroma.chroma_memory_store import ( |
There was a problem hiding this comment.
This new test fails on Python 3.12 before reaching the missing-dependency assertion: importing ChromaMemoryStore raises ImportError: cannot import name 'deprecated' from 'warnings'. The module currently chooses warnings.deprecated for Python >=3.12, but that decorator was introduced in 3.13. Please correct that guard to >=3.13 (using typing_extensions.deprecated on 3.12) so this regression test works across the supported matrix. Confirmed in https://github.com/microsoft/semantic-kernel/actions/runs/40098737410/job/121530788066.
There was a problem hiding this comment.
Good catch. Updated the import guard in ChromaMemoryStore to sys.version_info >= (3, 13) so it falls back to yping_extensions.deprecated on Python 3.12. Also cleaned up the redundant parentheses around the error string to satisfy pyupgrade.
…ing in ChromaMemoryStore
|
Hi Eduard van Valkenburg (@eavanvalkenburg), I've pushed an update addressing both points:
The updates are ready for another review. Thank you for your time! |
Motivation and Context
Closes #14328
When optional connector dependencies (such as
transformers,torch,onnxruntime-genai, orchromadb) are not installed in the environment, callers could encounter abrupt module-level import errors or genericModuleNotFoundError/ImportErrorexceptions that did not clarify which Semantic Kernel extra needed to be installed.Specifically:
hf_prompt_execution_settings.pyattempted to loadtransformersunconditionally at the module level withouttry...except, crashing upon import when optional Hugging Face extras were omitted. Additionally,get_generation_config()importedGenerationConfigbefore verifying the optional dependency status.hf_text_completion.pyandhf_text_embedding.pyeagerly importedtorchandtransformersat the top level, preventing callers from importing or handling Hugging Face settings or services gracefully without pre-installed packages.OnnxGenAICompletionBaseandChromaMemoryStoreraised generic error messages that did not identify the specific Semantic Kernel install extra (semantic-kernel[onnx]andsemantic-kernel[chroma]).Description
transformersandtorchimports inhf_prompt_execution_settings.py,hf_text_completion.py, andhf_text_embedding.pywithtry...except (ImportError, ModuleNotFoundError).semantic-kernel[hugging_face]when attempting to instantiate uninstalled services or invokeget_generation_config().OnnxGenAICompletionBaselazy-import error message to specifypip install semantic-kernel[onnx]._generate_next_token.ChromaMemoryStoreto explicitly referencepip install semantic-kernel[chroma].tests/unit/connectors/test_optional_dependencies.pycovering:HuggingFacePromptExecutionSettingsboth with and withouttransformers.HuggingFaceTextCompletionandHuggingFaceTextEmbeddingwithout required extras.OnnxGenAICompletionBasewithoutonnxruntime-genai.ChromaMemoryStorewithoutchromadb.Contribution Checklist