Azure / azure-sdk-for-js

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.
MIT License
2.07k stars 1.19k forks source link

OpenAI Assistants assistantsClient.createAssistant returns 400 model not found #29147

Closed diberry closed 6 months ago

diberry commented 6 months ago

Describe the bug

I based my code on the OpenAI Assistants sample in order to create the quickstart for the documentation. The sample uses the model "gpt-4-1106-preview". I can see model gpt-4 with version 1106-preview so I think it is the same thing and so my resource should have the model. When I run the code, I get 400 model not found.

image

To Reproduce Steps to reproduce the behavior:

  1. Create .env with key and endpoint
AZURE_OPENAI_KEY=a6274...
AZURE_OPENAI_RESOURCE=my-openai-resource-f821f98361
AZURE_OPENAI_ENDPOINT=https://sweden-central-openai-dfberry.openai.azure.com/
  1. Create code to get assistants
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;

if (!azureOpenAIKey || !azureOpenAIEndpoint) {
 throw new Error(
   "Please ensure to set AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT in your environment variables."
 );
}

const credential = new AzureKeyCredential(azureOpenAIKey);

const assistantsClient = new AssistantsClient(azureOpenAIEndpoint, credential);

const options: AssistantCreationOptions = {
 model: "gpt-4-1106-preview",                                                        //  <-- Model from samples & tests
 name: "Math Tutor",
 instructions: "You are a personal math tutor. Write and run code to answer math questions.",
 tools: [{ type: "code_interpreter" } as ToolDefinition],
};

// Create an assistant
const assistantResponse = await assistantsClient.createAssistant(options);
console.log(assistantResponse);
  1. Receive error
RestError: Unexpected status code: 400
    at createRestError (file:///workspaces/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/node_modules/@azure-rest/core-client/dist/esm/restError.js:10:12)
    at _createAssistantDeserialize (file:///workspaces/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/node_modules/@azure/openai-assistants/dist-esm/src/api/operations.js:28:15)
    at createAssistant (file:///workspaces/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/node_modules/@azure/openai-assistants/dist-esm/src/api/operations.js:45:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///workspaces/azure-typescript-e2e-apps/quickstarts/azure-openai-assistants/dist/index.js:18:27 {
  code: 'model_not_found',
  statusCode: 400,
  request: PipelineRequestImpl {
    url: 'https://sweden-central-openai-dfberry.openai.azure.com/openai/assistants?api-version=2024-02-15-preview',
    method: 'POST',
    headers: HttpHeadersImpl {
      _headersMap: Map(7) {
        'accept' => { name: 'accept', value: 'application/json' },
        'content-type' => {
          name: 'content-type',
          value: 'application/json; charset=UTF-8'
        },
        'accept-encoding' => { name: 'Accept-Encoding', value: 'gzip,deflate' },
        'user-agent' => {
          name: 'User-Agent',
          value: 'azsdk-js-openai-assistants-rest/1.0.0-beta.5 core-rest-pipeline/1.15.1 Node/18.16.0 OS/(arm64-Linux-6.6.12-linuxkit)'
        },
        'x-ms-client-request-id' => {
          name: 'x-ms-client-request-id',
          value: '63ce0058-153e-4a45-804b-7e722dcfe9a3'
        },
        'api-key' => { name: 'api-key', value: 'a6274...' },
        'content-length' => { name: 'Content-Length', value: '181' }
      }
    },
    timeout: 0,
    withCredentials: false,
    body: '{"model":"gpt-4-1106-preview","name":"Math Tutor","instructions":"You are a personal math tutor. Write and run code to answer math questions.","tools":[{"type":"code_interpreter"}]}',
    multipartBody: undefined,
    formData: undefined,
    streamResponseStatusCodes: undefined,
    enableBrowserStreams: true,
    proxySettings: undefined,
    disableKeepAlive: false,
    abortSignal: undefined,
    requestId: '63ce0058-153e-4a45-804b-7e722dcfe9a3',
    tracingOptions: undefined,
    allowInsecureConnection: false,
    onUploadProgress: undefined,
    onDownloadProgress: undefined
  },
  response: {
    headers: HttpHeadersImpl {
      _headersMap: Map(7) {
        'content-length' => { name: 'content-length', value: '83' },
        'content-type' => { name: 'content-type', value: 'application/json' },
        'apim-request-id' => {
          name: 'apim-request-id',
          value: 'c6d14605-10e2-4b03-86a1-9b13e6ba014b'
        },
        'strict-transport-security' => {
          name: 'strict-transport-security',
          value: 'max-age=31536000; includeSubDomains; preload'
        },
        'x-content-type-options' => { name: 'x-content-type-options', value: 'nosniff' },
        'x-ms-region' => { name: 'x-ms-region', value: 'Sweden Central' },
        'date' => { name: 'date', value: 'Tue, 02 Apr 2024 14:52:57 GMT' }
      }
    },
    request: PipelineRequestImpl {
      url: 'https://sweden-central-openai-dfberry.openai.azure.com/openai/assistants?api-version=2024-02-15-preview',
      method: 'POST',
      headers: HttpHeadersImpl {
        _headersMap: Map(7) {
          'accept' => { name: 'accept', value: 'application/json' },
          'content-type' => {
            name: 'content-type',
            value: 'application/json; charset=UTF-8'
          },
          'accept-encoding' => { name: 'Accept-Encoding', value: 'gzip,deflate' },
          'user-agent' => {
            name: 'User-Agent',
            value: 'azsdk-js-openai-assistants-rest/1.0.0-beta.5 core-rest-pipeline/1.15.1 Node/18.16.0 OS/(arm64-Linux-6.6.12-linuxkit)'
          },
          'x-ms-client-request-id' => {
            name: 'x-ms-client-request-id',
            value: '63ce0058-153e-4a45-804b-7e722dcfe9a3'
          },
          'api-key' => {
            name: 'api-key',
            value: 'a6274...'
          },
          'content-length' => { name: 'Content-Length', value: '181' }
        }
      },
      timeout: 0,
      withCredentials: false,
      body: '{"model":"gpt-4-1106-preview","name":"Math Tutor","instructions":"You are a personal math tutor. Write and run code to answer math questions.","tools":[{"type":"code_interpreter"}]}',
      multipartBody: undefined,
      formData: undefined,
      streamResponseStatusCodes: undefined,
      enableBrowserStreams: true,
      proxySettings: undefined,
      disableKeepAlive: false,
      abortSignal: undefined,
      requestId: '63ce0058-153e-4a45-804b-7e722dcfe9a3',
      tracingOptions: undefined,
      allowInsecureConnection: false,
      onUploadProgress: undefined,
      onDownloadProgress: undefined
    },
    status: 400
  },
  details: undefined
}

Expected behavior Found model or information about why model is incorrect. Since this isn't an issue of deployment/deployment name, why can't the model be an enum so I don't have to deal with strings. Can the error say something like model not enabled in resource or model not found in resource to distinguish these two issues?

Screenshots If applicable, add screenshots to help explain your problem.

Additional context More enums please.

diberry commented 6 months ago

There is some connection between the deployment and the model. If I have no deployments, I get a 400, if I have a deployment such as the following image, I can create the assistant, the thread, and the message with an object such as

const options: AssistantCreationOptions = {
  model: "gpt-35-turbo-1106",
  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],
};
image

This connection isn't clear from the reference documentation for the model which describes it as The ID of the model to use. Where is the documentation which describes where to get the model value?

glharper commented 6 months ago

This connection isn't clear from the reference documentation for the model which describes it as The ID of the model to use. Where is the documentation which describes where to get the model value?

I'll modify the PR to update the model doc string to clarify that it corresponds to the "Deployment name" in AOAI Studio