In this blog post, I want to share some good practices for text-to-code in ServiceNow and some hints about prompt engineering.
The Model that is used (as of April 2024) is a fine-tuned version of StarCoder (model card).
StarCoder was trained using sentinel tokens to enable support for Fill In the Middle (FIM) style prompts, and it also expected prompts in a certain format for code generation and code completion.
This means if you create a new prompt, it will use the above code for the context.
Let's go into ServiceNow and create our first prompt. Almost all script editors in ServiceNow now support text-to-code. These steps are based on the assumption, that you already activated the Text-to-code capability in the Now Assist admin console.
Our first try:
To write a prompt you can use the comment function. Either you do the "//prompt" or for longer prompts, you can also use the "/* prompt here */".
Every output comes first as a draft (greyed out), so you can refine your prompt or accept it by pressing "tab".
Adding instructions to the prompt
I found out, that if you give the LLM instructions, you can get better results. I like to add the variable name to my prompt like this:
With that, you can incorporate name conventions into your prompts and get better results.
Fill in the middle
As the model was trained to support FIM, it will also use parts above the prompt, which can look like this:
Here I just referred to the array, and it knew I meant the fruits array.
Those are a couple of tricks I learned when using the Text-to-code features (Now Assist for Creator) over the last weeks. I will try to update this post if I learn more.
Happy coding :)
Top comments (0)