Generative Pipelines
What generative pipelines are and how they used AI to automate processes
const axios = require("axios");
const fs = require("fs");
// ChatGPT: Get AI-generated response and recommended action
async function getChatGptResponse(complaintText) {
const rules = "your_business_logic(best provided in if/then format)";
const acceptableActions = "refund, apologize, escalate"
const apiKey = "your_openai_api_key";
const prompt = `Analyze the following customer complaint based on the rules provided and provide a recommended action of the one of the following actions: "${acceptableActions}". Complaint: "${complaintText}". Only return recommended action.`;
const response = await axios.post(
"https://api.openai.com/v1/engines/davinci-codex/completions",
{
prompt: prompt,
max_tokens: 100,
n: 1,
stop: null,
temperature: 0.7,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
}
);
const aiResponse = response.data.choices[0].text.trim();
const recommendedAction = parseRecommendedAction(aiResponse);
return { aiResponse, recommendedAction };
}
// Parse the recommended action from the AI-generated response
function parseRecommendedAction(aiResponse) {
const possibleActions = ["refund", "apologize, escalate"];
let recommendedAction = "";
possibleActions.forEach((action) => {
if (aiResponse.toLowerCase().includes(action)) {
recommendedAction = action;
}
});
return recommendedAction;
}
// Main complaint resolution process
async function resolveComplaint(complaintText, customerId, chargeId) {
const { aiResponse, recommendedAction } = await getChatGptResponse(complaintText);
const caseId = await createSalesforceCase({ Subject: complaintText, CustomerId: customerId });
const emailContent = aiResponse;
if (recommendedAction === "refund") {
const refundAmount = calculateRefundAmount(chargeId);
await issueRefund(chargeId, refundAmount);
emailContent += `\n\nWe have issued a refund of ${refundAmount} to your account.`;
}
await sendEmail(customerId, "Complaint Resolution", emailContent);
}Last updated