# OpenAI

## Where to find

LLM Actions allow you to integrate with a large language model provider, for example, OpenAI. It can be found under the Integrate section of a specific scenario. Once you select 'Create an LLM action' you will then have the opportunity to create the LLM action of your choice. Select OpenAI to start setting up your OpenAI integration.

<figure><img src="https://3203401256-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdP6xFXXyeBbibro1Ywnq%2Fuploads%2FYfkNCh1WuPpdFA3QKPgI%2FScreenshot%202024-07-08%20at%2018.05.09.png?alt=media&#x26;token=7fb75649-474e-4af6-99b9-841af3abd5ad" alt=""><figcaption><p>Setting up an OpenAI integration via OpenDialog</p></figcaption></figure>

## What you'll need

To set up an integration between your LLM action, and an OpenAI model, you can either use OpenDialog's managed credentials, or your own credentials if you prefer. Selecting 'OpenDialog managed' means you will use a service directly managed by OpenDialog, and will not need to provide any credentials. If you would like to use your own credentials, you will need an OpenAI account.&#x20;

[How to create an OpenAI account](https://platform.openai.com/docs/quickstart)

If you are using your own credentials, unselect 'OpenDialog managed' and provide the following three elements:

* The **OpenAI API Key** is an API key associated with your OpenAI account. This can be found under the ["API keys"](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key) page in your OpenAI platform.
* The **OpenAI Organisation** is a unique identifier for your organisation within OpenAI. This can be found on the [general settings](https://platform.openai.com/settings/organization/general) page under "Organization ID".
* The **Model** is an identifier for the large language model that you would like to use. OpenAI provides a list of [pre-built model](https://platform.openai.com/docs/models/gpt-4o) identifiers, or you can use a custom fine-tuned model identifier associated with your organisation.

## How to use

### Setting up the OpenAI LLM action in OpenDialog

To set up your OpenAI LLM action, navigate to "Integrate", and select "LLM Actions" from the menu. Use the "Create an LLM action" button to set up a new LLM action.

<figure><img src="https://3203401256-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdP6xFXXyeBbibro1Ywnq%2Fuploads%2F9yKX3vnXLdgF9E6Mqz3F%2FScreenshot%202024-07-08%20at%2018.21.46.png?alt=media&#x26;token=fa07d289-c001-4cbc-a78b-cae388475714" alt=""><figcaption><p>Use the "Create an LLM action" button to set up a new OpenAI integration</p></figcaption></figure>

After providing a name and a description for your LLM action, select "Open AI" and provide the necessary account details to set up your integration. Hit 'Save' to set up this integration and use it within your scenario.

### Using the OpenAI LLM action in your scenario

To use your OpenAI LLM action in your scenario, you can add it to an intent in the Designer.

<figure><img src="https://3203401256-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdP6xFXXyeBbibro1Ywnq%2Fuploads%2FCs8UlpekeJ2QaAvBxzz5%2FScreenshot%202024-07-08%20at%2018.25.21.png?alt=media&#x26;token=a307b0f1-9787-466a-a698-b26d7f82344d" alt=""><figcaption><p>Select the desired intent in the designer and click "Add conditions, actions &#x26; attributes" to reveal the Action section</p></figcaption></figure>

When your scenario matches this intent, your LLM prompts will be sent to the language model and any output attributes will be populated.

To display the LLM's response text in your scenario, you will need to use the `llm_response` attribute (or any other desired output attributes) within a [message](https://docs.opendialog.ai/opendialog-platform/conversation-designer/message-design/message-editor). Within a message, create a new text block, set the text to `{llm_response}` and click "Save Message".

<figure><img src="https://3203401256-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdP6xFXXyeBbibro1Ywnq%2Fuploads%2FyEr2A5b1vu1tmMGx4ZLJ%2FScreenshot%202024-07-09%20at%2009.52.58.png?alt=media&#x26;token=b4734d6b-557a-4cfa-8b19-e52c33fd1a15" alt=""><figcaption><p>Create a text message using the LLM's response by using the <code>llm_response</code> attribute</p></figcaption></figure>

### Testing the OpenAI LLM action in your scenario

You can check if your action is successful by testing your conversation in the Preview (Test - Preview) and checking the user context on the right side of your screen. When you match the intent with the action then the user context will update to include `action_success: true` as well as any other [output attributes](https://docs.opendialog.ai/opendialog-platform/interpreters-and-natural-language-understanding/llm-actions/..#use-custom-output-attributes), such as `llm_response`.
