Exploring code generation
Summarize
Summary of Exploring code generation
ServiceNow’s Now Assist for Code, available as part of the Creator Pro Plus offering, empowers developers to efficiently create, edit, explain, and autocomplete code using AI-powered capabilities on the ServiceNow AI Platform. This tool supports two model providers: the Now LLM Service and Azure OpenAI, allowing developers to switch between them based on their requirements.
Show less
Key Features
- Code Generation: Developers describe the desired code functionality in the Code with Now Assist dialog box to receive AI-generated JavaScript code suggestions within the script editor on forms or Workflow Studio. These suggestions appear after the prompt but must be explicitly accepted to be added to the script.
- Code Autocomplete: While typing in the script editor, developers receive contextually relevant code suggestions that can be accepted with the tab key or rejected with the escape key. Suggestions appear after a brief delay and help speed up coding by providing real-time assistance.
- Code Explain and Summarize: Available only with the Azure OpenAI model provider, this feature offers comprehensive explanations and summaries of existing code, aiding understanding and documentation.
- AI-Generated Code Tracking: Lines created by AI are visually indicated within the editor, helping developers distinguish between AI-generated and manually edited code.
How It Works
To generate code, developers open the Code with Now Assist dialog, describe their coding goal, and trigger code suggestions. They review the AI-generated code and choose to accept or reject it. Accepted code is added to the script, while rejected code is discarded. Developers can refine prompts to generate improved suggestions. Code autocomplete provides inline suggestions as developers type, which can also be accepted or rejected.
To use these features, developers must have the now.assist.creator role assigned.
Benefits for ServiceNow Customers
- Improved Script Quality: AI-generated code helps reduce errors and improve consistency.
- Increased Developer Productivity: Automates repetitive coding tasks and accelerates script development, benefiting users with varying scripting experience.
- Better Code Understanding: Explanation and summarization features aid in comprehending complex scripts, improving maintenance and collaboration.
- Flexible AI Model Options: Choice between Now LLM Service and Azure OpenAI allows tailoring AI assistance to organizational preferences.
Learn about how AI-generated code can empower developers scripting on the ServiceNow AI Platform.
Now Assist for Code supports both the Now LLM Service and Azure OpenAI model providers.
- Code generation
- Code editing
- Code explain and summarize
- Code autocomplete
You can switch between Now LLM Services and Azure OpenAI. For more information, see Exploring code generation
Code generation overview
Now Assist for Creator activates the code generation skill. With code generation, you provide text describing the code to generate and get code suggestions in the JavaScript editor on forms in the ServiceNow AI Platform and in Script steps in Workflow Studio. Developers with varying levels of experience in scripting on the ServiceNow AI Platform can benefit from using code generation to get started writing custom scripts or iterate on scripts more efficiently.
To generate code suggestions, you describe the goal of the code to generate in the Code with Now Assist dialog box. The code suggestion appears in the lines following your prompt but isn’t added to your script until it's accepted.
Code generation workflow
- From the script editor, a developer opens the Code with Now Assist dialog box and describes the code that they want to generate.
- The developer triggers generating a code suggestion.
In the following example, a developer describes what they want the script to do in the Code with Now Assist dialog box. The code suggestion appears highlighted in the script editor.
- The developer reviews the AI-generated code suggestion and either accepts or rejects it.
- If the developer accepts it, the code is added to the script. The developer can make any necessary edits based on further review.
- If the developer rejects it, the code isn’t added to the script. The developer can rephrase the prompt to generate a new code suggestion.
In the following example, a line next to the line numbers indicates which code was created by AI and hasn't been edited. If you edit AI-generated code, the line indicator doesn’t appear for those lines of code.Figure 1. AI-generated code lines
Optionally, you can turn on code completion functionality to use code or single-shot prompts in script editors with Now Assist for code generation.
Code autocomplete overview
The autocomplete feature of Now Assist for Code provides you with contextually relevant code suggestions while typing.
Code autocomplete workflow
- A developer begins coding in the script editor.
Within a few seconds, contextually relevant code suggestions are displayed in grey.
- The developer reviews the AI-generated code suggestions and either accepts or rejects them:
- The developer must press the tab key to accept the suggestions.
If the developer accepts, the code is added to the script.
- The developer must press the esc key to reject the suggestions.
If the developer rejects, the code isn’t added. The developer can continue to code and wait for a few seconds for the suggestions to appear.
- The developer must press the tab key to accept the suggestions.
- After accepting the code suggestions, the developer selects Update to save the script.
Code explain and summarize overview
The code explain and summarize features are only available with the Azure OpenAI model provider.
The code explain and summarize features provide a summary of the code and a comprehensive explanation of its functionality.
Code generation benefits
| Benefit | Feature | Users |
|---|---|---|
| Improve quality of scripts, automate repetitive coding tasks, and reduce time spent searching for or recalling code | Text-to-code and code complete | Developers |
| Identify code generated by AI | Tracking AI-generated code | Developers, administrators |