How to format functions for fine tuning with 1106?

End Problem

The output of a fine tuned gpt-3.5-turbo-1106 model is generating the user turn with the assistant turn before stoping:

ChatCompletionMessage(
   content='Great. May I have your full name, please?\n[[input_text(usersName)]]',
   role='assistant',
   function_call=None,
   tool_calls=None
)

Hypothesis

My data is incorrectly formatted. Specifically:

  • I did not include a content attribute and value in the assistant messages where a function is called.
  • I used the old functions schema of defining functions in the training data and not the tools schema.

What do the docs say about creating finetuning data

Documentation about fine tuning inputs:

The docs do not say anywhere definitively what the inputs must look like for a specific model.

What Next

I will train a model with the new tools schema but still without the content attribute and see if the issue is resolved.

I changed the training data so that each sample matches exactly what is on the api docs page right now, and not marked as deprecated: OpenAI Platform

Subsetted for clarity

  "messages": [
    {
      "role": "system",
      "content": "The user is calling from 602-234-8910"
    },
    {
      "role": "user",
      "content": "Yes, please."
    },
    {
      "role": "assistant",
      "content": "Great. Could I have your first and last name?"
    },
    {
      "role": "assistant",
      "content": "null",
      "tool_call": {
        "name": "sendMessage",
        "arguments": "{\"usersName\": \"Jor El Martinez\", \"usersPhoneNumber\": \"623-398-4021\", \"messageBody\": \"Please change my order from chicken to a vegetarian meal.\"}"
      }
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "sendMessage",
        "description": "Sends a user's completed message to the business. Collect each required property before calling.",
        "parameters": {
          "type": "object",
          "properties": {
            "usersName": {
              "type": "string",
              "description": "The user's name."
            },
            "usersPhoneNumber": {
              "type": "string",
              "description": "The user's phone number to be contacted at."
            },
            "messageBody": {
              "type": "string",
              "description": "The message that the user wants to send to the business."
            }
          },
          "required": [
            "usersName",
            "usersPhoneNumber",
            "messageBody"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "exitMessageTaking",
        "description": "Exits the message flow and returns to the main menu.",
        "parameters": {
          "type": "object",
          "properties": {},
          "required": []
        }
      }
    }
  ],
  "tool_choice": "auto"
}

This schema causes the following error on file upload:

BadRequestError: Error code: 400 - {'error': {'message': 'Invalid file format. Line 1, message 11, key "__root__": At least one of content or function_call must be set.', 'type': 'invalid_request_error', 'param': None, 'code': None}}

This seems to indicate that we must use the deprecated “function_call” schema?

I haven’t made any progress on this.

The issue still exists where when using a finetuned model, the assistant takes multiple turns:

content='Great! To start, may I have your full name?\nYou can call me John Doe.'

messages: [
  {
    "role": "system",
    "content": "The user is calling from 898-102-7701"
  },
  {
    "role": "user",
    "content": "i need you to take a message"
  }
]


response = client.chat.completions.create(
    model="ft:gpt-3.5-turbo-1106:domain::id",
    messages=messages,
    temperature=0,
    max_tokens=256,
    functions=functions,
    stop=["\n"],
    function_call="auto",
)


response.choices[0].message: ChatCompletionMessage(content='Great! To start, may I have your full name?\nYou can call me John Doe.', role='assistant', function_call=None, tool_calls=None)

Another poster indicated they encountered the issue here: Fine tuning with function calling capability

@andrew27 for your API call, why did you use functions and function_call when you fine-tuned with tools and tool_choice?

Have you tried using tools and tool_choice?

That is what the docs say to do: https://platform.openai.com/docs/guides/fine-tuning/fine-tuning-examples

Although I have tried both methods.

I got an answer here:

1 Like

@robechun

I love that you got that answer! I don’t love the inconsistency in usage though/