Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active June 3, 2024 07:38
Show Gist options
  • Save rain1024/b2c1af3bf872b8d299b9879cc703bc4c to your computer and use it in GitHub Desktop.
Save rain1024/b2c1af3bf872b8d299b9879cc703bc4c to your computer and use it in GitHub Desktop.
Azure OpenAI Starter Code
const axios = require('axios');
const YOUR_RESOURCE_NAME = ''; // Replace with your Azure OpenAI Resource name
const YOUR_DEPLOYMENT_NAME = ''; // Replace with your deployment id
const YOUR_API_KEY = ''; // Replace with your API key
const endpoint = `https://${YOUR_RESOURCE_NAME}.openai.azure.com/openai/deployments/${YOUR_DEPLOYMENT_NAME}/chat/completions?api-version=2023-05-15`;
async function getChatCompletions() {
try {
const response = await axios.post(endpoint, {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Does Azure OpenAI support customer managed keys?' },
{ role: 'assistant', content: 'Yes, customer managed keys are supported by Azure OpenAI.' },
{ role: 'user', content: 'Do other Azure AI services support this too?' }
]
}, {
headers: {
'Content-Type': 'application/json',
'api-key': YOUR_API_KEY
}
});
let response_message = response.data.choices[0].message['content'];
console.log(response_message);
} catch (error) {
console.error('Error calling OpenAI API:', error);
}
}
getChatCompletions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment