Skip to content

Commit 0be768a

Browse files
authored
Update the getting started document (#690)
Merging changes to the guidance
1 parent 3094238 commit 0be768a

File tree

2 files changed

+103
-50
lines changed

2 files changed

+103
-50
lines changed

docs/guides/README.MD renamed to docs/README.md

Lines changed: 103 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,228 @@
11
# OpenAI with .NET 10 - Getting Started Guide
2-
This readme shows you how to run each OpenAI based sample (.cs) file in this folder directly without a project or additional setup using the latest .NET 10 Preview features.
2+
3+
This readme shows you how to run each OpenAI based sample (.cs) file in this folder directly without a project or additional setup using the latest .NET 10 features.
34

45
## Prerequisites
56

6-
### 1. Install .NET 10 Preview
7+
### 1. Install .NET 10
78

9+
#### Option A: Using package manager - Recommended
810

9-
#### Option A: Using Windows Package Manager (winget) - Recommended
10-
```powershell
11-
# Install .NET 10 SDK Preview
12-
winget install Microsoft.DotNet.SDK.Preview
13-
```
11+
- Windows
12+
13+
```powershell
14+
# Install .NET 10 SDK Preview
15+
winget install Microsoft.DotNet.SDK.Preview
16+
```
17+
18+
- Mac OS
19+
20+
```bash
21+
# Install .NET 10 SDK Preview
22+
brew tap isen-ng/dotnet-sdk-versions
23+
brew install --cask dotnet-sdk10-preview
24+
```
25+
26+
#### Option B: Manual download
1427
15-
#### Option B: Manual Download
1628
1. Visit the [.NET 10 Download Page](https://dotnet.microsoft.com/download/dotnet/10.0)
17-
2. Download and install: **.NET SDK 10.0 Preview** (required for development and `dotnet run`)
29+
1. Download and install: **.NET SDK 10.0 Preview** (required for development and `dotnet run`)
1830
19-
### 2. Verify Installation
31+
### 2. Verify installation
2032
2133
After installation, verify you have the correct versions:
2234
2335
```powershell
2436
# Check installed SDKs
2537
dotnet --list-sdks
2638
27-
# Check version from the guides directory (should show 10.x)
28-
cd docs/guides
39+
# Check version from the docs directory (should show 10.x)
40+
cd docs
2941
dotnet --version
3042
```
3143

3244
You should see output similar to:
33-
```
34-
10.0.100-preview.5.25277.114
45+
46+
```text
47+
10.0.100-rc.1.25451.107
3548
```
3649

3750
## Setup
3851

39-
### 1. Clone the Repository
52+
### 1. Clone the repository
53+
4054
```powershell
4155
git clone https://github.com/openai/openai-dotnet.git
4256
cd openai-dotnet
4357
```
4458

45-
### 2. Set Your OpenAI API Key
59+
### 2. Set your OpenAI API key
4660

4761
You need an OpenAI API key to run the samples. Get one from [OpenAI's API platform](https://platform.openai.com/api-keys).
4862

49-
#### Temporary (Current Session Only)
63+
#### Temporary (Current session only)
64+
65+
```bash
66+
# bash/zsh
67+
export OPENAI_API_KEY="your-api-key-here"
68+
```
69+
5070
```powershell
71+
# PowerShell
5172
$env:OPENAI_API_KEY = "your-api-key-here"
5273
```
5374

54-
#### Permanent Options
75+
#### Permanent options
5576

5677
**Option A: Using System Properties (GUI)**
78+
5779
1. Press `Win + R`, type `sysdm.cpl`, press Enter
5880
2. Click "Environment Variables"
5981
3. Under "User variables", click "New"
6082
4. Variable name: `OPENAI_API_KEY`
6183
5. Variable value: Your API key
6284

6385
**Option B: Using PowerShell (Permanent)**
86+
6487
```powershell
6588
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "your-api-key-here", "User")
6689
```
6790

6891
**Option C: Using Command Prompt as Administrator**
92+
6993
```cmd
7094
setx OPENAI_API_KEY "your-api-key-here"
7195
```
7296

73-
### 3. Verify Environment Variable
97+
**Option D: Using bash/zsh**
98+
99+
```bash
100+
# bash
101+
echo 'export OPENAI_API_KEY=\"your-api-key-here\"' >> ~/.bashrc
102+
source ~/.bashrc
103+
```
104+
105+
```bash
106+
# zsh
107+
echo 'export OPENAI_API_KEY=\"your-api-key-here\"' >> ~/.zshrc
108+
source ~/.zshrc
109+
```
110+
111+
### 3. Verify environment variable
112+
113+
```bash
114+
# bash/zsh
115+
echo $OPENAI_API_KEY
116+
```
117+
74118
```powershell
119+
# PowerShell
75120
echo $env:OPENAI_API_KEY
76121
```
77122

78-
## Running the Samples
123+
## Running the samples
79124

80125
The samples use .NET 10's new single-file application feature. Each `.cs` file in the guides folder is a standalone application.
81126

82-
### Navigate to the Guides Directory
127+
### 1. Navigate to the docs directory
128+
83129
```powershell
84-
cd docs/guides
130+
cd docs
85131
```
86132

87-
### Run a Sample
133+
### 2. Run a sample
134+
88135
```powershell
89136
# Example: Run the simple chat prompt sample
90-
dotnet run text/chat/chat_simpleprompt.cs
137+
dotnet run quickstart/responses/developer_quickstart.cs
91138
92139
# Run other samples
93-
dotnet run text/chat/chat_instructions.cs
94-
dotnet run text/chat/chat_roles.cs
140+
dotnet run guides/text/responses/responses_simpleprompt.cs
141+
dotnet run guides/text/responses/responses_roles.cs
95142
```
96143

97-
### Expected Output
98-
When you run `chat_simpleprompt.cs`, you should see output similar to:
99-
```
144+
### 3. Expected output
145+
146+
When you run `developer_quickstart.cs`, you should see output similar to:
147+
148+
```text
100149
Under a velvet-purple sky, a gentle unicorn named Luna sprinkled stardust over the dreaming forest, filling every heart with peaceful, magical dreams.
101150
```
102151

103-
## Sample File Structure
152+
## Sample file structure
104153

105154
The samples are organized as follows:
106-
```
155+
156+
```text
107157
docs/
158+
├── global.json # Specifies .NET 10 preview SDK
159+
├── README.MD # Basic usage instructions
108160
├── guides/
109-
│ ├── global.json # Specifies .NET 10 preview SDK
110-
│ ├── README.MD # Basic usage instructions
111161
│ └── text/
112162
│ ├── chat/
113-
│ │ ├── chat_simpleprompt.cs # Basic chat completion
114-
│ │ ├── chat_instructions.cs # Chat with system instructions
115-
│ │ └── chat_roles.cs # Chat with different roles
163+
│ └── ... # Chat handling samples
116164
│ └── responses/
117-
│ └── ... # Response handling samples
165+
│ └── ... # Response handling samples
166+
├── quickstart/
167+
│ └── responses/
168+
│ └── ... # Response handling samples
118169
```
119170

120-
## Understanding the Single-File Format
171+
## Understanding the single-file format
121172

122173
Each sample file contains special directives at the top:
123174

124175
```csharp
125176
// SAMPLE: Description of what this sample does
126-
#:package OpenAI@2.2.*-* // NuGet package reference
127-
#:property PublishAot false // Build properties
177+
#:package OpenAI@2.* // NuGet package reference
178+
#:property PublishAot=false // Build properties
128179
129-
using OpenAI.Chat; // Regular C# code follows
180+
using OpenAI.Responses; // Regular C# code follows
130181
131182
// Your application code here...
132183
```
133184

134185
## Troubleshooting
135186

136187
### Problem: "No package found matching input criteria"
188+
137189
- **Solution**: The .NET 10 preview packages might not be available yet. Try installing from the official Microsoft download page instead.
138190

139191
### Problem: `dotnet --version` shows 9.x instead of 10.x
192+
140193
- **Solution**: You need to install the .NET 10 **SDK** (not just the runtime). The `global.json` file in the guides directory requires the SDK.
141194

142195
### Problem: "Couldn't find a project to run"
196+
143197
- **Solution**: Make sure you're running the command from the `docs/guides` directory and providing the correct path to the `.cs` file.
144198

145199
### Problem: "The property directive needs to have two parts"
200+
146201
- **Solution**: The property directive format should be `#:property PropertyName PropertyValue` (space-separated, not equals sign).
147202

148203
### Problem: API errors
149-
- **Solution**:
204+
205+
- **Solution**:
150206
- Verify your `OPENAI_API_KEY` environment variable is set correctly
151207
- Check that your API key is valid and has sufficient credits
152208
- Ensure you're using a valid model name (e.g., "gpt-4", "gpt-3.5-turbo")
153209

154210
### Problem: Build errors about missing packages
211+
155212
- **Solution**: The package directives should automatically download dependencies. If not, try:
213+
156214
```powershell
157215
dotnet restore
158216
```
159217

160-
## Additional Resources
218+
## Additional resources
161219

162220
- [OpenAI .NET SDK Documentation](https://github.com/openai/openai-dotnet)
163-
- [.NET 10 Preview Documentation](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-10)
221+
- [.NET 10 Preview Documentation](https://docs.microsoft.com/dotnet/core/whats-new/dotnet-10)
164222
- [OpenAI API Documentation](https://platform.openai.com/docs)
165223
- [Single-File Applications in .NET 10](https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-app/)
166224

167-
## Next Steps
225+
## Next steps
168226

169227
Once you have the basic samples working, you can:
170228

docs/guides/global.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)