Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active June 3, 2024 07:38
Show Gist options
  • Select an option

  • Save rain1024/b2c1af3bf872b8d299b9879cc703bc4c to your computer and use it in GitHub Desktop.

Select an option

Save rain1024/b2c1af3bf872b8d299b9879cc703bc4c to your computer and use it in GitHub Desktop.

Revisions

  1. rain1024 revised this gist Sep 8, 2023. No changes.
  2. rain1024 renamed this gist Sep 8, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. rain1024 created this gist Sep 7, 2023.
    32 changes: 32 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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();