This repository has been archived by the owner on May 2, 2024. It is now read-only.
forked from forcedotcom/salesforcedx-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'forcedotcom:develop' into develop
- Loading branch information
Showing
32 changed files
with
930 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Apex Code Generation | ||
lang: en | ||
--- | ||
|
||
## Generate Apex Code | ||
|
||
Use the Einstein for Developers side bar to write a question or an instruction that describes the task for which you'd like to receive an Apex code suggestion and press **Ask**. Copy the code suggestion you received and paste it into an Apex file to use as "starter" code. | ||
|
||
![Sidebar code generation](../../../images/einstein-sidebar.png) | ||
|
||
## Use the Command Palette to Generate Apex Code | ||
|
||
You can quickly access Einstein for Developers from inside an Apex file in the VS Code editor. | ||
|
||
1. Open an existing Apex (`.cls`) file, or create one from the command palette by running the **SFDX: Create Apex Class** command. | ||
2. Put your cursor on the line in the file where you want the generated code to be placed. | ||
3. From the Command Palette, run **Einstein: Generate Code**. | ||
4. For your query, enter a description of the code that you want to generate. For example, “`Write a method that takes an account as a parameter and returns all contacts associated with that account.`” | ||
5. Review the code that Einstein generates, and then click **Accept**, **Try Again**, or **Clear**. | ||
|
||
Use our example prompts to learn how to get the most out of the generative AI tool. | ||
|
||
**Tip**: To access the **Einstein: Generate Code** command through hotkeys, press Cmd+r (macOS) or Ctrl+r (Windows or Linux). You can customize these shortcuts. See [Keyboard Shortcuts editor](https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-shortcuts-editor). | ||
|
||
|
||
You can customize these shortcuts. See [Keyboard Shortcuts editor](https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-shortcuts-editor). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
--- | ||
title: Example Prompts and Responses | ||
lang: en | ||
--- | ||
|
||
## Generated Code Quality | ||
|
||
As with all LLM-based products, the technology behind Einstein for Developers is still new. The generated output often requires editing to be customized for your individual project. Some responses aren't optimal. We'd love to hear feedback from you on the generated output through the History & Feedback Panel in the IDE. Your feedback is critical to the continuous training of our large language model (LLM) during the beta program. | ||
|
||
We strongly encourage you to let us know when you see examples of less optimal code, so that we can continue to improve generated responses. We recommend tools such as [Apex PMD](https://marketplace.visualstudio.com/items?itemName=chuckjonas.apex-pmd) (already in your Salesforce Extension Pack) and [Salesforce Code Analyzer](https://forcedotcom.github.io/sfdx-scanner/) to ensure the quality of your generated code. | ||
|
||
## Prompt Writing Tips | ||
|
||
Prompt writing is key to quality code generation. Here are some tips for improved prompt writing and a selection of sample prompts to start you on your generative AI code-assistance journey. | ||
|
||
| Original Prompt | Improved Prompt | | ||
| ------------------------------------------------------- | ------------------------------------------------------------------------------ | | ||
| Write Apex code that sorts the list of contacts. | Write Apex code that sorts the list of contacts alphabetically by last name. | | ||
| Write a method that adds two numbers. | Write a method that adds two numbers and returns the result. | | ||
| Write an Apex method that returns fields for an object. | Write an Apex method that accepts an SObject and returns a list of its fields. | | ||
|
||
## Example Prompts and Responses | ||
|
||
**Prompt:** Write an Apex method that accepts a list of sobjects and a field name and returns a set of non null field values. | ||
|
||
**Response:** | ||
|
||
``` | ||
public Set<String> getFieldValues(List<sObject> records, String fieldName) { | ||
Set<String> fieldValues = new Set<String>(); | ||
for (sObject record : records) { | ||
try { | ||
Object fieldValue = record.get(fieldName); | ||
if (fieldValue != null) { | ||
fieldValues.add((String) fieldValue); | ||
} | ||
} catch (Exception e) { | ||
system.debug('Error: ' + e.getMessage()); | ||
} | ||
} | ||
return fieldValues; | ||
} | ||
``` | ||
|
||
**Prompt:** Create an @invocable method that serializes an input list of sObjects and returns JSON. | ||
|
||
**Response:** | ||
|
||
``` | ||
@InvocableMethod(label='Create Account' description='Creates a new account with the specified name, number and symbol.' category='Account') | ||
public static List<String> createAccounts(List<Account> accounts) { | ||
List<String> response = new List<String>(); | ||
for (Account account : accounts) { | ||
String jsonAccount = JSON.serialize(account); | ||
response.add(jsonAccount); | ||
} | ||
return response; | ||
} | ||
``` | ||
|
||
**Prompt:** Write an Apex method that accepts product name as input and retrieves orderitems filtered on product name. | ||
|
||
**Response**: | ||
|
||
``` | ||
public List<OrderItem> getOrderItemsByProductName(String productName) { | ||
List<OrderItem> orderItems = [SELECT Description FROM OrderItem WHERE ProductCode = :productName LIMIT 50]; | ||
return orderItems; | ||
} | ||
``` | ||
|
||
**Prompt:** Write an Apex trigger to add the number of contacts associated with an account. | ||
|
||
``` | ||
trigger gptcontacttrigger on Account (after insert, after update) { | ||
List<Contact> listContacts = new List<Contact>(); | ||
for (Account acc : Trigger.new) { | ||
List<Contact> listaccContacts = [SELECT Id, Name, AccountId FROM Contact WHERE AccountId = :acc.Id]; | ||
if (acc.Contacts.size() < listaccContacts.size()) { | ||
acc.addError('Not enough contacts'); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Edit a Prompt and Regenerate Output | ||
|
||
A well designed prompt is key to getting a good response from Einstein. We encourage you to modify your prompts until you get Apex code that helps you complete your task at hand. When you use the `Einstein: Generate Code` command from the command palette, use the **Retry** and **Accept** options. In the sidebar, edit the prompt and click **Ask**. | ||
|
||
For example, the prompt, "Write code to provide the ability to update the FirstName for a list of users" generates this response. | ||
|
||
``` | ||
public with sharing class AccountService { | ||
public Account createAccount( String accountName, String accountNumber, String tickerSymbol ) { | ||
Account newAcct = new Account( | ||
Name = accountName, | ||
AccountNumber = accountNumber, | ||
TickerSymbol = accountNumber | ||
); | ||
return newAcct; | ||
} | ||
// Function to update the FirstName for a list of users | ||
public static List<User> updateFirstName(List<User> users, String newFirstName) { | ||
for (User u : users) { | ||
if (String.isNotBlank(u.FirstName)) { | ||
u.FirstName = newFirstName; | ||
} | ||
} | ||
return users; | ||
} | ||
``` | ||
|
||
This response is good, but you can edit the prompt to generate reusable code by creating a method. | ||
|
||
Click **Retry** and edit the prompt for more specific output. Update the prompt to say, "Write code to provide the ability to update the FirstName for a list of users as a method". This is the new response. | ||
|
||
``` | ||
public with sharing class AccountService { | ||
public Account createAccount( String accountName, String accountNumber, String tickerSymbol ) { | ||
Account newAcct = new Account( | ||
Name = accountName, | ||
AccountNumber = accountNumber, | ||
TickerSymbol = accountNumber | ||
); | ||
return newAcct; | ||
} | ||
} | ||
//This is a method that allows updating the FirstName for a list of users | ||
public static void updateFirstName(List<User> users) { | ||
for (User usr : users) { | ||
if (usr.FirstName != null) { | ||
usr.FirstName = 'New First Name'; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
If you like this output, click **Accept**. To update your prompt and regenerate new output, click **Retry**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: Einstein for Developers FAQ | ||
lang: en | ||
--- | ||
|
||
**What is Einstein for Developers?** | ||
|
||
Einstein for Developers is an AI-assisted tooling that is available as an easy-to-install VS Code extension built using Einstein, the secure, custom AI model from Salesforce. | ||
|
||
**What data has Einstein for Developers been trained on?** | ||
|
||
Einstein for Developers uses our trusted generative AI, CodeGen, to assist you through Salesforce development. CodeGen uses expertise that’s learned from anonymized code patterns. | ||
|
||
**Where can I learn more about Einstein for Developers Privacy and Data Protection?** | ||
|
||
See [Trusted AI from Salesforce](https://www.salesforceairesearch.com/trusted-ai). | ||
|
||
**Will my code ever be shared outside of my development environment?** | ||
|
||
No. Salesforce treats your code as confidential information under your Main Service Agreement (MSA) and doesn't disclose it to other Salesforce customers or anyone outside of Salesforce. Some of your code and entity schema can be used to improve Einstein for Developers and train CodeGen. Due to the nature of machine learning, Einstein for Developers can generate output that resembles code that was used to train the model. | ||
|
||
**I still have some security concerns, what if my code contains proprietary info?** | ||
|
||
Before using any code to label or build models, the research team scrubs all personally identifiable information (PII) and secrets info from the code. This information includes names, company names, phone numbers, address, and hard-coded API tokens. The data is encrypted at rest using customer-managed encryption keys. See [Customer-managed encryption keys (CMEK)](https://cloud.google.com/kms/docs/cmek). We also ensure that only Salesforce employees handle your code, not contractors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Einstein for Developers Feedback and Support | ||
lang: en | ||
--- | ||
|
||
## Feedback | ||
|
||
From the Command Palette run **Einstein: Show Prompt History** to open the Feedback console. Use 👍, 👎and comments for each prompt to provide feedback. To ask questions, request features, and post feedback, use the [Discussions](https://github.com/forcedotcom/Einstein-GPT-for-Developers/discussions) tab. | ||
|
||
## Support | ||
|
||
If you need support, file an [issue](https://github.com/forcedotcom/Einstein-GPT-for-Developers/issues) in the GitHub repo. Our team triages all incoming issues and gets back to you as fast as we can. | ||
|
||
**Note:** You need a github account to create an issue. If you don’t have a GitHub account, it’s easy (and free) to [sign up for one](https://github.com/join?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F&source=header-home). | ||
|
||
If you want to provide general feedback, request product enhancements, start discussions with other Einstein for Developers users or the product team, and share best practices, use the [Einstein for Developers Trailblazer Group](https://trailhead.salesforce.com/trailblazer-community/groups/0F94V000000oRJs?tab=discussion&sort=LAST_MODIFIED_DATE_DESC). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Einstein for Developers Glossary | ||
lang: en | ||
--- | ||
|
||
This glossary defines generative AI terms that appear throughout the Einstein documentation. | ||
|
||
**generative pre-trained transformer (GPT):** A family of language models developed by OpenAI that are generally trained on a large corpus of text data so they can generate human-like text. | ||
|
||
**grounding:** The process used to inject domain-specific knowledge and customer information into the prompt. | ||
human in the loop (HITL): A model that requires human interaction. | ||
|
||
**intent:** A user’s goal for interacting with the AI assistant. | ||
|
||
**large language model (LLM):** A language model consisting of a neural network with many parameters trained on large quantities of text. | ||
|
||
**prompt:** A natural language description of the task to be done. An input to the LLM. | ||
|
||
**prompt management:** The suite of tools used to build, manage, package, and share prompts, including the prompt templates and the prompt template store. | ||
|
||
**prompt template:** A string with placeholders/tags that can be replaced with custom values to generate a final prompt. The template includes the hyperparameters associated with that prompt and your choice of model/vendor if you're not using default values. | ||
|
||
**prompt chaining:** The method to select the right prompt engineering, which is a break-up of complex tasks into several intermediate steps, and then tie it back together in the hope that the AI generates a more concrete, customized, and thus better result. To get the best prompt, use the “Retry” option to regenerate code. | ||
|
||
**semantic retrieval:** A scenario where a large language model uses all the knowledge that exists in a customer's CRM data. Each CRM user has access to a personalized generative AI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Einstein for Developers (Beta) | ||
lang: en | ||
--- | ||
|
||
## Overview | ||
|
||
Quickly generate code suggestions using natural language instructions with Einstein for Developers to enhance developer productivity. Einstein for Developers is an AI-powered developer tool that's available as an easy-to-install Visual Studio Code extension built using CodeGen, the secure, custom AI model from Salesforce. The extension is available in the [VS Code](https://marketplace.visualstudio.com/vscode) and [Open VSX](https://open-vsx.org/) marketplaces. | ||
|
||
Einstein for Developers assists you throughout the Salesforce development process with expertise learned from anonymized code patterns. Our suite of AI-powered developer tools increases productivity and provides helpful assistance for complex coding tasks. We enforce development best practices with code generation and our suite of recommended static analysis and security scanning tools. With boilerplate code generation as its foundation, AI-assisted tooling also makes it easier for new developers to onboard to the Salesforce Platform. | ||
|
||
**Important**: This feature is a Beta Service. A customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at [Agreements and Terms](https://www.salesforce.com/company/legal/agreements/). | ||
|
||
## Current Capabilities | ||
|
||
This release of Einstein for Developers focuses on boilerplate Apex code generation from natural language prompts. This feature, used along with IntelliSense, makes Apex development tooling in Visual Studio Code even richer. Familiarity with Visual Studio Code is assumed. | ||
|
||
Use the extension in this release to generate boilerplate code from natural language instructions in a sidebar, so you can work with your editor and the tool side by side, without any interruptions to your workflow. You can also get code suggestions within an existing Apex class, trigger, or anonymous Apex file. Use the VS Code Command Palette to enter a prompt describing what you'd like to build and then generate code suggestions within your editor. | ||
|
||
**Note**: This tool uses generative AI, which can produce inaccurate or harmful responses. The output generated by AI is often nondeterministic. Before using the generated output, review it for accuracy and safety. You assume responsibility for how the outcomes of Einstein are applied to your organization. | ||
|
||
## Trusted Generative AI at Salesforce | ||
|
||
Einstein solutions are designed, developed, and delivered to be compliant with our five principles for trusted generative AI. | ||
|
||
**Accuracy**: We prioritize accuracy, precision, and recall in our models, and we back our model outputs up with explanations and sources whenever possible. We recommend that a human check model output before sharing with end users. | ||
|
||
**Safety:** We work to mitigate bias, toxicity, and harmful outputs in our models using industry-leading techniques. We protect the privacy of personally identifiable information (PII) in our data by adding guardrails around this data. | ||
|
||
**Honesty:** We ensure that the data we use in our models respects data provenance and that we have consent to use the data. | ||
|
||
**Empowerment:** Whenever possible, we design models to include human involvement as part of the workflow. | ||
|
||
**Sustainability:** We strive to build right-sized models that prioritize accuracy and to reduce our carbon footprint. | ||
|
||
Learn more at [Salesforce AI Research: Trusted AI](https://www.salesforceairesearch.com/trusted-ai). | ||
|
||
## The CodeGen Model | ||
|
||
**Important**: Einstein for Developers uses a customized LLM that is based on our open-source CodeGen model. This model that powers Einstein for Developers is the exclusive property of Salesforce. | ||
|
||
### CodeGen 2.5 | ||
|
||
A new member of the growing family of Salesforce CodeGen models, `CodeGen 2.5` shows that a small model, if trained well, can achieve surprisingly good performance. | ||
|
||
Key aspects of the `CodeGen 2.5` model version are: | ||
|
||
- It was released with state-of-the-art on `HumanEval` for 7B parameters. | ||
- At only 7B parameters, its performance is on par with code-generation models (`CodeGen1-16B`, `CodeGen2-16B`, `StarCoder-15B`) with more than 15B parameters. | ||
- It features robust infill sampling, that is, the model can “read” text on both the left and right side of the current cursor position. | ||
- It is optimized for fast sampling under `Flash` attention for serving completions. It is also optimized for local deployment to personal machines. | ||
- `CodeGen2.5` is permissively licensed in `Apache 2.0`. | ||
|
||
See the blog post [CodeGen2.5: Small, but Mighty](https://blog.salesforceairesearch.com/codegen25/). |
Oops, something went wrong.