Skip to content

BisonITS/azure-openai-servicenow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Azure OpenAI Integration

This project provides a ServiceNow application to facilitate the integration between ServiceNow instances and Azure's OpenAI service. It enables the sending of prompts to Azure OpenAI and receiving responses, which can be utilized within ServiceNow for various purposes such as chatbots, automated customer support, and more.

Features

  • Easy Configuration: Set up your Azure OpenAI API key, endpoint, version, and deployment ID directly within the script.
  • Flexible Messaging: Supports adding user, assistant, and system messages to the context sent to Azure OpenAI.
  • Customizable Parameters: Adjust the behavior of the OpenAI model with parameters like maxTokens, temperature, topP, frequencyPenalty, and presencePenalty.
  • Context Management: Maintain a conversation context to make interactions with the AI more coherent and contextually aware.

Prerequisites

Before you can use this integration, you'll need:

  • An Azure account with access to OpenAI services.
  • A ServiceNow instance where you can create or modify Script Includes.

Setup

  1. Azure OpenAI Configuration: Ensure you have an Azure OpenAI API key, endpoint, API version, and deployment ID. These will be used to configure the script include to communicate with Azure OpenAI.

  2. Clone the repository: Clone the repository to your own Github account.

  3. Link the repository to your SN instance: Create a personal access token and store this in a SN credential record. More info from SN on this process here.

  4. Pull the source code: Once the connection is made you can pull the source code to your instance.

  5. System Properties: Ensure you set the following global system properties according to the values in your Azure OpenAI environment.

    • azure_openai.api_key
    • azure_openai.api_version
    • azure_openai.api_endpoint
    • azure_openai.deployment_id

Usage

A single question

To ask a question to the Azure OpenAI API you can do the following:

var azureOpenAI = new x_bits2_az_openai.AzureOpenAI();
gs.info(azureOpenAI.prompt('What is the capital of France?'));
// Output: The capital of Iceland is Reykjavik.

Adding to the prompt

Currently you can add things to the prompt like this:

var azureOpenAI = new x_bits2_az_openai.AzureOpenAI();
gs.info(azureOpenAI.prompt('My name is Jesse'));
// Output: Nice to meet you, Jesse! How may I assist you today?
gs.info(azureOpenAI.prompt('What is my name?'));
// Output: Your name is Jesse.

By default the class will save your previous prompts in an instance property called context. The context more or less corresponds to the conversation history.

If you want to disable this behavior you can set addPromptsToContext to false in the the config object:

var azureOpenAI = new x_bits2_az_openai.AzureOpenAI({
	addPromptsToContext: false
});
gs.info(azureOpenAI.prompt('My name is Jesse'));
// Output: Nice to meet you! How may I assist you today?
gs.info(azureOpenAI.prompt('What is my name?'));
// Output: I'm sorry, as an AI language model, I don't have access to personal information such as your name unless you provide it to me.

The API that is implemented is https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#chat-completions

Adding context before prompting

If you want to give the model some context before prompting you can do so as follows:

var azureOpenAI = new x_bits2_az_openai.AzureOpenAI();

azureOpenAI.addToContext({
	role: 'system',
	content:
		'Sie sind ein professioneller Servicedesk-Assistent für ein Unternehmen namens BitHawk. Sie kommunizieren über ServiceNow. Schreibe jeweils eine kurze Zusammenfassung des Incidents mit allen wichtigen Informationen (auf Deutsch), einer Liste mit wichtigen Anhaltspunkten und einen möglichen Lösungsvorschlag, falls du einen hast. Falls ein Lösungsvorschlag schwierig ist, dir Informationen fehlen oder es schlichtweg einfach keine Lösung gibt, dann lasse das Feld leer.\nFormatiere deine Antworten folgendermassen:\nZusammenfassung:\n...\n\nWichtige Anhaltspunkte:\n-...\n-...\n\nLösungsvorschlag:\n...'
});

azureOpenAI.prompt('Your prompt here');

References

The Github Repository

Customization

You can customize the behavior of the Azure OpenAI model by adjusting the parameters in the AzureOpenAI object, such as MAX_TOKENS, TEMPERATURE, TOP_P, etc., to fine-tune the AI's responses based on your requirements.

Contributing

Contributions to this project are welcome! Please fork the repository and submit a pull request with your enhancements or fixes.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published