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-ada-002",
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
最佳作法
確認輸入內容未超過長度最大值
我們最新內嵌模型的輸入文字長度上限為8192標記。 在提出要求之前,請先確認輸入內容未超過此限制。
如果在單一內嵌要求中傳送輸入數位,則陣列大小上限為2048。
限制和風險
我們的內嵌模型在某些情況下可能不可靠,或會帶來社交風險,而且可能會在缺少風險緩解措施的情況下造成損害。 如需了解如何要求負責任的詳細資訊,請檢閱我們的負責任 AI 內容。