Open sydrawat01 opened 1 year ago
Demo code:
const { Configuration, OpenAIApi } = require('openai')
const basePath = 'https://azureopenaiproject.openai.azure.com/openai/deployments/'
const model = 'azure-openai-model-name'
const azureOpenAiChatGPT = async (model) => {
const configuration = new Configuration({
basePath: basePath + model,
apiKey: 'abcdxyz',
})
const openai = new OpenAIApi(configuration)
const completion = await openai.createCompletion(
{
model,
prompt: 'what is jardiance?',
max_tokens: 100,
temperature: 1,
frequency_penalty: 0,
presence_penalty: 0,
top_p: 0.5,
best_of: 1,
stop: null,
},
{
headers: {
'api-key': 'abcdxyz',
},
params: { 'api-version': '2022-12-01' },
}
)
return completion
}
azureOpenAiChatGPT(model)
.then((result) => {
console.log(result.data.choices[0].text)
return 'ok'
})
.catch((err) => {
console.log(err)
return 'not ok'
})
Have a message stream that the API can accept, which can then be rendered on the UI.
Use the
openai
NodeJS package to use the Azure OpenAI API to provide responses to our bot instead of our custom built OpenAI API.