Skip to content

Commit affbd3f

Browse files
Merge pull request #237545 from codemillmatt/oai-dotnet-gen-embed
Adding a C# example to the embeddings how-to
2 parents 1cab343 + ca600f9 commit affbd3f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

articles/cognitive-services/openai/how-to/embeddings.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: nitinme
77
ms.service: cognitive-services
88
ms.subservice: openai
99
ms.topic: how-to
10-
ms.date: 6/24/2022
10+
ms.date: 5/9/2023
1111
author: ChrisHMSFT
1212
ms.author: chrhoder
1313
recommendations: false
@@ -46,6 +46,29 @@ response = openai.Embedding.create(
4646
embeddings = response['data'][0]['embedding']
4747
print(embeddings)
4848
```
49+
50+
# [C#](#tab/csharp)
51+
```csharp
52+
using Azure;
53+
using Azure.AI.OpenAI;
54+
55+
Uri oaiEndpoint = new ("https://YOUR_RESOURCE_NAME.openai.azure.com");
56+
string oaiKey = "YOUR_API_KEY";
57+
58+
AzureKeyCredential credentials = new (oaiKey);
59+
60+
OpenAIClient openAIClient = new (oaiEndpoint, credentials);
61+
62+
EmbeddingsOptions embeddingOptions = new ("Your text string goes here");
63+
64+
var returnValue = openAIClient.GetEmbeddings("YOUR_DEPLOYMENT_NAME", embeddingOptions);
65+
66+
foreach (float item in returnValue.Value.Data[0].Embedding)
67+
{
68+
Console.WriteLine(item);
69+
}
70+
```
71+
4972
---
5073

5174
## Best Practices

0 commit comments

Comments
 (0)