Skip to content

Add a new chat_snowflake() provider#258

Merged
atheriel merged 1 commit into
tidyverse:mainfrom
atheriel:chat-snowflake
Jan 22, 2025
Merged

Add a new chat_snowflake() provider#258
atheriel merged 1 commit into
tidyverse:mainfrom
atheriel:chat-snowflake

Conversation

@atheriel

Copy link
Copy Markdown
Collaborator

This commit adds chat_snowflake() for chatting with models hosted through Snowflake's Cortex LLM REST API:

chat <- chat_snowflake()
chat$chat("Tell me a joke in the form of a SQL query.")

On the backend it looks fairly similar to OpenAI, though it has only the basic textual functionality, and so many advanced ellmer features are not available. I also reused quite a bit of the credential support and utilities from chat_cortex(), so this commit also includes some minor refactoring of that provider.

Right now the default model for chat_snowflake() is Llama 3.1 70B, but we should change it to Claude 3.5 Sonnet when that gets rolled out more widely; it's only available to customers in the us-west-1 Snowflake region right now.

Unit tests are included.

Part of #255.

Comment thread R/provider-cortex.R
Comment thread R/provider-snowflake.R
Comment thread R/provider-snowflake.R
req <- request(provider@base_url)
req <- req_url_path_append(req, "/api/v2/cortex/inference:complete")
creds <- cortex_credentials(provider@account, provider@credentials)
req <- req_headers(req, !!!creds, .redact = "Authorization")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about always redacting Authorization in httr2. What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That kind of makes sense to me, yeah.

This commit adds `chat_snowflake()` for chatting with models hosted
through Snowflake's [Cortex LLM REST API][0]:

    chat <- chat_snowflake()
    chat$chat("Tell me a joke in the form of a SQL query.")

On the backend it looks fairly similar to OpenAI, though it has only the
basic textual functionality, and so many advanced ellmer features are
not available. I also reused quite a bit of the credential support and
utilities from `chat_cortex()`, so this commit also includes some minor
refactoring of that provider.

Right now the default model for `chat_snowflake()` is Llama 3.1 70B, but
we should change it to Claude 3.5 Sonnet when that gets rolled out more
widely; it's only available to customers in the `us-west-1` Snowflake
region right now.

Unit tests are included.

Part of tidyverse#255.

[0]: https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-llm-rest-api

Signed-off-by: Aaron Jacobs <aaron.jacobs@posit.co>
@atheriel

Copy link
Copy Markdown
Collaborator Author

@hadley I don't have write permissions to merge, if you were waiting for me to.

@hadley

hadley commented Jan 22, 2025

Copy link
Copy Markdown
Member

You do now 😄 Feel free to add yourself to the authors too, if you want.

@atheriel

Copy link
Copy Markdown
Collaborator Author

image

Still locked out, I'm afraid.

@hadley

hadley commented Jan 22, 2025

Copy link
Copy Markdown
Member

You have to accept the invite 😄

@atheriel atheriel merged commit 7a4855e into tidyverse:main Jan 22, 2025
@atheriel

Copy link
Copy Markdown
Collaborator Author

🤦

@atheriel atheriel deleted the chat-snowflake branch January 22, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants