Correct Array Format for Function Calling Open AI's ChatGPT

30 views Asked by At

I am integrating a ChatGPT with function calling for specific tasks. However, during my research I've encountered two different array structures for prompt history. I'm unsure which one is the correct or more efficient for maintaining historical record for function calls with GPT. Neither one of them produce errors during the call, as function is an allowed role.

What I am currently using:

{
    "messages": [
        {
            "role": "system",
            "content": ""
        },
        {
            "role": "user",
            "content": "What is the weather like in Boston?"
        },
        {
            "role": "assistant",
            "content": "20 C",
            "name": "get_current_weather",
            "function_call": {
                "name": "get_current_weather",
                "arguments": "{\n  \"location\": \"Boston, MA\"\n}"
            }
        }
    ]
}

What I have seen a few places online:

{
    "messages": [
        {
            "role": "system",
            "content": ""
        },
        {
            "role": "user",
            "content": "What is the weather like in Boston?"
        },
        {
            "role": "assistant",
            "content": "What is the weather like in Boston?",
            "function_call": {
                "name": "get_current_weather",
                "arguments": "{\n  \"location\": \"Boston, MA\"\n}"
            }
        },
        {
            "name": "get_current_weather",
            "role": "function",
            "content": "20 C"
        }
    ]
}

Can anyone shed some light on these two and when to use each one?

0

There are 0 answers