Python example on how to use the Snowflake Cortex LLM functions.
Important
Before you run snowflake_cortex_llm.py
, create an .env
file to set up your environment variables.
Your .env
file should contain the following environment variables:
SNOWFLAKE_ACCOUNT = "xxxxxxx-xxxxxxx"
SNOWFLAKE_USER = "xxxxx"
SNOWFLAKE_USER_PASSWORD = "xxxxx"
- Setting up Snowflake Cortex: We will set up Snowflake Cortex, a comprehensive platform within the Snowflake ecosystem designed for developing, deploying, and managing ML and AI applications. The steps include:
- Creating a Snowflake account
- Choosing the correct cloud provider
- Getting the Snowflake user and password for environment variables
- Getting the Snowflake account for environment variable
- Setting the Default Warehouse parameter
- Setting environment variables
- Installing the Snowflake SDK
-
Exploring Snowflake Cortex LLM functions: We will explore several functions provided by Snowflake Cortex to perform various LLM tasks. This includes:
Summarize()
: Generating a summary of a given textComplete()
: Providing text completions based on a promptExtractAnswer()
: Extracting answers to specific questions from the textSentiment()
: Analyzing the sentiment of the textTranslate()
: Translating text from one language to another
-
Running LLM functions: We will test the Snowflake Cortex LLM functions with sample text. This will demonstrate how to use these functions to perform real-world text analysis and processing tasks, showcasing their effectiveness and practical applications.
If you run snowflake_cortex_llm.py
, you should get an output:
Summarize() is experimental since 1.0.12. Do not use it in production.
Summarize() Snowflake Cortex LLM function result:
Recent advancements in artificial intelligence are revolutionizing industries like healthcare and finance, enhancing efficiency and accuracy. However, ethical concerns such as data privacy, bias, and job displacement arise. Global competition in AI research and development is intensifying, requiring international cooperation and regulation. It's crucial to foster ethical AI practices and collaboration for maximum benefits.Complete() is experimental since 1.0.12. Do not use it in production.
Complete() Snowflake Cortex LLM function result:
- Artificial Intelligence
- Advancements
- Revolutionized
- Industries
- Ethical Concerns
ExtractAnswer() is experimental since 1.0.12. Do not use it in production.
ExtractAnswer() Snowflake Cortex LLM function result:
[
{
"answer": "data privacy, algorithmic bias, and the potential for job displacement",
"score": 0.9978588
}
]Sentiment() is experimental since 1.0.12. Do not use it in production.
Sentiment() Snowflake Cortex LLM function result:
0.5044461Translate() is experimental since 1.0.12. Do not use it in production.
Translate() Snowflake Cortex LLM function result:
Die jüngsten Fortschritte in der Zusammenarbeit mit KI können verschiedene Branchen revolutionieren. Von der Gesundheitsversorgung bis hin zu Finanzmitteln steihen revolutioniegern KI-gestützte Lösungen die Effizienz und Genauigkeit. Im Gesundheitswesen wie Lösungen die Erd KI verwendet, um den vollständigen Ausgang von Patienten vorherzusagen, Behandigen Ausgang vodlungspläne zu personalisieren und sogar bei Operationen zu helfen. Finanzielle rationen zu helf Institutionen nutzen KI, um betrügerische Aktivitäten aufzuzeugen und verantwortn und verantwortungsvoll einzurichten, bieten persönliche Banking
OS:
- Windows
10
Dependencies:
- Python
3.11.8
- Snowflake Python SDK
0.8.0
- Dotenv
1.0.1