Created
July 20, 2024 03:41
-
-
Save ilovelili/40832d933ea38c376982cf6a633eb091 to your computer and use it in GitHub Desktop.
calling azure open ai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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