The magic that they are doing is pretraining AI and recognizing specific special tokens to invoke backend API methods. This trained AI is disabled if a tool or function isnât passed âofficiallyâ.
Code
Example trained "function calling" forced into the AI:
system = """
You are ImageCreate.
You employ your python ability to perform one task:
- Create and display 1280x720 images per user specification.
# Tools
## python
// You have a stateless Python Jupyter notebook without file storage.
// Additional libraries installed include:
// PIL (pillow), numpy, io, IPython
// Important: PIL's Image.show() method is broken, \
so use IPython.display for GUI user display of Image object.
## functions
namespace functions {
// do not use functions, only python tool is available
type disabled_function = (_: {
// This null property also will never be used, only use python
null_value: any,
}) => any;
} // namespace functions
""".strip()
user = "Show an image with thousands of colorful circles by writing and executing python code."
messages = [{"role": "system", "content": system},
{"role": "user", "content": user}]
Output from gpt-4-vision-preview
or gpt-4-1106-preview
:
Certainly! I will create an image with a multitude of colorful circles using Python. Letâs get started.
Thatâs all, there is an introduction and nothing happens except âstopâ.
However, for the next step, all I will do is include a do-nothing placeholder toolâŚeverything else is the same system prompt language, simulating what OpenAI backend creates.
Output with dummy function namespace as tools
API parameter:
â output as a tool_calls= argument â
from PIL import Image, ImageDraw
import numpy as np
from IPython.display import display
# Create an image with a white background
width, height = 1280, 720
image = Image.new("RGB", (width, height), "white")
draw = ImageDraw.Draw(image)
# Generate random circles
num_circles = 1000
for _ in range(num_circles):
# Random position
x, y = np.random.randint(0, width), np.random.randint(0, height)
# Random radius
r = np.random.randint(5, 50)
# Random color
color = (np.random.randint(0, 255), np.random.randint(0, 255), np.random.randint(0, 255))
# Draw the circle
draw.ellipse((x-r, y-r, x+r, y+r), fill=color, outline=None)
# Display the image
display(image)
Conclusion
You cannot activate the pretraining on functions or tools unless they decide to let you. For gpt-4-vision, they do not let you.