Git Product home page Git Product logo

rubyai's Introduction

RubyAI - OpenAI integration Ruby gem

Gem Version GitHub license

Use the OpenAI API 🤖 with Ruby! ❤️

Generate text with ChatGPT (Generative Pre-trained Transformer)

Installation

Add this line to your application's Gemfile:

gem "rubyai"

And then execute:

$ bundle install

Or install with:

$ gem install rubyai

and require with:

require "rubyai"

Usage

Quickstart

For a quick test you can pass your token directly to a new client:

result = RubyAI::Client.new(access_token, messages).call

ChatGPT

ChatGPT is a conversational-style text generation model. You can use it to generate a response to a sequence of messages:

api_key = "YOUR API KEY"
messages = "Who is the best chess player in history?"

result = RubyAI::Client.new(api_key, messages, model: "gpt-4").call
puts result.dig("choices", 0, "message", "content")

# => As an AI language model, I do not have personal opinions, but according to historical records, Garry Kasparov is often considered as one of the best chess players in history. Other notable players include Magnus Carlsen, Bobby Fischer, and Jose Capablanca.

You can also pass client variables using the configuration file. Create configruation file like on example:

configuration = RubyAI::Configuration.new("YOUR API KEY", "Who is the best chess player in history?")
client = RubyAI::Client.new(configuration)
result = client.call
puts result.dig("choices", 0, "message", "content")

Also (mostly) if you are using Rails you can use configure method:

RubyAI.configure do |config|
  config.api_key = "YOUR API KEY"
  config.messages = "Who is the best chess player in history?"
  config.model = "gpt-3.5-turbo"
end

Development

After checking out the repo, run bin/setup to install dependencies. You can 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alexshapalov/rubyai. This project is intended to be a safe, welcoming space for collaboration, and contributors.

License

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

rubyai's People

Contributors

alexshapalov avatar bodyyyya avatar fyurchik avatar sanyakosivchuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rubyai's Issues

Add Faraday gem

Add Faraday gem

This HTTP client provides simple APIs for making HTTP connections with any web server. It has the capability to handle connection- timeout and errors, and it can even retry the request for you if the first connection could not go through successfully. The retry function is beneficial when it comes to web scraping. You can keep trying until a request status is 200.

https://lostisland.github.io/faraday/#/customization/index

Add configuration class

Add and extract the configuration class where we add all setups.

We can see as an example lib/open.rb, we need to add on y main attributes like:

  class Configuration
    attr_writer :access_token

    attr_accessor :api_type, :api_version, :organization_id, :uri_base, :request_timeout

...

We can put this file in lib/configuration.rb and use it in the main class.

Add Rubocop

Add Rubocop file .rubocop.yml

Like:

AllCops:
  TargetRubyVersion: 2.6
  NewCops: enable
  SuggestExtensions: false

Style/Documentation:
  # Skips checking to make sure top level modules / classes have a comment.
  Enabled: false

Layout/LineLength:
  Max: 100
  Exclude:
    - "**/*.gemspec"

Lint/AmbiguousOperator:
  # https://github.com/rubocop/rubocop/issues/4294
  Exclude:
    - "lib/openai/client.rb"

Metrics/AbcSize:
  Max: 20

Metrics/BlockLength:
  Exclude:
    - "spec/**/*"

Style/StringLiterals:
  EnforcedStyle: double_quotes

Style/FrozenStringLiteralComment:
  Enabled: false

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.