Issue importing Lark using SelfQueryRetriever #23961
-
Checked other resources
Commit to Help
Example Codefrom langchain.retrievers.self_query.base import SelfQueryRetriever
SelfQueryRetriever.from_llm(...) DescriptionI'm running in a Lambda environment where I keep getting the following stack-trace: [ERROR] ImportError: Cannot import lark, please install it with 'pip install lark'.
Traceback (most recent call last):
File "/var/task/src/services/handle-search-query/functions/handler.py", line 14, in main
return handler(event)
File "/var/task/src/services/handle-search-query/functions/handler.py", line 9, in handler
results = search(query)
File "/var/task/src/modules/ai.py", line 203, in search
video_retriever = SelfQueryRetriever.from_llm(
File "/opt/python/langchain/retrievers/self_query/base.py", line 323, in from_llm
query_constructor = load_query_constructor_runnable(
File "/opt/python/langchain/chains/query_constructor/base.py", line 361, in load_query_constructor_runnable
output_parser = StructuredQueryOutputParser.from_components(
File "/opt/python/langchain/chains/query_constructor/base.py", line 99, in from_components
ast_parse = get_parser(
File "/opt/python/langchain/chains/query_constructor/parser.py", line 173, in get_parser
raise ImportError( On the Lambda, I have attached a layer where my Python dependencies are available, including Lark. I was wondering why the # libs/langchain/langchain/chains/query_constructor/parser.py
try:
check_package_version("lark", gte_version="1.1.5")
from lark import Lark, Transformer, v_args
except ImportError:
def v_args(*args: Any, **kwargs: Any) -> Any: # type: ignore
"""Dummy decorator for when lark is not installed."""
return lambda _: None
Transformer = object # type: ignore
Lark = object # type: ignore
def get_parser(
allowed_comparators: Optional[Sequence[Comparator]] = None,
allowed_operators: Optional[Sequence[Operator]] = None,
allowed_attributes: Optional[Sequence[str]] = None,
) -> Lark:
"""Return a parser for the query language.
Args:
allowed_comparators: Optional[Sequence[Comparator]]
allowed_operators: Optional[Sequence[Operator]]
Returns:
Lark parser for the query language.
"""
# QueryTransformer is None when Lark cannot be imported.
if QueryTransformer is None:
raise ImportError(
"Cannot import lark, please install it with 'pip install lark'."
)
transformer = QueryTransformer(
allowed_comparators=allowed_comparators,
allowed_operators=allowed_operators,
allowed_attributes=allowed_attributes,
)
return Lark(GRAMMAR, parser="lalr", transformer=transformer, start="program") Thanks in advance for any help! System Infolangchain: v0.2.3 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
To resolve the Here are the steps to troubleshoot and resolve the issue:
By following these steps, you should be able to resolve the |
Beta Was this translation helpful? Give feedback.
-
@dosu could you pass this to a maintainer? |
Beta Was this translation helpful? Give feedback.
-
I found out the issue I raised here is Lambda related, so this discussion became irrelevant. |
Beta Was this translation helpful? Give feedback.
I found out the issue I raised here is Lambda related, so this discussion became irrelevant.