Skip to content

Commit de0fa80

Browse files
Merge pull request #259481 from mgreenegit/patch-2
PowerShell example for embeddings
2 parents 997c7b2 + d26a494 commit de0fa80

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ foreach (float item in returnValue.Value.Data[0].Embedding.ToArray())
9494
}
9595
```
9696

97+
# [PowerShell](#tab/PowerShell)
98+
```powershell-interactive
99+
# Azure OpenAI metadata variables
100+
$openai = @{
101+
api_key = $Env:AZURE_OPENAI_KEY
102+
api_base = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
103+
api_version = '2023-05-15' # this may change in the future
104+
name = 'YOUR-DEPLOYMENT-NAME-HERE' #This will correspond to the custom name you chose for your deployment when you deployed a model.
105+
}
106+
107+
$headers = [ordered]@{
108+
'api-key' = $openai.api_key
109+
}
110+
111+
$text = 'Your text string goes here'
112+
113+
$body = [ordered]@{
114+
input = $text
115+
} | ConvertTo-Json
116+
117+
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/embeddings?api-version=$($openai.api_version)"
118+
119+
$response = Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Post -ContentType 'application/json'
120+
return $response.data.embedding
121+
```
122+
97123
---
98124

99125
## Best practices

0 commit comments

Comments
 (0)