javascriptaxiosopenai-apifine-tuning

OpenAI API error when using a fine-tuned model: "The model `xxxxx` does not exist"


I'm trying to do a chatbot with a fine tuned model.

I'm doing my request like this:

    const API_KEY = "/";
    const ORG_ID = "/";
    const headers = {
      "Content-Type": "application/json",
      Authorization: "Bearer " + API_KEY,
      "OpenAI-Organization": ORG_ID,
    };
    const res = await axios.post(
      "https://api.openai.com/v1/chat/completions",
      {
        model: "ft-modelname",
        messages: [
          {
            role: "system",
            content: "your name is Name.",
          },
          {
            role: "user",
            content: message,
          },
        ],
      },
      { headers }
    );

And after listing my models with the API I can see it, it does exist.

But I have this error in the console:

{
    "error": {
        "message": "The model `ft-modelname` does not exist",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

After looking up, i can't find a way to do this, some people use open ai engine api instead of completion, but it don't work too.
Do you have any ideas ?

Thank you.

Edit: It works when I'm not using a fine tune model


Solution

  • UPDATE: 22 August 2023

    Fine-tuning for GPT-3.5 is now available, as stated in the official OpenAI blog:

    Fine-tuning for GPT-3.5 Turbo is now available, with fine-tuning for GPT-4 coming this fall.

    Consequently, the Chat Completions API (i.e., the GPT-3.5 API) endpoint can be used for a fine-tuned model, but only for a GPT-3.5 fine-tuned model. For a GPT-3 fine-tuned model, use the Completions API (i.e., the GPT-3 API) endpoint.

    As stated in the official OpenAI documentation:

    When a job has succeeded, you will see the fine_tuned_model field populated with the name of the model when you retrieve the job details. You may now specify this model as a parameter to in the Chat Completions API (for gpt-3.5-turbo) or legacy Completions API (for babbage-002 and davinci-002), and make requests to it using the Playground.


    Problem

    You're using the wrong API endpoint.

    Solution

    Use the Completions API (i.e., the GPT-3 API) endpoint instead of the Chat Completions API (i.e., the GPT-3.5 API) endpoint.

    As stated in the official OpenAI documentation:

    When a job has succeeded, the fine_tuned_model field will be populated with the name of the model. You may now specify this model as a parameter to our Completions API, and make requests to it using the Playground.

    In general

    Python

    import os
    import openai
    
    openai.api_key = os.getenv("OPENAI_API_KEY")
    
    openai.Completion.create(
        model = FINE_TUNED_MODEL,
        prompt = YOUR_PROMPT)
    

    NodeJS

    const { Configuration, OpenAIApi } = require("openai");
    
    const configuration = new Configuration({
      apiKey: process.env.OPENAI_API_KEY,
    });
    
    const openai = new OpenAIApi(configuration);
    
    const response = await openai.createCompletion({
      model: FINE_TUNED_MODEL
      prompt: YOUR_PROMPT,
    });
    

    cURL

    curl https://api.openai.com/v1/completions \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"prompt": YOUR_PROMPT, "model": FINE_TUNED_MODEL}'
    

    OpenAI CLI

    openai api completions.create -m <FINE_TUNED_MODEL> -p <YOUR_PROMPT>
    

    Your case

    Try this:

    const res = await axios.post(
      "https://api.openai.com/v1/completions", {
        model: "ft-modelname",
        prompt: "Say this is a test",
      }, {
        headers
      }
    );