This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
I assume the model id of gpt-35-turbo-1106 is a concatenation of the model name and model version from the screenshot and not the deployment name.
Use following code, build and run.
import { AssistantsClient, AssistantCreationOptions, MessageRole, CodeInterpreterToolDefinition, ToolDefinition } from "@azure/openai-assistants";
import { AzureKeyCredential } from "@azure/core-auth";
import 'dotenv/config'
const azureOpenAIKey = process.env.AZURE_OPENAI_KEY as string;
const azureOpenAIEndpoint = process.env.AZURE_OPENAI_ENDPOINT as string;
const azureOpenAIModelId = process.env.AZURE_OPENAI_MODEL_ID as string;
if (!azureOpenAIKey || !azureOpenAIEndpoint) {
throw new Error(
"Please ensure to set AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT in your environment variables."
);
}
const assistantsClient = new AssistantsClient(azureOpenAIEndpoint, new AzureKeyCredential(azureOpenAIKey));
//"gpt-35-turbo-1106",
//"gpt-35-turbo-instruct-0914",
const options: AssistantCreationOptions = {
model: azureOpenAIModelId,
name: "Math Tutor",
instructions: "You are a personal math tutor. Write and run JavaScript code to answer math questions.",
tools: [{ type: "code_interpreter" } as ToolDefinition],
};
// Create an assistant
const assistantResponse = await assistantsClient.createAssistant(options);
console.log(`Assistant created: ${JSON.stringify(assistantResponse)}`);
// Create a thread
const assistantThread = await assistantsClient.createThread({});
console.log(`Thread created: ${JSON.stringify(assistantThread)}`);
// Add a user question to the thread
const threadResponse = await assistantsClient.createMessage(assistantThread.id, "user", "What is 3x + 11 = 14?");
console.log(`Message created: ${JSON.stringify(threadResponse)}`);
// Run the thread
let runResponse = await assistantsClient.createRun(
assistantThread.id,
{
assistantId: assistantResponse.id
}
);
console.log(`Run created: ${JSON.stringify(runResponse)}`);
// Wait for the assistant to respond
do {
await new Promise((r) => setTimeout(r, 500));
runResponse = await assistantsClient.getRun(assistantThread.id, runResponse.id);
} while (runResponse.status === "queued" || runResponse.status === "in_progress");
// Get the messages
const runMessages = await assistantsClient.listMessages(assistantThread.id);
for (const runMessageDatum of runMessages.data) {
for (const item of runMessageDatum.content) {
if (item.type === "text") {
console.log(`Message content: ${JSON.stringify(item.text?.value)}`);
}
}
}
Describe the bug Code correctly creates assistant and thread but returns 500 on create message
To Reproduce Steps to reproduce the behavior:
I assume the model id of
gpt-35-turbo-1106
is a concatenation of the model name and model version from the screenshot and not the deployment name.Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.