Skip to content

johnnymo87/openai-ruby-client

Repository files navigation

openai-ruby-client

This is just a personal script for how I use the openai-ruby gem to interact with OpenAI's API, building and sending a prompt to the o1-preview model.

Install

  1. Install or update rbenv (and ruby-build to get access to recent releases of python).
    brew update && brew install ruby-build rbenv
    brew update && brew upgrade ruby-build rbenv
    
  2. Install ruby.
    rbenv install $(cat ./.ruby-version)
    
  3. Install ruby gems.
    bundle
    

Environment Variables

This application requires an OpenAI API key. You can set it as an OPENAI_ACCESS_TOKEN environment variable in your shell or in an .envrc file. Below are steps for how to use direnv to manage environment variables, but you can also simply set the environment variable in your shell.

  1. Install direnv and configure your shell to enable automatic environment variable loading.
    brew install direnv
    
  2. Update your dotfiles to use the direnv hook.
    # in e.g. ~/.bash_profile
    
    if which direnv > /dev/null; then
      eval "$(direnv hook bash)"
    fi
    
  3. Copy .envrc.example to .envrc.
    cp .envrc.example .envrc
    
  4. Fill out .envrc.
  5. Source the environment variables defined in .envrc.
    direnv allow
    

Run

Write a prompt in a file in the prompts/ directory, e.g. prompts/o1-preview-000001. Consider using this script to merge many files into one in a way that's useful when prompting.

There's an o1_preview_client.rb file. Use it to execute the prompt.

bundle exec ruby o1_preview_client.rb execute prompts/o1-preview-000001

The result will be in the log/ directory. There's no support for follow up prompts, so if there's anything from the result that you want to use in a follow up prompt, you'll have to copy it manually.

Contributing

If you'd like to contribute to the project, please feel free to submit a pull request or open an issue to discuss your ideas.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages