Integrate ChatGPT using flow #inSalesforce
1.New External Credential
OpenAI External Credential
Custom Auth Protocol
2.After logging in to OpenAI, click to view API keys and create a new secret key.
3. Copy the API Key you created, create custom header credential named Authorization, Value paste the API Key, Sequence - 1
4. Create Principal related to External Credential
ChatGPT 1 Named Principal - Identity Type
5.Create a new named credential and choose the external service
Open AI, URL:https://api.openai.com/v1/completions
Enabled for callouts
Open AI External Cred - Ext Cred.
Generate Auth Header - Checked
6. Create a new permission set ChatGPT
and select the OpenAI_External_Credential - ChatGPT... in the External Cred.
7.Create a screen flow and add action element and click Create HTTP Callout
Name it: ChatGPTService Named Cred. OpenAI
8. Configure Invocable Action:
ChatGPTAction, POST
9. Provide the sample Request-Response
{
"model": "text-davinci-003",
"prompt": "What is the capital city of France?",
"temperature": 0.7,
"max_tokens": 250
}
{
"warning": "Warning message.",
"id": "cmpl-7z1DK3tYzc1kLDJ8eAEuGmMTe1amU",
"object": "text_completion",
"created": 1694777030,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nParis.",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 4,
"total_tokens": 12
}
}
10. Create a screen flow to integrate ChatGPT with salesforcee
Add Screen with text input : Question Screen : Question
Create a new Apex-defined variable:
RequestBody_ChatGPT:
Apex defined, Apex Class: External Service_Chat....
Assign values to the Apex-defined variable: Assign Request Body
RequestBody_chatGPT>max,, equals 250
RequestBody_ChatGPT>model equals text-davinci-003
RequestBody_ChatGPT>temperature equals 0.7
RequestBody_ChatGPT>prompt equals Question(from Screen)
Action: CallChatGPT
Choose the Invocable action you created, choose apex defined variable that you assigned as request body
CallChatGPT, CharGPTService - External Service, POST...
Set Request Body: requestBody_ChatGPT
Assignment:Response Assignment
ChoicesOutput:
Apex Defined, Service_ChatGPTService_CallChatGPT_OUT_2XX_choices, Allow multiple
ChoicesOutput equals Outputs from CallChatGPT>2XX>C...
Loop:
ChoicesOutput
Create Apex defined variable
Apex Defined, Class: Service_ChatGPTService_CallChatGPT_OUT...
Choice - create variable - Apex Defined - ExternalService.. CallChatGPT>2XX>C..
Assignment: Choice Assignment
Choice equals current Item from Loop..
Screen:
ChatGPT Answer
Choice.text
Other Example: The above way, it will help users solve cases. Build a record-triggered flow to automate the process as well
Visual: https://www.youtube.com/watch?v=EOefO72sD8o
Comments
Post a Comment