Remove Langchain Dependency #282
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request improves the handling of optional dependencies on
langchain_communitythroughout the codebase. The main changes ensure that the code can run even iflangchain_communityis not installed, by using dynamic imports and adding graceful fallbacks.Dependency management and import handling:
langchain_communityfrom the required dependencies inpyproject.toml, making it optional.src/agentlab/llm/llm_utils.pyandsrc/agentlab/llm/tracking.pyto useimportlib.util.find_specfor checking the presence oflangchain_community, and conditionally import related modules or set them toNoneif unavailable. [1] [2] [3] [4]Graceful degradation and error handling:
langchain_communityobjects (such asmessages_to_dictinllm_utils.pyand pricing functions intracking.py) to check for the presence of these dependencies and handle their absence gracefully, including logging warnings and returning empty results as needed. [1] [2] [3]Description by Korbit AI
What change is being made?
Remove the langchain dependency and make the code robust to operate without it by implementing conditional imports and handling import exceptions.
Why are these changes being made?
This change improves the modularity and flexibility of the code by avoiding a hard dependency on langchain, allowing the application to function without it if necessary. This approach anticipates scenarios where users might not have langchain installed and provides fallbacks for critical functionalities, ensuring a resilient system.