Skip to content

Instantly share code, notes, and snippets.

@dvinciguerra
Last active November 10, 2023 02:12
Show Gist options
  • Save dvinciguerra/984e9a6c23b2e39aa7452fc8f21e0732 to your computer and use it in GitHub Desktop.
Save dvinciguerra/984e9a6c23b2e39aa7452fc8f21e0732 to your computer and use it in GitHub Desktop.
Ruby ChatGPT CLI to ask things without leave terminal
#!/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