Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gpt-4o: fixed failing tool/function calling #175

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

adubovik
Copy link
Collaborator

@adubovik adubovik commented Nov 19, 2024

Usually, when the assistant replies with a tool call, the content is set to null.

This should be accounted for in the follow-up tokenization of the chat completion request. The following method doesn't do it:

content = message.get("content", "")
custom_content = message.pop("custom_content", {})
attachments = custom_content.get("attachments", [])

It was made more forgiving:

        content = message.get("content") or ""
        custom_content = message.pop("custom_content", None) or {}
        attachments = custom_content.get("attachments") or []
How to reproduce the bug

Set the .env file:

GPT4O_DEPLOYMENTS=gpt-4o-2024-05-13

Send the following request to the adapter-openai running locally at port 5006:

MODEL=gpt-4o-2024-05-13
ENDPOINT=...
KEY=...

URL=http://0.0.0.0:5006/openai/deployments/${MODEL}/chat/completions?api-version=2024-02-01

curl -X POST $URL \
  -H "X-UPSTREAM-ENDPOINT:https://${ENDPOINT}.openai.azure.com/openai/deployments/${MODEL}/chat/completions" \
  -H "X-UPSTREAM-KEY:${KEY}" \
  -d '{
"stream": false,
"messages": [
  {
    "role": "user",
    "content": "What is the weather like in Boston and London today?",
    "custom_content": null
  },
  {
    "role": "assistant",
    "content": null,
    "custom_content": {
      "attachments": null
    },
    "tool_calls": [
      {
        "id": "call_Q6aBknWA6Jx9H5hvCEHpfJsv",
        "type": "function",
        "function": {
          "name": "get_current_weather",
          "arguments": "{\"location\": \"Boston, MA\", \"unit\": \"celsius\"}"
        }
      },
      {
        "id": "call_LNAJMTe5BddYZ49Te8QmHo9O",
        "type": "function",
        "function": {
          "name": "get_current_weather",
          "arguments": "{\"location\": \"London, UK\", \"unit\": \"celsius\"}"
        }
      }
    ]
  },
  {
    "role": "tool",
    "tool_call_id": "call_Q6aBknWA6Jx9H5hvCEHpfJsv",
    "content": "30"
  },
  {
    "role": "tool",
    "tool_call_id": "call_LNAJMTe5BddYZ49Te8QmHo9O",
    "content": "20"
  }
],
"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": ["unit", "location"]
      }
    }
  }
],
"tool_choice": "auto",
"temperature": 0.0
}'

It fails with the error:

  File "./aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 152, in <listcomp>
    await self.transform_message(message) for message in messages
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 128, in transform_message
    content_meta = await self.download_content_images(content)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 102, in download_content_images
    for content_part in content:
TypeError: 'NoneType' object is not iterable

@adubovik adubovik self-assigned this Nov 19, 2024
@adubovik adubovik force-pushed the fix/fixed-failing-function-calling-in-gpt-4o branch from 0a3da1c to 4bfd72d Compare November 19, 2024 13:49
@adubovik
Copy link
Collaborator Author

adubovik commented Nov 19, 2024

/deploy-review

Environment URL: https://chat-ai-dial-adapter-openai-pr-175.nightly-test.deltixhub.io
E2E tests status: success

@adubovik adubovik merged commit 79b7d11 into development Nov 19, 2024
8 checks passed
@adubovik adubovik deleted the fix/fixed-failing-function-calling-in-gpt-4o branch November 19, 2024 16:20
adubovik added a commit that referenced this pull request Nov 19, 2024
* fix: truncated error messages in plain text tokenizer (#172)
* fix: removed content-encoding header to avoid decoding errors (#174)
* chore: bump aiohttp from 3.10.2 to 3.10.11 (#173)
* fix: gpt-4o: fixed failing tool/function calling (#175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants