llama-index llms cortex integration
Project description
LlamaIndex Llms Integration: Cortex
Overview
Integrate with Snowflake Cortex API. 3 ways to authenticate:
-
Snowpark Session object (recommended way) this allows authentication via Snowpark Container Services default token, via Oauth, password, private key, web browser, or any other method.
Guide to creating sessions: https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session
-
Path to a private key file. Encrypted private keys unsupported. For encrypted keys: use a Snowpark Session instead, with the 'private_key_file_pwd' parameter.
-
JWT token
Installation
pip install llama-index-llms-cortex
Example using a Private Key
import os
from llama_index.llms.cortex import Cortex
llm = Cortex(
model="llama3.2-1b",
user=os.environ["YOUR_SF_USER"],
account=os.environ["YOUR_SF_ACCOUNT"],
private_key_file=os.environ["PATH_TO_SF_PRIVATE_KEY"],
)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
Example Using a Session
import os
from snowflake.snowpark import Session
from llama_index.llms.cortex import Cortex
connection_parameters = {
"account": "<your snowflake account>",
"user": "<your snowflake user>",
"role": "<your snowflake role>",
"database": "<your snowflake database>",
"schema": "<your snowflake schema",
"warehouse": "<your snowflake warehouse>",
"authenticator": "JWT_AUTHENTICATOR",
}
session = Session.builder.configs(connection_parameters).create()
llm = Cortex(
model="llama3.2-1b",
user=os.environ["YOUR_SF_USER"],
account=os.environ["YOUR_SF_ACCOUNT"],
session=session,
)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
Connect in an SPCS environment
import os
from snowflake.snowpark import Session
from llama_index.llms.cortex import Cortex
from llama_index.llms.cortex import utils as cortex_utils
connection_parameters = {
"account": "<your snowflake account>",
"user": "<your snowflake user>",
"role": "<your snowflake role>",
"database": "<your snowflake database>",
"schema": "<your snowflake schema",
"warehouse": "<your snowflake warehouse>",
"token": cortex_utils.get_default_spcs_token(),
"authenticator": "JWT_AUTHENTICATOR",
}
session = Session.builder.configs(connection_parameters).create()
llm = Cortex(
model="llama3.2-1b",
user=os.environ["YOUR_SF_USER"],
account=os.environ["YOUR_SF_ACCOUNT"],
session=session,
)
completion_response = llm.complete(
"write me a haiku about a snowflake", temperature=0.0
)
print(completion_response)
TODO
1 snowflake token counting 2 Pull metadata for snowflake models from Snowflake official documentation (support ticket is out, they said they'll get back to me 4-20-2025)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_llms_cortex-0.2.0.tar.gz.
File metadata
- Download URL: llama_index_llms_cortex-0.2.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93231e30621616b917763c56f6671a1e34b5ab90909052c5a1edae8464cc4bcb
|
|
| MD5 |
8ba85943f3d41b5ac7653ce3a0e7e200
|
|
| BLAKE2b-256 |
b4bb3471d4d54064e225be63e15b782ed7e2ec8c2fba50a75c46f2cc6ba189c6
|
File details
Details for the file llama_index_llms_cortex-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_llms_cortex-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7a85c1e68e42795db250fa574ae0e48d7c561df81b649b8e4bb22eb55671ff
|
|
| MD5 |
14f028b649d8c56ec1ec7c74a6ef4c94
|
|
| BLAKE2b-256 |
eae66533ac2384e382fcb5dc522dbe62bda581ccd10704fd4e8a96b69f3b5f6d
|