- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 02-04-2023 07:54 AM
It's time to integrate ServiceNow with ChatGPT. Hope it will help you.
Reference links:
- Endpoint, headers and JSON link: https://platform.openai.com/docs/api-reference/making-requests
Refer below:
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
- API key Creation Link: Need to create API key using below link and use it on header.
https://platform.openai.com/account/api-keys
Refer below:
Below are the 3 steps required to complete this integration.
1. Create a ChatGPT table with Question, Answer, Request, Response, Status code are string fields.
2. Create REST Message and Post HTTP method to update the data on ServiceNow.
3. Create Async business rule and use given script and give your names.
Step 1. Create ChatGPT table and below are the fields which I have created. Create your own fields.
Step 2: REST Message and Post HTTP method with No authentication on
Note: Authorization should be Bearer YOUR_API_KEY
Rest Message:
POST HTTP Method:
Content:
{
"model": "${model}",
"prompt": "${prompt}",
"max_tokens": ${max_tokens},
"temperature": ${temperature}
}
Step 3. Async Business rule insert/update on the ChatGPT table and give specific condition as below example.
Ex: Question changes(condition)
Script:
(function executeRule(current, previous /*null when async*/ ) {
try {
var r = new sn_ws.RESTMessageV2('ChatGPT', 'POST');//give your rest mesage name and method name
r.setStringParameterNoEscape('model', "text-davinci-003");
r.setStringParameterNoEscape('prompt', current.u_question);//give your field name
r.setStringParameterNoEscape('max_tokens', 100);
r.setStringParameterNoEscape('temperature', 0);
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);
current.u_request = r.getRequestBody();//it will give the request body
current.u_response = responseBody;
current.u_status_code = code;
current.u_answer = responseObj.choices[0].text;//it will give the text from response
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Screenshot:
Results: when you give question and Save on ChatGPT table then we will get the response.
Will get Response as below.
To make to easy and understandable to everyone, I have provided the all the details with screenshots.
- 46,224 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Maybe it's an idea to post the update set with the configuration and a little instruction on how to personalize it for those who deploy said update set (like pasting your own API key on the appropriate places)?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Please share technical document if you have
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have tried integrating chat gpt with service now When i tested it i am getting below response as error
Please find the Rest Message and Http Method and Business rule screen shots below.
Rest message :
HTTP Method :
BR:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @sushma9 ,
You need to populate the values for the variables you added in your HTTP Method screenshot:
Generate the variables and populate similar values as below:
Populate the variables with your requirements or anything for that matter as the BR you created will override but needs a sample:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You can find which model is appropriate for you here Models - OpenAI API
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @johndoh
I am going to use the model as dynamic model and i am defining them in BR. Do i Need to again use these values here and i have given those values here and tried as well but i am getting below error message response.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@sushma9 remove the quotes around 100 for the max tokens and the quotes around the 0 in temperature and test again. You should be successful then 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @sushma9 ,
max_tokens and temperature are integers give as below it will work not as string.
{
"model": "text-davinci-003",
"prompt": "What is Chat GPT?",
"max_tokens": 100,
"temperature": 0
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Pavankumar_1,
I have created API key with using https://platform.openai.com/account/api-keys.
I'm creating ChatGPT table.
Can you please tell about ChatGPT table and how to create that. Is this different table or same table.
Please help me to start and achieve it. I'm really very interested to do this integration using ChatGPT.
Regards,
Nivedita
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is this possible that we can integrate this without global search/outbound calls here? Want to answer inside servicenow instance by using chatGPT

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Next step, plug VA into the mix! Nice post!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @RodGallegos ,
Thanks @RodGallegos . I tried with VA as well.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Pavankumar_1 , I tried with VA it is working with REST calls. But I need to use CHATGPT for Private calls(basic contextual search inside the private instance) not for Global search. Is that Possible ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @taofeek93 ,
you are not proving any test value on variable so try to give some values some do test.
please refer below screen and try again
you will get the response as below
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
when I tested with the values i got this error message. can you help me please to solve it
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Fatima Zahra At ,
you have exceeded you limit. Please check below link for limits
https://platform.openai.com/account/limits
You have to buy credits or try with different account.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
gpt-3.5-turbo
Thanks for this example Pavan. It is a great starting point for tinkering with Generative AI. This is my first integration attempt with ServiceNow .. I've not succeeded yet but your example is pretty clear.
I'm not getting a message to say I've exceeded my current quota but I assume that is possibly because I need to pay now or create a new account. I'll give that a go.
Just FYI .. InstructGPT model "text-davinci-003" is deprecated and replaced with "gpt-3.5-turbo-instruct". There might be more suitable models for your purpose so check them out here: https://platform.openai.com/docs/models
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
What is the business value of this integration? It's not clear to me why I would do this.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
For the ones whowould like to make it work with gpt-3.5-turbo, here is the updated script after having updated the endpoints to "https://api.openai.com/v1/chat/completions":
(function executeRule(current, previous /*null when async*/ ) {
try {
var r = new sn_ws.RESTMessageV2('ChatGPT', 'POST');//give your rest mesage name and method name
r.setStringParameterNoEscape('model', "gpt-3.5-turbo"); //https://platform.openai.com/docs/guides/text-generation
var messages = [
{ role: "user", content: current.u_question.toString() } // Add the current question
];
var requestBody = {
model: "gpt-3.5-turbo",
max_tokens: 100,
temperature: 0,
messages: messages // Adding the messages array to the request body
};
r.setRequestBody(JSON.stringify(requestBody));
r.setStringParameterNoEscape('max_tokens', 100);
r.setStringParameterNoEscape('temperature', 0);
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);
current.u_request = r.getRequestBody();//it will give the request body
current.u_response = responseBody;
current.u_status_code = code;
//current.u_answer = responseObj.choices[0].text;//it will give the text from response
current.u_answer = responseObj.choices[0].message.content;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
} catch (ex) {
var message = ex.message;
}
})(current, previous);
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Pavankumar_1
First , thank you for this article. But with everything configured as required I am getting below error which is somewhat new to me. Can you please help me with the issue:
{
"error": {
"message": "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.",
"type": "insufficient_quota",
"param": null,
"code": "insufficient_quota"
}
}
Screenshots are also added.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Pavankumar_1& everyone,
New update on the post.
Replace the below to make integration works,
End Point: https://api.openai.com/v1/chat/completions
Content:
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "${content}"
}
]
}
Thanks,
Abdul Fathah
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
i have followed the above steps you mentioned and still unable to get response
could you please help me with that
i am attaching the configuration screenshots.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
this error i am getting
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Pavankumar_1 , Needed help i am getting this error.
and also i have attached 4 scrennshot of rest ,http method with br .
Please Help @Pavankumar_1
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Maybe that is related to the license, and you reached your limit. Try with other account
- « Previous
-
- 1
- 2
- Next »