Using Snowflake Cortex LLMs with Crew AI

Hi , I wanted to use Snowflake Cortex LLM in Crew AI but did not find any way how do I do it , kindly help me with a short implementation example , because , Snowflake cortex LLMs are approved for us and we can only use those , so need help in setting up Crew AI agents which use Snowflake cortex LLMs

Following is the custom Langchain class code I tried

class SnowflakeCortexLLM:
def init(self, sp_session, model=“claude-3-5-sonnet”):
self.sp_session = sp_session
self.model = model

def call(self, prompt, **kwargs):
    """This method will be called by CrewAI"""
    try:
        # Properly escape single quotes in the prompt
        # This is critical for SQL injection prevention
        safe_prompt = prompt.replace("'", "''")
        
        # Execute Cortex function
        result_df = self.sp_session.sql(
            f"SELECT complete('{self.model}', '{safe_prompt}')"
        ).collect()
        
        # Extract response from result
        return result_df[0][0] if result_df else "No response from Cortex."
    except Exception as e:
        print(f"Error in Snowflake Cortex LLM: {e}")
        return f"Error: {str(e)}"

chat = SnowflakeCortexLLM(sp_session = session)

I used this chat in Crew AI agents ,
data_analyst_agent = Agent(
role=“Data Analyst”,
goal="Monitor and analyze market data in real-time "
“to identify trends and predict market movements.”,
backstory="Specializing in financial markets, this agent "
"uses statistical modeling and machine learning "
"to provide crucial insights. With a knack for data, "
"the Data Analyst Agent is the cornerstone for "
“informing trading decisions.”,
verbose=True,
allow_delegation=True,
llm = {
“provider”: “custom”,
“config”: chat
},
tools = [ simple_search_tool , web_scraper]
)

I have already added the connection parameters and authentication part to form connection with snowflake , I get the following error on using it

After authentication got the following error
:rocket: Crew: crew
└── :clipboard: Task: b8b498ad-76ee-49ec-8a60-705aeafe29b7
Status: Executing Task…

:rocket: Crew: crew
└── :clipboard: Task: b8b498ad-76ee-49ec-8a60-705aeafe29b7
Status: Executing Task…
└── :robot: Agent: Crew Manager
Status: In Progress

Agent: Crew Manager

Task: Continuously monitor and analyze market data for the selected stock (AAPL). Use statistical modeling and machine learning to identify trends and predict market movements.

:rocket: Crew: crew
└── :clipboard: Task: b8b498ad-76ee-49ec-8a60-705aeafe29b7
Status: Executing Task…
└── :robot: Agent: Crew Manager
Status: In Progress
└── :brain: Thinking…

:rocket: Crew: crew
└── :clipboard: Task: b8b498ad-76ee-49ec-8a60-705aeafe29b7
Status: Executing Task…
└── :robot: Agent: Crew Manager
Status: In Progress
└── :cross_mark: LLM Failed

╭─────────────────────────────────────────────────────────────────────────────────────────────────── LLM Error ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ :cross_mark: LLM Call Failed │
│ Error: litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=claude-3-5-sonnet │
│ Pass model as E.g. For ‘Huggingface’ inference endpoints pass in completion(model='huggingface/starcoder',..) Learn more: h │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

2025-03-19 19:09:56,229 - 16588 - llm.py-llm:751 - ERROR: LiteLLM call failed: litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=claude-3-5-sonnet
Pass model as E.g. For ‘Huggingface’ inference endpoints pass in completion(model='huggingface/starcoder',..) Learn more:
Error during LLM call: litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=claude-3-5-sonnet
Pass model as E.g. For ‘Huggingface’ inference endpoints pass in completion(model='huggingface/starcoder',..) Learn more: Providers | liteLLM
An unknown error occurred. Please check the details below.
Error details: litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=claude-3-5-sonnet
Pass model as E.g. For ‘Huggingface’ inference endpoints pass in completion(model='huggingface/starcoder',..) Learn more:
:rocket: Crew: crew
└── :clipboard: Task: b8b498ad-76ee-49ec-8a60-705aeafe29b7
Assigned to: Crew Manager
Status: :cross_mark: Failed
└── :robot: Agent: Crew Manager
Status: In Progress
└── :cross_mark: LLM Failed
╭────────────────────────────────────────────────────────────────────────────────────────────────── Task Failure ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Task Failed │
│ Name: b8b498ad-76ee-49ec-8a60-705aeafe29b7 │
│ Agent: Crew Manager │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────────────────────────────────────────────────────────────────────── Crew Failure ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Crew Execution Failed │
│ Name: crew │
│ ID: e03e7942-8e81-497d-9d3c-205c6fc891ac │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Traceback (most recent call last):
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

It seems that support for Snowflake is on the way in LiteLLM, which CrewAI depends on.