-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into cristi/logout-warnings
- Loading branch information
Showing
57 changed files
with
1,057 additions
and
143 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
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
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. |
Oops, something went wrong.