Last active
June 3, 2024 07:38
-
-
Save rain1024/b2c1af3bf872b8d299b9879cc703bc4c to your computer and use it in GitHub Desktop.
Revisions
-
rain1024 revised this gist
Sep 8, 2023 . No changes.There are no files selected for viewing
-
rain1024 renamed this gist
Sep 8, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rain1024 created this gist
Sep 7, 2023 .There are no files selected for viewing
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 charactersOriginal 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();