Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnnymo87/openai-ruby-client
https://github.com/johnnymo87/openai-ruby-client
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/johnnymo87/openai-ruby-client
- Owner: johnnymo87
- License: mit
- Created: 2023-06-09T12:58:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-24T18:19:06.000Z (14 days ago)
- Last Synced: 2024-10-26T06:21:48.922Z (13 days ago)
- Language: Ruby
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## openai-ruby-client
This is just a personal script for how I use [the `openai-ruby` gem](https://github.com/alexrudall/ruby-openai) to interact with OpenAI's API, building and sending a prompt to [the `o1-preview` model](https://platform.openai.com/docs/models/o1).
## 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
```
1. Install ruby.
```
rbenv install $(cat ./.ruby-version)
```
1. Install ruby gems.
```
bundle
```### Environment Variables
This application requires [an OpenAI API key](https://platform.openai.com/docs/quickstart). You can set it as an `OPENAI_ACCESS_TOKEN` environment variable in your shell or in [an `.envrc` file](https://github.com/direnv/direnv). 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
```
1. Update your dotfiles to use the direnv hook.
```
# in e.g. ~/.bash_profileif which direnv > /dev/null; then
eval "$(direnv hook bash)"
fi
```
* If you use zsh instead of bash, replace `direnv hook bash` with `direnv hook zsh`. See [the hooks documentation page in the direnv GitHub repository](https://github.com/direnv/direnv/blob/master/docs/hook.md) for more details.
1. Copy `.envrc.example` to `.envrc`.
```
cp .envrc.example .envrc
```
1. Fill out `.envrc`.
1. 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](https://gist.github.com/johnnymo87/4701b6671730768ba95f19a5ee29a177) 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](LICENSE) file for more information.