Skip to main content

Patching multi_tool_use.parallel in OpenAI

Quick monkey-patching fix for OpenAI's hallucinated multi_tool_use.parallel issue.

This is a simple workaround for this issue where the GPT ChatCompletions API sometimes hallucinates a strange alternative way of calling multiple tools at once. In my experience, these calls at least always follow a predictable structure and can be hotfixed to look like normal, legal tool calls. This patch does that, and also rewrites the message accordingly (which, in my experience, makes the model perform calls work in the normal expected way.)

This fix will be redundant soon, but it looks like I am not the only one who occasionally runs into this error, so I thought I would share this workaround.

Installation and usage

pip install openai-multi-tool-use-parallel-patch

In your code:

import openai_multi_tool_use_parallel_patch  # import applies the patch
import openai

client = openai.AsyncOpenAI(...)  # sync client will be patched too

...

response = await client.chat.completions.create(...)  # no changes to the call signature or response vs vanilla OpenAI client

That's it - theoretically this should work even if you import openai first, but at the least you will need to make sure not to create your openai.OpenAI or openai.AsyncOpenAI instances before importing this patch.

Metadata

Release files for openai-multi-tool-use-parallel-patch 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-multi-tool-use-parallel-patch 0.2.0
File Size Uploaded
openai_multi_tool_use_parallel_patch-0.2.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-multi-tool-use-parallel-patch 0.2.0
File Interpreter ABI Platform
openai_multi_tool_use_parallel_patch-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / openai_multi_tool_use_parallel_patch-0.2.0.tar.gz

Download URL openai_multi_tool_use_parallel_patch-0.2.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7ceb1150df00ddb21b11556520cd94b8b151d6199245e1d6aabc1c85ed442cc
BLAKE2b-256 checksum
How to use checksums
33e5af197f1dc70aa32cf978587f55e25ce11c20df022c2690eb2b416b16680a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.7.17 Darwin/23.1.0

Release files / openai_multi_tool_use_parallel_patch-0.2.0-py3-none-any.whl

Download URL openai_multi_tool_use_parallel_patch-0.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
850382c7e7559458caf075d7c0fa5e838b0037de894cd0a5be147e519415d618
BLAKE2b-256 checksum
How to use checksums
25a2ed1fe194d823577f8cabd7e68b2b4550508620d0268caa6d55df3b4d6f5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.7.17 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page