Microsoft spun out Guidance after this gem was released, and soon thereafter Guidance itself was updated to be more pure-python based and not used Handlebars. That makes it not worth trying to use from Ruby any longer, so this project is deprecated.
This Gem wraps https://github.com/microsoft/guidance for use in Ruby. See documentation at in the Guidance repo for info on how to use it.
This requires a version of python that includes the library version. Development has been done using 3.10.9 which can be installed with the below. You must also install Guidance.
env PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install 3.10
pyenv global 3.10
pip install -U guidance
To install the gem using bundle:
bundle add guidance
Via Ruby gems directly:
$ gem install guidance
You will need to configure credentials for the backing LLM service you use. This is not well-documented in Guidance but can be found in the source fairly easy such as at https://github.com/microsoft/guidance/blob/d2c5e3cbb730e337b9bee20520eb694bd43e5f38/guidance/llms/_openai.py#L160 which for OpenAI. For OpenAI (as the most common service), the easiest option is using an env variable for the below:
export OPENAI_API_KEY=<your key>
These keys can be found at https://platform.openai.com/account/api-keys if you have an account.
require "guidance"
Make sure you installed with the library version installed. Note that even with that option, we have seen issues with Python 3.7 but have not fully analyzed the issue.
Make sure you installed the pip module.
PyCall also uses the library version of Python which does not get its paths set the same way. Try finding where your guidance library was installed and adding it to the ENV var "PYTHONPATH"
If you want to report a bug, or have ideas, feedback or questions about the gem, let me know via GitHub issues and I will do my best to provide a helpful answer. Happy hacking!
The gem is available as open source under the terms of the MIT License.
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Pull requests are welcome!