Is it possible to have tool_call and content in single completion message

I got a response from GPT-4 Turbo model containing both tool_call and message content. Is that expected? According to this Chat Completion Message Content + Function_Call - #2 by Foxabilo

we should only get either function call or content.

ChatCompletionMessage(
        content='Thought:\nThe workflow involves several steps, including:\n\n1. Opening the OpenAI website in a web browser automation context using Playwright.\n2. Navigating to the Login page.\n3. Clicking on the Login with Google button.\n4. Entering the email "" and proceeding with the login (since I don\'t have access to the password, this step would need to be done manually or skipped in this context).\n5. Navigating to the settings and then to the Organization section.\n6. Finding and copying the Organization ID.\n7. Printing the Organization ID.\n\nAction Plan:\n1. Start by setting up the initial script to launch the browser and open the OpenAI website.\n2. Use exploratory code snippets to obtain the correct selectors or XPaths for each step in the process.\n3. Implement each stage one by one, building up the script incrementally.\n4. Include error handling and wait times for possible network delays and page load times.\n5. Since I cannot actually perform the Google login, we will have to either mock this process or skip that part of the automation script.\n\nFirst, I will provide you with the initial Python script using Playwright to launch the browser and open the OpenAI website. If this is okay with you, I will proceed with the action of executing this first step.',
        role="assistant",
        function_call=None,
        tool_calls=[
            ChatCompletionMessageToolCall(
                id="call_6g7a7STxdqS7DhOX9GOp8Wyx",
                function=Function(
                    arguments="{\"code_block\":\"from playwright.sync_api import sync_playwright\\n\\nwith sync_playwright() as p:\\n    browser = p.chromium.launch(headless=False)\\n    page = browser.new_page()\\n    page.goto('https://openai.com/')\\n\\n    # This is where we would continue to navigate to the login\\n    # Since I can't interact with Google login, skipping that\\n\\n    browser.close()\\n\\n    print('Opened the OpenAI website successfully')\\n\"}",
                    name="exec_python_code",
                ),
                type="function",
            )
        ],
    ),
2 Likes

Yes, it is possible and you should handle it appropriately. It’s just been trained out of the AI models a bit more.

The AI will see the text it is writing as a preface to the post-function AI output or what a function might display in the UI.

1 Like

hi @rushout09 !

Thanks for sharing!

I’m curious how did you make that happen haha? I’m trying to make it happen cause I want to show something before the function calling takes time to complete. And does it always work or only at times?

thanks for sharing @_j ! Do you know if this still works / is reliable?

You can prompt the model to do so maybe. In my case, it was automatically returning both tool_call and content at times randomly.

Another thing you can do is add an additonal param in funciton calling and use that to input from gpt to display to user.

3 Likes

Thanks so much for the suggestion @rushout09 !

I guess prompting it to do the message isn’t reliable then. But the additional param makes sense!

Are you using the SDK directly or using something like vercel’s ai sdk, just curious!

Hey sorry for the late reply. I am using openai python sdk.