Skip to content

Instantly share code, notes, and snippets.

@kristapratico
Last active November 29, 2023 22:20
Show Gist options
  • Save kristapratico/daa80edd5c9ad02daade3c3b4bfffa18 to your computer and use it in GitHub Desktop.
Save kristapratico/daa80edd5c9ad02daade3c3b4bfffa18 to your computer and use it in GitHub Desktop.
error: 'content' is a required property - 'messages.2'

POST https://resource.openai.azure.com/openai/deployments/gpt-4-1106-preview/chat/completions?api-version=2023-12-01-preview or https://api.openai.com/v1/chat/completions

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "What's the weather like today in Seattle?"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Get the current weather in a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ]
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ]
}

AOAI Response:

{
    "id": "chatcmpl-8QM3pZHioFyGl1BRnT6sodYZG5EDZ",
    "object": "chat.completion",
    "created": 1701292021,
    "model": "gpt-4",
    "prompt_filter_results": [
        {
            "prompt_index": 0,
            "content_filter_results": {}
        }
    ],
    "choices": [
        {
            "index": 0,
            "finish_reason": "tool_calls",
            "message": {
                "role": "assistant",
                "tool_calls": [
                    {
                        "id": "call_NW2AMWCYrSx9vnwusGqRtVO6",
                        "type": "function",
                        "function": {
                            "name": "get_current_weather",
                            "arguments": "{\"location\":\"Seattle, WA\"}"
                        }
                    }
                ]
            }
        }
    ],
    "usage": {
        "prompt_tokens": 89,
        "completion_tokens": 17,
        "total_tokens": 106
    },
    "system_fingerprint": "fp_50a4261de5"
}

OAI Response (Note that content is returned with null):

{
    "id": "chatcmpl-8QMCmnm5UFuD1mQb6tR5CujKtmHF5",
    "object": "chat.completion",
    "created": 1701292576,
    "model": "gpt-4-1106-preview",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": null,
                "tool_calls": [
                    {
                        "id": "call_mF5dyJ5w1GwpagEeNeVhAlJD",
                        "type": "function",
                        "function": {
                            "name": "get_current_weather",
                            "arguments": "{\"location\":\"Seattle, WA\"}"
                        }
                    }
                ]
            },
            "finish_reason": "tool_calls"
        }
    ],
    "usage": {
        "prompt_tokens": 89,
        "completion_tokens": 17,
        "total_tokens": 106
    },
    "system_fingerprint": "fp_a24b4d720c"
}

Now I must add the assistant message in the above response to the next request for tools. I want to just copy it in exactly, but the Azure assistant message does not contain content:

POST https://resource.openai.azure.com/openai/deployments/gpt-4-1106-preview/chat/completions?api-version=2023-12-01-preview

{
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "What's the weather like today in Seattle?"
        },
        {
            "role": "assistant",
            "tool_calls": [
                {
                    "id": "call_NW2AMWCYrSx9vnwusGqRtVO6",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": "{\"location\":\"Seattle, WA\"}"
                    }
                }
            ]
        },
        {
            "role": "tool",
            "tool_call_id": "call_NW2AMWCYrSx9vnwusGqRtVO6",
            "content": "{\"temperature\": \"22\", \"unit\": \"celsius\", \"description\": \"Sunny\"}"
         }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Get the current weather in a given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "celsius",
                                "fahrenheit"
                            ]
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ]
}

AOAI Response:

{
    "error": {
        "message": "'content' is a required property - 'messages.2'",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}

OAI Response: Successful

{
    "id": "chatcmpl-8QMHRKrjPjlsNv3J1YALBpoQY6pxI",
    "object": "chat.completion",
    "created": 1701292865,
    "model": "gpt-4-1106-preview",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "The current weather in Seattle, WA is sunny with a temperature of 22 degrees Celsius."
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 135,
        "completion_tokens": 19,
        "total_tokens": 154
    },
    "system_fingerprint": "fp_a24b4d720c"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment