Skip to content

cb341/vibe_if

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VibeIf

A Ruby gem that uses OpenAI to evaluate your instance variables and conditionally execute code blocks based on natural language descriptions.

Installation

Add this line to your application's Gemfile:

gem 'vibe_if'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install vibe_if

Setup

Create an initializer (e.g., config/initializers/vibe_if.rb for Rails) or configure at the top of your script:

require 'vibe_if'

VibeIf.configure do |config|
  config.openai_api_key = ENV['OPENAI_API_KEY'] # or your API key
  config.model = 'gpt-3.5-turbo' # optional, defaults to gpt-3.5-turbo
end

Usage

Use the vibe_if method on any object to conditionally execute code based on natural language conditions:

class User
  def initialize(name, age, status)
    @name = name
    @age = age
    @status = status
  end

  def check_eligibility
    vibe_if "user is an adult and active" do
      puts "#{@name} is eligible!"
    end

    vibe_if "user seems unhappy or inactive" do
      puts "Reaching out to #{@name}..."
    end
  end
end

user = User.new("Alice", 25, "active")
user.check_eligibility

The gem will send your instance variables to OpenAI, which evaluates the condition and returns true/false to determine whether the block should execute.

Environment Variables

Set your OpenAI API key:

export OPENAI_API_KEY="your-openai-api-key-here"

Inspiration

This gem was inspired by vibesort, a Python library that uses GPT for AI-powered array sorting.

License

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

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •  

Languages