orbai
: A Ruby DSL for OpenAI
Welcome to orbai
, an idiomatic Ruby DSL for OpenAI's powerful API. With the
combination of Ruby's natural language processing strengths and OpenAI's
advanced capabilities, your applications are set to take a massive leap forward.
Disclaimer
Please be aware that orbai
is in its early stages and is not maintained
regularly. While we aim to provide the best, there might be bugs or
unimplemented features. Your patience and contributions are highly appreciated.
Quick Start (For Rubyists)
- Install the orbai gem:
gem install orbai
-
Have an OpenAI API key in your
environment. By default, orbai
will look for OPENAI_API_KEY
..
-
Use orbai
to query OpenAI:
require "orbai"
Orbai.query("What's the capital of France?")
Rationale
- Ruby is the Best Language for DSLs: Ruby's expressiveness has made it the
go-to language for Domain Specific Languages, finding its use in a myriad of
practical domains.
- OpenAI & Ruby: OpenAI offers transformative capabilities to the domains
where Ruby DSLs excel.
- orbai: Born out of the need for an expressive, easy-to-integrate tool
that merges the power of OpenAI and the elegance of Ruby.
Getting Started (For Newbies)
- Installing Ruby: If you're a technical person, we recommend using
asdf-vm for version management.
- Learning Ruby: If you're new to Ruby...
TODO
- Follow the "Quick Start" guide above to get up and running.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run
rake spec
to run the tests. You can also run bin/console
for an interactive
prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To
release a new version, update the version number in version.rb
, and then run
bundle exec rake release
, which will create a git tag for the version, push
git commits and the created tag, and push the .gem
file to
rubygems.org.
Contributing
We welcome contributions to orbai
! If you stumble upon issues or have features
you'd like to suggest, please:
Help Wanted!
- 🔲 Feedback
- 🔲 Docs
- 🔲 Tests
- 🔲 Triage
- 🔲 Imagination
Orbai::DSL
Simple Query API
require "orbai"
Orbai.query("What is your favorite color?")
Wishlist
- 🔲 Config DX
- 🔲 Roles Builder DX
- 🔲 Context Params DX
- 🔲 Extract structured data
- 🔲 Functions DX
- 🔲 Images DX
- 🔲 Audio DX
- 🔲 Files DX
- 🔲 Embeddings DX
- 🔲 Fine-tuning DX
Orbai
Module / HttpClient
HTTP Methods
The Orbai
module is just a container for everything else.
For ease of use, it includes http getters through an HttpClient
singleton.
The HTTP getters throw an Orbai::HTTPClient::Error
if the request fails. The
OpenAI API type
field from the error response is assigned to
Orbai::HTTPClient::Error#type
.
Example
Orbai.get("/chat/completions", model: 'gpt-3.5-turbo', messages: [
{role:'system',content:'Act as a helpful prompt.'},
{role:'user',content:'What is the capital of France?'},
])
{"id"=>"chatcmpl-XXXXXXXX",
"object"=>"chat.completion",
"created"=>1697444538,
"model"=>"gpt-3.5-turbo-0613",
"choices"=>
[{"index"=>0,
"message"=>
{"role"=>"assistant", "content"=>"The capital of France is Paris."},
"finish_reason"=>"stop"}],
"usage"=>{"prompt_tokens"=>24, "completion_tokens"=>7, "total_tokens"=>31}}
Orbai
Shortcuts / HttpClient
HTTP Methods
c = Orbai::HttpClient.new
c.http_client
c.get(path, **params)
c.post(path, **params)
c.put(path, **params)
c.patch(path, **params)
c.delete(path, **params)
c.http_request(method, path, **params)
Orbai::HttpClient
The HttpClient
class is used to make requests to the OpenAI API. It returns
the JSON response from the API as a ruby hash.
Example:
c = Orbai::HttpClient.new
c.chat_completions(
model: 'gpt-3.5-turbo',
messages: [
{role:'system',content:'Act as a helpful prompt.'},
{role:'user',content:'What is the capital of France?'},
],
)
{"id"=>"chatcmpl-XXXXXXXX",
"object"=>"chat.completion",
"created"=>1697983333,
"model"=>"gpt-3.5-turbo-0613",
"choices"=>
[{"index"=>0,
"message"=>
{"role"=>"assistant", "content"=>"The capital of France is Paris."},
"finish_reason"=>"stop"}],
"usage"=>{"prompt_tokens"=>24, "completion_tokens"=>7, "total_tokens"=>31}}
API Methods Cheatsheet
c = Orbai::HttpClient.new
c.chat_completions(**params)
c.completions(**params)
c.edits(**params)
c.create_image(**params)
c.create_image_edit(**params)
c.create_image_variation(**params)
c.create_embedding(**params)
c.create_fine_tuning_jobs(**params)
c.list_fine_tuning_jobs(**params)
c.retrieve_fine_tuning_job(id, **params)
c.cancel_fine_tuning_job(id, **params)
c.list_fine_tuning_events(id, **params)
c.create_transcription(**params)
c.create_translation(**params)
c.list_files(**params)
c.upload_file(**params)
c.delete_file(id, **params)
c.retrieve_file(id, **params)
c.file_content(id, **params)
c.list_models(**params)
c.retrieve_model(id, **params)
c.delete_model(id, **params)
c.create_moderation(**params)