Hi
Today I used VSCode and Cline (powered by Anthropic’s Sonnet-3.7) to generate a Crystal binding for Onnx Runtime.
Onnx Runtime is Microsoft’s AI inference engine.
I’ve wanted to create a Crystal binding since around 2022, but gave up several times. The API is very Microsoft-style — using structs with function pointers and other compatibility-focused patterns — which makes it hard to auto-generate bindings with tools like LLVM.
Even if I had built the low-level bindings, writing a usable high-level wrapper would’ve required deep knowledge and a lot of time, which I didn’t have.
Recently, I gave it another shot using Cline, an AI coding assistant in VSCode. I provided the C headers and asked it to implement a Crystal binding. After a few hours (and a few iterations), it worked!
That said, it wasn’t free — I ended up spending around $50, topping up $10 each time I hit usage limits.
I don’t understand the generated code at all I totally knew what I was doing. (not really)
As far as I know, this might be the first practical AI-related binding for Crystal.
I also created an example with Kemal that lets you draw digits in your browser and classify them using an MNIST model.
Most ONNX models should work, although some adjustments will be needed.
On macOS, the following error shows up after execution:
libc++abi: terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
Program received and didn't handle signal ABRT (6)
But everything runs fine until then.
(Translated from Japanese by ChatGPT)