GithubHelp home page GithubHelp logo

itikhonenko / openai-client Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 172 KB

The gem that makes it easier to use the OpenAI API

License: MIT License

Ruby 99.51% Shell 0.49%
chatgpt chatgpt-api codex gpt-3 openai openai-api ruby

openai-client's Introduction

Openai::Client

This gem is a wrapper for calling the OpenAI and GPT-3 APIs.

Installation

Add this line to your application's Gemfile:

gem 'openai-client'

And then execute:

bundle

Or install it yourself as:

gem install openai-client

Usage

require 'openai-client'

Openai::Client.configure do |c|
  c.access_token    = 'access_token'
  c.organization_id = 'organization_id' # optional
end

OpenAI Models API

List Models

Openai::Client.models.list

Find Model

Openai::Client.models.find(model_id)
# Models
Openai::Client.models.list

# Find a Model
Openai::Client.models.find(model_id)

OpenAI Completions API

Create Completion

request_body = {
  model: 'text-davinci-003',
  prompt: 'Say this is a test',
  max_tokens: 7,
  temperature: 0,
  top_p: 1,
  n: 1,
  stream: false,
  logprobs: nil,
  stop: "\n"
}
Openai::Client.completions.create(request_body)

API Documentation

OpenAI Edits API

Create Edit

request_body = {
  model: 'text-davinci-edit-001',
  input: 'What day of the wek is it?',
  instruction: 'Fix the spelling mistakes'
}
Openai::Client.edits.create(request_body)

API Documentation

OpenAI Image API

Create an Image

request_body = {
  prompt: 'A cute baby sea otter',
  n: 1,                  # between 1 and 10
  size: '1024x1024',     # 256x256, 512x512, or 1024x1024
  response_format: 'url' # url or b64_json
}
response = Openai::Client.images.create(request_body)

API Documentation

Create an Image Edit

request_body = {
  image: '/absolute/path/to/image/you/want/to/change/img.png'
  mask: '/absolute/path/to/mask.png'
  prompt: 'A cute baby sea otter wearing a beret',
  n: 1,                  # between 1 and 10
  size: '1024x1024',     # 256x256, 512x512, or 1024x1024
  response_format: 'url' # url or b64_json
}
response = Openai::Client.images.edit(request_body)
  • image - must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
  • mask - an additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.

API Documentation

Create an Image Variation

request_body = {
  image: '/absolute/path/to/image.png'
  n: 1,                  # between 1 and 10
  size: '1024x1024',     # 256x256, 512x512, or 1024x1024
  response_format: 'url' # url or b64_json
}
response = Openai::Client.images.variations(request_body)
  • image - must be a valid PNG file, less than 4MB, and square.

API Documentation

OpenAI Embeddings API

Create Embeddings

request_body = {
  model: 'text-embedding-ada-002',
  input: 'The food was delicious and the waiter...'
}
Openai::Client.embeddings.create(request_body)

API Documentation

OpenAI Moderations API

Create Moderation

request_body = {
  model: 'text-moderation-latest', # text-moderation-stable or text-moderation-latest
  input: 'I want to kill them.'
}
Openai::Client.moderations.create(request_body)

API Documentation

OpenAI Files API

List Files

Openai::Client.files.list

API Documentation

Find File

Openai::Client.files.find(file_id)

API Documentation

Find File Content

Openai::Client.files.find_content(file_id)

API Documentation

Upload File

request_body = {
  file: '/absolute/path/to/file.jsonl',
  purpose: 'fine-tune'
}
Openai::Client.files.upload(request_body)

The file format must be jsonl, where each line contains the prompt and completion properties.

Example (file.jsonl):

{"prompt": "<prompt text>", "completion": "<ideal generated text>"}
{"prompt": "<prompt text>", "completion": "<ideal generated text>"}
...

API Documentation

Delete File

Openai::Client.files.delete(file_id)

API Documentation

OpenAI Fine-Tunes API

Create Fine-Tune

request_body = {
  training_file: "file-XGinujblHPwGLSztz8cPS8XY"
}

Openai::Client.fine_tunes.create(request_body)

API Documentation

List Fine-Tunes

Openai::Client.fine_tunes.list

API Documentation

Find Fine-Tune

Openai::Client.fine_tunes.find(fine_tune_id)

API Documentation

List Fine-Tune Events

Openai::Client.fine_tunes.find_events(fine_tune_id)

API Documentation

Cancel Fine-Tune

Openai::Client.fine_tunes.cancel(fine_tune_id)

API Documentation

Delete Fine-Tune Model

Openai::Client.models.delete(model_id)

API Documentation

  • You must have the Owner role in your organization.
  • Make sure you provide the Model ID and not the Fine-Tune ID.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/itikhonenko/openai-client.

License

The gem is available as open source under the terms of the MIT License.

openai-client's People

Contributors

itikhonenko avatar

Stargazers

Tuan Duc Tran avatar  avatar Ed Tee avatar  avatar Scott 1743 avatar

Watchers

Kostas Georgiou avatar  avatar

Forkers

ihortykhonenko

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.