You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/codespaces/new?hide_repo_select=true&ref=main&skip_quickstart=true&machine=basicLinux32gb&repo=784926917&devcontainer_path=.devcontainer%2Fdevcontainer.json&geo=WestUs2)
19
+
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/azure-openai-keyless-python)
20
+
18
21
The purpose of this repository is to provision an Azure OpenAI account with an RBAC role permission for your user account to access,
19
22
so that you can use the OpenAI API SDKs with keyless (Entra) authentication. By default, the account will include a gpt-3.5 model, but you can modify `infra/main.bicep` to deploy other models instead.
20
23
21
-
## Prerequisites
24
+
*[Getting started](#getting-started)
25
+
*[GitHub Codespaces](#github-codespaces)
26
+
*[VS Code Dev Containers](#vs-code-dev-containers)
27
+
*[Local environment](#local-environment)
28
+
*[Deployment](#deployment)
29
+
*[Running the Python example](#running-the-python-example)
30
+
*[Guidance](#guidance)
31
+
*[Costs](#costs)
32
+
*[Security guidelines](#security-guidelines)
33
+
*[Resources](#resources)
34
+
35
+
## Getting started
36
+
37
+
You have a few options for getting started with this template.
38
+
The quickest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also [set it up locally](#local-environment).
39
+
40
+
### GitHub Codespaces
41
+
42
+
You can run this template virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:
43
+
44
+
1. Open the template (this may take several minutes):
45
+
46
+
[](https://codespaces.new/Azure-Samples/azure-openai-keyless-python)
47
+
48
+
2. Open a terminal window
49
+
3. Continue with the [deployment steps](#deployment)
50
+
51
+
### VS Code Dev Containers
22
52
23
-
1. Sign up for a [free Azure account](https://azure.microsoft.com/free/) and create an Azure Subscription.
24
-
2. Request access to Azure OpenAI Service by completing the form at [https://aka.ms/oai/access](https://aka.ms/oai/access) and awaiting approval.
25
-
3. Install the [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd). (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)
53
+
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):
26
54
27
-
## Provisioning
55
+
1. Start Docker Desktop (install it if not already installed)
56
+
2. Open the project:
57
+
58
+
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/azure-openai-keyless-python)
59
+
60
+
3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
61
+
4. Continue with the [deployment steps](#deployment)
2. Make a new directory called `azure-openai-keyless-python` and clone this template into it using the `azd` CLI:
71
+
72
+
```shell
73
+
azd init -t azure-openai-keyless-python
74
+
```
75
+
76
+
You can also use git to clone the repository if you prefer.
77
+
78
+
3. Continue with the [deployment steps](#deployment)
79
+
80
+
## Deployment
28
81
29
82
1. Login to Azure:
30
83
31
84
```shell
32
85
azd auth login
33
86
```
34
87
88
+
For GitHub Codespaces users, if the previous command fails, try:
89
+
90
+
```shell
91
+
azd auth login --use-device-code
92
+
```
93
+
35
94
2. Provision the OpenAI account:
36
95
37
96
```shell
38
97
azd provision
39
98
```
40
99
41
-
It will prompt you to provide an `azd` environment name (like "chat-app"), selecta subscription from your Azure account, and selecta [location where the OpenAI model is available](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) (like "canadaeast"). Then it will provision the resources in your account and deploy the latest code. If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the OpenAI resource. To change the location run:
100
+
It will prompt you to provide an `azd` environment name (like "chat-app"), selecta subscription from your Azure account, and selecta [location where the OpenAI model is available](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) (like "canadaeast"). Then it will provision the resources in your account and deploy the latest code.
101
+
102
+
⚠️ If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the OpenAI resource. To change the location run:
42
103
43
104
```shell
44
105
azd env set AZURE_LOCATION "yournewlocationname"
@@ -58,7 +119,7 @@ so that you can use the OpenAI API SDKs with keyless (Entra) authentication. By
58
119
pwsh ./write_dot_env.ps1
59
120
```
60
121
61
-
4. Then you can run the example code in this repository.
122
+
4. Then you can proceed to [run the Python example](#running-the-python-example).
62
123
63
124
## Running the Python example
64
125
@@ -77,3 +138,20 @@ so that you can use the OpenAI API SDKs with keyless (Entra) authentication. By
77
138
```
78
139
79
140
This will use the OpenAI API SDK to make a request to the OpenAI API and print the response.
141
+
142
+
## Guidance
143
+
144
+
### Costs
145
+
146
+
This template creates only the Azure OpenAI resource, which is free to provision. However, you will be charged for the usage of the Azure OpenAI chat completions API. The pricing is based on the number of tokens used, with around 1-3 tokens used per word. You can find the pricing details for the OpenAI API on the [Azure Cognitive Services pricing page](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/).
147
+
148
+
### Security guidelines
149
+
150
+
This template uses [keyless authentication](https://learn.microsoft.com/en-us/azure/developer/ai/keyless-connections) for authenticating to the Azure OpenAI resource. This is a secure way to authenticate to Azure resources without needing to store credentials in your code. Your Azure user account is assigned the "Cognitive Services OpenAI User" role, which allows you to access the OpenAI resource. You can find more information about the permissions of this role in the [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/role-based-access-control).
151
+
152
+
For further security, you could also deploy the Azure OpenAI inside a private virtual network (VNet) and use a private endpoint to access it. This would prevent the OpenAI resource from being accessed from the public internet.
153
+
154
+
## Resources
155
+
156
+
* [Video: Using keyless auth with Azure AI services](https://www.youtube.com/watch?v=IkDcQvKoQ8k)
0 commit comments