How to Integrate GPT-3 API with Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 06:28 PM
🚀 Exciting News for ServiceNow Enthusiasts! 🚀
Discover the Next-Level Virtual Agent: Integrating GPT-3 API with ServiceNow! 🤖✨
🔎 What is GPT-3 API? Unleash the power of GPT-3 (Generative Pre-trained Transformer 3) API and elevate your ServiceNow virtual agent's capabilities to a whole new level. 🌐🧠
💡 Step-by-Step Integration Guide: Learn how to seamlessly integrate GPT-3 API with your ServiceNow platform. Follow our comprehensive step-by-step guide to enable natural language processing and advanced conversational interactions. 🚀
- 📌 Step 1: Create GPT account and access to developer UI https://platform.openai.com/docs/api-reference/making-requests
Note: The Script in this article may be different if GPT changes their API in the future version - 📌 Step 2: Set Up REST Message with below details:
Note: Authorization should be Bearer YOUR_API_KEY - This can be found under your profile image
Build your POST Method with below content:
{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "${content}"}],
"temperature": 0.7
}
📌 Step 3: Build your simple Flow for Virtual Chat.
In the script, you will trigger the REST we built eariler with input from user
try {
var question = vaInputs.question;
gs.info('Async Chat '+ responseBody)
var r = new sn_ws.RESTMessageV2('ChatGPT', 'POST');//give your rest mesage name and method name
r.setStringParameterNoEscape('content', question);//give your field name
var response = r.execute();
var responseBody = response.getBody();//it will give the response body
var code = response.getStatusCode();//get status code
var responseObj = JSON.parse(responseBody);
vaVars.u_request = r.getRequestBody();//it will give the request body
vaVars.u_response = responseBody;
vaVars.u_status_code = code;
var u_answer = responseObj.choices[0].message.content+'';//it will give the text from response
vaVars.u_answer = u_answer;
} catch (ex) {
var message = ex.message;
}
Note: Don't forget to train your Bot NLU so that it can realize the conversation entry.
Now it is ready to ask GPT
#ServiceNow #AI #GPT3 #VirtualAgent #AIIntegration #NaturalLanguageProcessing #ConversationalAI #DigitalTransformation
Cuong Phan
ServiceNow Technical Lead