Skip to content

Commit

Permalink
Updating azure samples to point to the latest API version (openai#425)
Browse files Browse the repository at this point in the history
* Updating to use api version 2023-05-15

* Removing authoring references from azure samples as it is not yet present.
  • Loading branch information
glecaros authored May 22, 2023
1 parent 610f730 commit 828a6c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 684 deletions.
76 changes: 5 additions & 71 deletions examples/azure/chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
"metadata": {},
"outputs": [],
"source": [
"openai.api_version = '2023-03-15-preview'\n",
"openai.api_version = '2023-05-15'\n",
"openai.api_base = '' # Please add your endpoint here"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -61,7 +62,7 @@
"outputs": [],
"source": [
"openai.api_type = 'azure'\n",
"openai.api_key = '' # Please add your api key here"
"openai.api_key = '' # Please add your api key here\n"
]
},
{
Expand Down Expand Up @@ -112,55 +113,7 @@
"metadata": {},
"outputs": [],
"source": [
"deployment_id = \"\" # Fill in the deployment id from the portal here"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Create programatically\n",
"We can also create the deployment using code. Note that you can only create one deployment per model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = \"gpt-35-turbo\"\n",
"\n",
"# Now let's create the deployment\n",
"print(f'Creating a new deployment with model: {model}')\n",
"result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"standard\"})\n",
"deployment_id = result[\"id\"]\n",
"print(f'Successfully created deployment with id: {deployment_id}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Wait for deployment to succeed\n",
"Now let's check the status of the newly created deployment and wait till it is succeeded."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Checking for deployment status.')\n",
"resp = openai.Deployment.retrieve(id=deployment_id)\n",
"status = resp[\"status\"]\n",
"print(f'Deployment {deployment_id} has status: {status}')\n",
"while status not in [\"succeeded\", \"failed\"]:\n",
" resp = openai.Deployment.retrieve(id=deployment_id)\n",
" status = resp[\"status\"]\n",
" print(f'Deployment {deployment_id} has status: {status}')"
"deployment_id = '' # Fill in the deployment id from the portal here"
]
},
{
Expand Down Expand Up @@ -227,25 +180,6 @@
" if \"content\" in delta.keys():\n",
" print(delta.content, end=\"\", flush=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Delete\n",
"Finally let's delete the deployment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Deleting deployment: {deployment_id}')\n",
"openai.Deployment.delete(sid=deployment_id)"
]
}
],
"metadata": {
Expand All @@ -264,7 +198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.3"
},
"orig_nbformat": 4
},
Expand Down
73 changes: 11 additions & 62 deletions examples/azure/completions.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -11,14 +12,15 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import openai"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -28,22 +30,24 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"openai.api_version = '2022-12-01'\n",
"openai.api_version = '2023-05-15'\n",
"openai.api_base = '' # Please add your endpoint here"
]
},
{
"attachments": {},
"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`."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -62,6 +66,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -102,55 +107,17 @@
"Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\". Select `text-davinci-002` as the model."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Create programatically\n",
"We can also create a deployment using code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = \"text-davinci-002\"\n",
"\n",
"# Now let's create the deployment\n",
"print(f'Creating a new deployment with model: {model}')\n",
"result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"standard\"})\n",
"deployment_id = result[\"id\"]\n",
"print(f'Successfully created deployment with id: {deployment_id}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Wait for deployment to succeed\n",
"Now let's check the status of the newly created deployment and wait till it is succeeded."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Checking for deployment status.')\n",
"resp = openai.Deployment.retrieve(id=deployment_id)\n",
"status = resp[\"status\"]\n",
"print(f'Deployment {deployment_id} has status: {status}')\n",
"while status not in [\"succeeded\", \"failed\"]:\n",
" resp = openai.Deployment.retrieve(id=deployment_id)\n",
" status = resp[\"status\"]\n",
" print(f'Deployment {deployment_id} has status: {status}')"
"deployment_id = '' # Fill in the deployment id from the portal here"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -170,24 +137,6 @@
" \n",
"print(f\"{prompt}{completion['choices'][0]['text']}.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Delete\n",
"Finally let's delete the deployment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Deleting deployment: {deployment_id}')\n",
"openai.Deployment.delete(sid=deployment_id)"
]
}
],
"metadata": {
Expand All @@ -206,7 +155,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.3"
},
"vscode": {
"interpreter": {
Expand Down
64 changes: 8 additions & 56 deletions examples/azure/embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"import openai\n",
"from openai import cli"
"import openai"
]
},
{
Expand All @@ -35,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"openai.api_version = '2022-12-01'\n",
"openai.api_version = '2023-05-15'\n",
"openai.api_base = '' # Please add your endpoint here"
]
},
Expand Down Expand Up @@ -91,6 +90,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -99,56 +99,25 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Deployments: Create manually\n",
"Let's create a deployment using the `text-similarity-curie-001` model. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\"."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Create programatically\n",
"We can also create a deployment using code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = \"text-similarity-curie-001\"\n",
"\n",
"# Now let's create the deployment\n",
"print(f'Creating a new deployment with model: {model}')\n",
"result = openai.Deployment.create(model=model, scale_settings={\"scale_type\":\"standard\"})\n",
"deployment_id = result[\"id\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Retrieving\n",
"Now let's check the status of the newly created deployment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Checking for deployment status.')\n",
"resp = openai.Deployment.retrieve(id=deployment_id)\n",
"status = resp[\"status\"]\n",
"print(f'Deployment {deployment_id} is with status: {status}')"
"deployment_id = '' # Fill in the deployment id from the portal here"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -183,6 +152,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -201,24 +171,6 @@
" \n",
"print(embeddings)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### (Optional) Deployments: Delete\n",
"Finally let's delete the deployment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'Deleting deployment: {deployment_id}')\n",
"openai.Deployment.delete(sid=deployment_id)"
]
}
],
"metadata": {
Expand All @@ -237,7 +189,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.3"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit 828a6c5

Please sign in to comment.