I use https://gist.github.com/nicowilliams/ea2fa2b445c2db50d2ee650... for this.
You could expose this as a tool for an LLM.