Get startedGet started for free

GenAI - Snowflake Cortex LLM Functions - Part II

1. GenAI - Snowflake Cortex LLM Functions - Part II

We just learned how to use Snowflake Cortex Complete inside a SELECT statement. Now we’re going to cover how you can give the model context when you can call Complete – specifically, how you can feed in the past history of your prompts and the responses you got. For this, let’s expand the worksheet so it fills the whole screen. That will make this easier to see. Okay, so let’s take a look at the code we’re about to run: SELECT SNOWFLAKE.CORTEX.COMPLETE( 'mistral-7b', -- the model you want to use [ {'role': 'system', 'content': 'Analyze this Snowflake review and determine the overall sentiment. Answer with just \"Positive\", \"Negative\", or \"Neutral\"' }, {'role': 'user', 'content': 'I love Snowflake because it is so simple to use.'} ], -- the array with the prompt history, and your new prompt {} -- An empty object of options (we're not specify additional options here) ) AS response; This might look confusing, but I promise it’s not bad at all. We’re still just doing two basic things: One, we’re telling Complete the name of the model we want it to use. Two, we’re giving it an array with our instructions (you can see it’s an array because we’re using brackets ‘[‘ ) Inside that array are objects (you can see that they are objects because we have the braces ‘{‘ ). Each object lists a role, and content. There are three possible roles – System, User, and Assistant. Typically the first role will be “System” (this is like the initial prompt you’re giving to get things started). Then you have user input. If we run this, we’ll see that it correctly identifies this review of Snowflake as positive. Okay, so now for the interesting part – Let’s add in that output as another object – we’ll specify the role as “assistant,” and for the content, we’ll put the exact same output we just received. Now let’s give it a new prompt – To do this, we add in another Object, and put the role as User, and then put our prompt as the content. Let’s ask for a generic elaboration, like: “Based on other information you know about Snowflake, explain why the reviewer might feel the way they do.” And we get a slightly more detailed response, and note how the LLM is bringing in other knowledge it has about Snowflake. That’s pretty cool. If you were to continue down this path, you’d probably see object after object, alternating between having the assistant role and the user role. Pretty cool. Okay, so that’s it for Complete! To recap, we did six things: One, we spent some time exploring Snowflake Cortex LLM functions in general by taking a close look at Snowflake Cortex Complete Two, we learned how to specify the model we’d like to use and feed a prompt to Complete to get a response Three, we learned how to use the Snowflake Cortex Summarize function Four, we listed a few of the models you can select from when you’re using Complete Five, we generated a table of responses by feeding a column to Complete And six, we learned how to get Complete to work with an array holding our previous prompt history As I mentioned in the GenAI Overview, Snowflake doesn’t restrict your GenAI workflows to LLM functions like Complete. You can pretty much get as sophisticated as you want with LLMs in Snowflake – the infrastructure is there for you. But I love what we covered here because LLM functions let you use LLMs in your normal SQL workflows, and they’re all ready to go. You don’t have to find a model, load it, manage it, or anything like that – Functions like Complete are ready for you to use out-of-the box. I think that’s very cool.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.