Skip to content

Commit a441b27

Browse files
Updated CM README.md (Azure#49757)
* Updated CM README.md * Update README.md
1 parent dc2d56a commit a441b27

File tree

1 file changed

+42
-92
lines changed

1 file changed

+42
-92
lines changed

sdk/cloudmachine/README.md

Lines changed: 42 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,93 @@
11
# Azure Projects client library for .NET
22

3-
Write Azure apps in 5 minutes
3+
Azure.Projects is an set of libraries and tools for rapid application development on Azure.
4+
If you cannot get an app running in 10 minutes, let us know that we failed!
45

5-
## Getting started
6-
7-
### Install the packages
6+
These libraries and tools make it easier to start building an application, by:
7+
- Relying on opinionated defaults whenever possible.
8+
- Using the Azure.Provisioning libraries for provisioning resources in code (in C#).
9+
- Exposing simplified APIs for the most commonly used Azure services.
810

9-
Install the client library for .NET with [NuGet](https://www.nuget.org/ ):
11+
At the same time, Azure.Projects supports break-glass scenarios where, if needed, you can override the defaults, use powerful tools (like bicep, azd), or the full featured Azure SDK libraries.
12+
In other words, Azure.Projects provides smart, simplified APIs but will never block you from using the full power of the Azure platform, if you choose to.
1013

11-
```dotnetcli
12-
dotnet add package Azure.Projects --prerelease
13-
dotnet add package Azure.Projects.Provisioning --prerelease
14-
dotnet add package Azure.Projects.AI --prerelease
15-
```
16-
17-
### Authenticate the Client
14+
## Getting started
1815

1916
### Prerequisites
2017

2118
* You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/).
22-
* You must have .NET 8 (or higher) installed
23-
* You must have Azure CLI (az) installed
24-
* You must have Azure Developer CLI (azd) installed
25-
* You must have npm installed
26-
* You must be logged into Azure CLI and Azure Developer CLI
27-
28-
## Key concepts
29-
30-
Write Azure apps in 5 minutes using simplified opinionated APIs and declarative resource provisioning.
19+
* You must have [.NET 8](https://dotnet.microsoft.com/download) (or higher) installed
20+
* You must have [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd) (azd) installed
21+
* You must be logged into Azure Developer CLI (`azd auth login`)
3122

3223
### Walkthrough
3324

34-
#### Create Server Project
25+
#### Create a console application
3526

3627
In a command line window type
28+
3729
```dotnetcli
3830
mkdir cmdemo
3931
cd cmdemo
40-
mkdir server
41-
cd server
42-
dotnet new web
32+
dotnet new console
4333
```
4434

45-
Add `Azure.Projects.*` packages
35+
#### Install Required Packages
36+
4637
```dotnetcli
38+
dotnet add package Azure.Projects --prerelease
4739
dotnet add package Azure.Projects.Provisioning --prerelease
4840
dotnet add package Azure.Projects.AI --prerelease
4941
```
50-
#### Use Azure Developer CLI to provision Projects
5142

52-
Open `Program.cs` file and add the following two lines of code to the top of the file
43+
#### Write, Provision, and Run the Application
44+
45+
Open `Program.cs` file and change the code to the following
5346
```csharp
47+
using Azure.AI.OpenAI;
5448
using Azure.Projects;
49+
using Azure.Projects.Tooling;
50+
using OpenAI.Chat;
5551

5652
ProjectInfrastructure infrastructure = new();
57-
if (infrastructure.TryExecuteCommand(args)) return;
58-
```
53+
infrastructure.AddFeature(new OpenAIChatFeature("gpt-35-turbo", "0125"));
5954

60-
The `TryExecuteCommand` call allows running the app with a `-init` switch, which will generate bicep files required to provision project resources in Azure. Let's generate these bicep files now.
61-
```dotnetcli
62-
dotnet run -bicep
63-
```
64-
As you can see, a folder called `infra` was created with several bicep files in it. Let's now initialize the project.
55+
if (args.Length > 0 && args[0] == "-bicep")
56+
{
57+
Azd.Init(infrastructure);
58+
return;
59+
}
60+
61+
ProjectClient project = new();
62+
ChatClient chat = project.GetOpenAIChatClient();
63+
Console.WriteLine(chat.CompleteChat("list all noble gasses.").AsText());
6564

66-
```dotnetcli
67-
azd init
68-
```
69-
type 'demo' as the environment name, and then let's provision the resources (select `eastus` as the region):
70-
```dotnetcli
71-
azd provision
72-
```
73-
When provisioning finishes, you should see something like the following in the console output
74-
```dotnetcli
75-
(✓) Done: Resource group: cm125957681369428 (627ms)
76-
```
77-
And if you go to your Azure portal, or execute the following az command, you can see the resource group created. The resource group will contain resources such as Storage, ServiceBus, and EventGrid.
78-
```dotnetcli
79-
az resource list --resource-group <resource_group_from_command_line> --output table
8065
```
8166

82-
#### Use CDK to add resources to the Project
67+
You can now provision Azure resources for this application by executing the following three commands.
8368

84-
Since we are writing an AI application, we need to provision Azure OpenAI resources. To do this, add the following line of code right below where the infrastructure instance is created:
85-
```csharp
86-
infrastructure.AddFeature(new OpenAIModelFeature("gpt-4o-mini", "2024-07-18"));
87-
```
88-
Now regenerate the bicep files and re-provision
8969
```dotnetcli
9070
dotnet run -bicep
71+
azd init
9172
azd provision
9273
```
93-
94-
#### Add ProjectClient to ASP.NET DI Container
95-
You will be using `ProjectClient` to access resources provisioned in the cloud machine. Let's add such client to the DI container such that it is avaliable to ASP.NET handlers
74+
The first command created a folder called `infra` with several bicep files in it. The files will be used by azd to provision Azure resources.
75+
The second command sets initializes the project as an azd project. Select 'create minimal project' when asked to choose a template, and type 'demo' as the environment name.
76+
The last command actually provisions resources described by the bicep files. When provisioning finishes, you should see something like the following in the console output
9677
```dotnetcli
97-
builder.AddAzureProjectClient(infrastructure);
98-
```
99-
#### Call ProjectClient APIs
100-
101-
You are now ready to call Azure OpenAI service from the app. To do this, change the line of code that maps the application root to the following:
102-
103-
```csharp
104-
app.MapGet("/", (ProjectClient client) => client.GetOpenAIChatClient().CompleteChat("list all noble gases").AsText());
105-
```
106-
107-
The full program should now look like the following:
108-
```csharp
109-
using Azure.Projects;
110-
using Azure.Projects.OpenAI;
111-
112-
ProjectInfrastructure infrastructure = new();
113-
infrastructure.AddFeature(new OpenAIModelFeature("gpt-4o-mini", "2024-07-18"));
114-
if (infrastructure.TryExecuteCommand(args)) return;
115-
116-
var builder = WebApplication.CreateBuilder(args);
117-
builder.AddAzureProjectClient(infrastructure);
118-
119-
var app = builder.Build();
120-
121-
app.MapGet("/", (ProjectClient client) => client.GetOpenAIChatClient().CompleteChat("list all noble gases").AsText());
122-
123-
app.Run();
78+
(✓) Done: Resource group: cm125957681369428 (627ms)
12479
```
80+
You can now run the app
12581

126-
You can now start the application
12782
```dotnetcli
12883
dotnet run
12984
```
130-
and navigate to the URL printed in the console.
131-
132-
## Examples
13385

13486
## Troubleshooting
13587

13688
- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues).
13789
- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags.
13890

139-
## Next steps
140-
14191
## Contributing
14292

14393
For details on contributing to this repository, see the [contributing
@@ -161,4 +111,4 @@ more information, see the [Code of Conduct FAQ][coc_faq] or contact
161111
<!-- LINKS -->
162112
[cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md
163113
[coc]: https://opensource.microsoft.com/codeofconduct/
164-
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
114+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/

0 commit comments

Comments
 (0)