openai-crystal
OpenAI API client library to access GPT-3 in Crystal
Installation
-
Add the dependency to your
shard.yml
:dependencies: openai: github: sferik/openai-crystal
-
Run
shards install
Usage
require "openai"
openai_client = OpenAI::Client.new(api_key: ENV.fetch("OPENAI_API_KEY"), default_engine: "ada")
# List Engines
openai_client.engines
# Retrieve Engine
openai_client.engine("babbage")
# Search
openai_client.search(documents: ["White House", "hospital", "school"], query: "the president")
# Create Completion
openai_client.completions(prompt: "Once upon a time", max_tokens: 5)
# Stream Completion
openai_client.completions(prompt: "Once upon a time", max_tokens: 100) do |completion|
puts completion.choices.first.text
end
Contributing
- Fork it (https://github.com/sferik/openai-crystal/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Erik Berlin - creator and maintainer
Repository
openai-crystal
Owner
Statistic
- 49
- 45
- 2
- 0
- 2
- over 1 year ago
- August 13, 2020
License
MIT License
Links
Synced at
Sun, 17 Nov 2024 16:59:48 GMT
Languages