using Azure;
using Azure.AI.OpenAI;
Uri oaiEndpoint = new ("https://YOUR_RESOURCE_NAME.openai.azure.com");
string oaiKey = "YOUR_API_KEY";
AzureKeyCredential credentials = new (oaiKey);
OpenAIClient openAIClient = new (oaiEndpoint, credentials);
EmbeddingsOptions embeddingOptions = new()
{
DeploymentName = "text-embedding-3-large",
Input = { "Your text string goes here" },
};
var returnValue = openAIClient.GetEmbeddings(embeddingOptions);
foreach (float item in returnValue.Value.Data[0].Embedding.ToArray())
{
Console.WriteLine(item);
}
# Azure OpenAI metadata variables
$openai = @{
api_key = $Env:AZURE_OPENAI_API_KEY
api_base = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
api_version = '2024-02-01' # this may change in the future
name = 'YOUR-DEPLOYMENT-NAME-HERE' #This will correspond to the custom name you chose for your deployment when you deployed a model.
}
$headers = [ordered]@{
'api-key' = $openai.api_key
}
$text = 'Your text string goes here'
$body = [ordered]@{
input = $text
} | ConvertTo-Json
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/embeddings?api-version=$($openai.api_version)"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Post -ContentType 'application/json'
return $response.data.embedding