Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Most code examples are written in Python, though the concepts can be applied in
- [How to get completions from Azure OpenAI](examples/azure/completions.ipynb)
- [How to get embeddings from Azure OpenAI](examples/azure/embeddings.ipynb)
- [How to fine-tune GPT-3 with Azure OpenAI](examples/azure/finetuning.ipynb)
- [How to use Dall-E image generation with Azure OpenAI](examples/azure/dalle.ipynb)
- Apps
- [File Q and A](apps/file-q-and-a/)
- [Web Crawl Q and A](apps/web-crawl-q-and-a)
Expand Down
143 changes: 143 additions & 0 deletions examples/azure/dalle.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Azure Dall-E image generation example\n",
"In this example we'll try to go over all operations needed to get image generation working using the Azure endpoints."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import openai"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup\n",
"For the following sections to work properly we first have to setup some things. Let's start with the `api_base`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"openai.api_base = '' # Please add your endpoint here\n",
"\n",
"# IMPORTANT: Dall-E is currently only available through api_version '2023-04-01-preview'. This version only supports Dall-E.\n",
"# If you want to use Dall-E and completions together, you have to override the api_version in the constructor as shown throughout the example.\n",
"openai.api_version = '2023-04-01-preview' # If this version is set globally completions and embeddings will not work without an override. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setup: Portal\n",
"Let's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"openai.api_type = 'azure'\n",
"openai.api_key = '' # Please add your api key here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Setup: Microsoft Active Directory Authentication\n",
"Let's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# from azure.identity import DefaultAzureCredential\n",
"\n",
"# default_credential = DefaultAzureCredential()\n",
"# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n",
"\n",
"# openai.api_type = 'azure_ad'\n",
"# openai.api_key = token.token"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Image generation\n",
"Now let's generate two images."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"openai.Image.create(\n",
" # IMPORTANT: Dall-E is currently only available through api version '2023-04-01-preview'. This version only supports Dall-E, no completions, etc..\n",
" # This means that if you want to use Dall-E and completions together, you have to override the api_version here.\n",
" api_version='2023-04-01-preview',\n",
" prompt='A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art',\n",
" size='1024x1024',\n",
" n=2\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"vscode": {
"interpreter": {
"hash": "3a5103089ab7e7c666b279eeded403fcec76de49a40685dbdfe9f9c78ad97c17"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}