Last active
April 10, 2023 19:50
-
-
Save fercreek/4e786926fabf0e2152b677924af16a57 to your computer and use it in GitHub Desktop.
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
require 'openai' | |
# Comprueba si se proporciona un argumento de mensaje y, en caso contrario, solicita al usuario que proporcione uno. | |
if ARGV.empty? | |
puts "Please specify a message to send to the chatbot as an argument" | |
exit | |
end | |
# Combina los argumentos proporcionados en un único mensaje. | |
message = ARGV.join(" ") | |
# Configura el cliente de OpenAI con el token de acceso. | |
OpenAI.configure do |config| | |
config.access_token = "<ACCESS_KEY>" | |
end | |
# Crea una instancia del cliente de OpenAI. | |
client = OpenAI::Client.new | |
# Prepara y envía la solicitud de chat al modelo ChatGPT. | |
response = client.chat( | |
parameters: { | |
model: "gpt-3.5-turbo", | |
messages: [{ role: "user", content: message}], | |
temperature: 0.7, | |
}) | |
# Extrae e imprime el contenido del mensaje en la respuesta del chatbot. | |
puts response.dig("choices", 0, "message", "content") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment