openai

Version, currently main branch1 version
  • main branchlatestMar 27, 2023

github.com/sferik/openai-crystal

OpenAI API client library to access GPT-3 in Crystal

54 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  openai:
    github: sferik/openai-crystal
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.35.1
License
MIT
Author
Erik Berlin <sferik@gmail.com>

Dependencies

Development Dependencies

  • ameba*github: crystal-ameba/amebadev
  • webmock*github: manastech/webmock.crdev

README

# OpenAI API client library to access GPT-3 in Crystal

[![Build Status](https://travis-ci.org/sferik/openai-crystal.svg?branch=main)](https://travis-ci.org/sferik/openai-crystal)

## Installation

1. Add the dependency to your `shard.yml`:

   ```yaml
   dependencies:
     openai:
       github: sferik/openai-crystal
   ```

2. Run `shards install`

## Usage

```crystal
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

1. Fork it (<https://github.com/sferik/openai-crystal/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## Contributors

- [Erik Berlin](https://github.com/sferik) - creator and maintainer