Blender is a powerful tool, but sometimes it's easier to use plain English to accomplish your task.
This project presents a Blender add-on that adds an interface for communicating with Llama 3 70b which can perform tasks in Blender 3D given English instructions.
VideoDemo:
How does it work?TL;DR: Llama 3 70b (a powerful LLM for which the AMD Radeon Pro W7900 is large enough to handle while also managing 3D content creation) is configured to be a Blender Python API assistant and your commands are converted into API calls. Erroneous commands are caught and the LLM (with a slightly different configuration) is re-prompted to fix them.
Blender is a free and open-source 3D content creation suite. Its interface is written in Python, meaning there exists a Python command for pretty much everything. An add-on to Blender is a Python script that can invoke arbitrary Blender commands.
LLMs like Llama 3 70b have been trained on Blender's Python API and also understand how to structure Python code very well, all that is left is a means for prompting and a device to perform inferencing quickly. That is where the AMD Radeon Pro W7900 comes in. This pro-level GPU has 48 GB of VRAM which is enough to host Llama 3 70b (with minimal quantization) and perform content creation in Blender.
To quickly set up and manage the LLM, Ollama was used. It supports ROCm GPUs and can efficiently manage the device's VRAM.
To help with building the Python commands, a bit of prompt engineering was put in. When handling a prompt, the model is instructed about the context of what it is doing (Blender Python) and told to ignore unrelated tasks and only answer with code (no explanation). That way responses are faster and the commands can be easily parsed. Along with the user's prompt, a dictionary with the current objects in the scene and their locations are also supplied to the model as context. Once the model generates the appropriate Python code, it is executed in Blender's interpreter and the command is shown in the UI for reference. If an error occurs while trying to evaluate the command (since LLMs can sometimes make mistakes), a new prompt is generated that contains the Python traceback and given to the LLM to fix in a recursive loop. If it can't resolve the error after a few tries it will show the error.
UsageThis add-on was tested on Ubuntu 22.04.4 LTS with ROCm 6 installed. The add-on is not dependent on the OS or specific ROCm version though so if you can get ROCm installed and Ollama running with ROCm support then that's all that is needed.
1. Install Blender 3D
2. Install ROCm
2. Install and serve Ollama from http://localhost:11434
. Using Docker is the easiest method.
3. From the code section or the GitHub repo, download the add-on script called ai_assistant.py
.
4. Launch Blender. From Edit > Preferences > Add-ons > Install, select the downloaded script. Click the enable checkbox once installed.
5. Press "n
" to open the sidebar. Select the "AI Assistant" tab to show the UI.
6. Type in a command like "Add a cube above the current one" and press submit.
After some thinking, you should see a cube appear above the default one!
If this is the first time Ollama and the Llama 3 70b model is being used you may have to wait a while for Ollama to download and initialize the model. Downloads are cached and the model will live in VRAM for quick access. After 5 minutes of inactivity it will be unloaded (Ollama's default).
Where to go from here?All code is free and open-source and can be modified to your liking. For example, the model prompt settings are on lines 46 - 49
. One may want to extend the time the LLM lives in VRAM. To do so, simply add the option keep_alive = -1
to keep the model indefinitely (or = 30m
for 30 minutes).
One future direction is to try and curate a training data set to fine-tune these models. However, Llama 3 70b is pretty good already.
Feedback is appreciated in the command and issue board. Thank you!
Comments