Closed phusting closed 1 year ago
@phusting can you provide some details about what environment you're running this in, such as what Node version, etc. If you're seeing AzureKeyCredential
not being defined I imagine it's some issue with the require statement since it appears the package is exporting the credential correctly.
Node 8.19.3 I'm using Visual Studio 2022 and building a Word Web Add-in.
const { OpenAIClient } = require("@azure/openai");
const endpoint = process.env["ENDPOINT"] || "https://myinstancecantshow-azureopenai.openai.azure.com/";
const azureApiKey = process.env["AZURE_API_KEY"] || "mykeycantshow";
const messages = [
{ role: "system", content: "You are a helpful assistant. You will talk like a pirate." },
{ role: "user", content: "Can you help me?" },
{ role: "assistant", content: "Arrrr! Of course, me hearty! What can I do for ye?" },
{ role: "user", content: "What's the best way to train a parrot?" },
];
// ** AZURE EXAMPLE
console.log("== Chat Completions Sample ==");
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
const deploymentId = "gpt-35-turbo";
const result = await client.getChatCompletions(deploymentId, messages);
for (const choice of result.choices) {
console.log(choice.message);
}
} catch (error) {
document.getElementById("txterror").innerText = error;
}
@phusting Node 8 has been out of support since the end of 2019. Our minimum supported Node version at this time is Node 14.
I'm not familiar with Word Web Add-ins, but I imagine you'll have to bundle similarly to the browser, since presumably the Add-In is running inside of a browser context?
Sorry, it is Node v18.13. I typed the wrong command.
Yes, it is running in a Chromium instance.
Going directly to OpenAI API is just fine. I am setting the azureai key, but it fails right away.
Seems like a Office web add-in thing. I'm actually further and it is sending the request, now troubleshooting the response. :) Almost there!
Almost, but this I have no clue. Any suggestions? I'm getting a 404 error.
`fetchHttpClient.js:67
POST https://ghostwriterai-azureopenai.openai.azure.com/openai/deployments/text-davinci-003/completions?api-version=2023-03-15-preview 404`
Closing, I got it to work in Office now.
I'm using the sample at https://github.com/Azure/azure-sdk-for-js/blob/%40azure/openai_1.0.0-beta.2/sdk/openai/openai/samples/v1-beta/javascript/chatCompletions.js#L16
and I'm always getting a ReferenceError: AzureKeyCredential is not defined I have it from my azure account but not sure why I'm always getting this. Is there somewhere I can look to figure out what the issue is?