-
-
Save dvinciguerra/984e9a6c23b2e39aa7452fc8f21e0732 to your computer and use it in GitHub Desktop.
Ruby ChatGPT CLI to ask things without leave terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# _ _ | |
# | |__ ___| |_ | |
# | '_ \ _ \ _| | |
# |_.__\___/\__| | |
# Ruby ChatGPT CLI to ask things without leave terminal | |
# by dvinciguerra | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'dotenv' | |
gem 'chatgpt-ruby' | |
end | |
require 'dotenv' | |
Dotenv.load("#{ENV['HOME']}/.env") | |
require 'chatgpt/client' | |
api_key = ENV['OPENAI_API_KEY'] | |
client = ChatGPT::Client.new(api_key) | |
messages = [ | |
{ | |
role: "system", | |
content: "You are a helpful assistant." | |
}, | |
{ | |
role: "user", | |
content: ARGV.join(" ") | |
} | |
] | |
response = client.chat(messages) | |
puts response['choices'][0]['message']['content'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment