Skip to content

Instantly share code, notes, and snippets.

@ilovelili
Created July 20, 2024 03:41
Show Gist options
  • Save ilovelili/40832d933ea38c376982cf6a633eb091 to your computer and use it in GitHub Desktop.
Save ilovelili/40832d933ea38c376982cf6a633eb091 to your computer and use it in GitHub Desktop.
calling azure open ai
async function getAIResponse(userSpeech: string): Promise<string> {
const response = await fetch(
`${openAIEndpoint}/openai/deployments/Woodstock-AI/completions?api-version=2024-06-01`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${openAIAPIKey}`,
},
body: JSON.stringify({
prompt: userSpeech,
max_tokens: 150,
temperature: 0.7,
}),
}
);
const data = await response.json();
return data.choices[0].text.trim();
}
=================================================================
Error:
{
"statusCode": 401,
"message": "Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment