Open sfc-gh-clakkad opened 2 months ago
facing similar issue
facing similar issue..
I'm not sure why yet, but making _sp_session
a public field in the ChatSnowflakeCortex
model makes this problem go away.
Just replace _sp_session
with sp_session
everywhere in snowflake.py
The public variable gets initialized on calling ChatSnowflakeCortex
, but the internal variables initialization is not enforced (the one starting with _
) , renaming _sp_session
to sp_session
enforces the initialization of the variable, i.e., snowflake session gets created in this case.
Checked other resources
Example Code
Issue reproduced using the Snowflake Cortex integration tutorial on the official documentation here : https://python.langchain.com/v0.2/docs/integrations/chat/snowflake/
during generation at the line
chat.invoke(messages)
This is from the langchain-community package and not the core langchain.
Error Message and Stack Trace (if applicable)
` ... File ~/opt/anaconda3/envs/cortex_base/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py:624, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, run_id, kwargs) 621 for i, m in enumerate(messages): 622 try: 623 results.append( --> 624 self._generate_with_cache( 625 m, 626 stop=stop, 627 run_manager=run_managers[i] if run_managers else None, 628 kwargs, 629 ) 630 ) 631 except BaseException as e: 632 if run_managers:
File ~/opt/anaconda3/envs/cortex_base/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py:846, in BaseChatModel._generate_with_cache(self, messages, stop, run_manager, kwargs) 844 else: 845 if inspect.signature(self._generate).parameters.get("run_manager"): --> 846 result = self._generate( 847 messages, stop=stop, run_manager=run_manager, kwargs 848 ) 849 else: 850 result = self._generate(messages, stop=stop, **kwargs)
File ~/opt/anaconda3/envs/cortex_base/lib/python3.10/site-packages/langchain_community/chat_models/snowflake.py:220, in ChatSnowflakeCortex._generate(self, messages, stop, run_manager, **kwargs) 218 l_rows = self._sp_session.sql(sql_stmt).collect() 219 except Exception as e: --> 220 raise ChatSnowflakeCortexError( 221 f"Error while making request to Snowflake Cortex via Snowpark: {e}" 222 ) 224 response = json.loads(l_rows[0]["LLM_RESPONSE"]) 225 ai_message_content = response["choices"][0]["messages"]
ChatSnowflakeCortexError: Error while making request to Snowflake Cortex via Snowpark: 'NoneType' object has no attribute 'sql'`
Description
System Info
langchain==0.2.16 langchain-community==0.2.16 langchain-core==0.2.38 langchain-text-splitters==0.2.4
platform: mac python==3.10