Project

ask_gpt

0.0
No release in over a year
A ruby gem to Interact with OpenAI GPT API with context and history
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

AskGpt

Gem Version

Introduction

AskGpt is a Ruby Gem that enables users to ask questions to ChatGPT with context.

Installation

To install AskGpt, add the following line to your Gemfile:

gem 'ask_gpt'

Then run bundle install to install the gem.

Usage

After installation, import AskGpt into your Ruby program:

require 'ask_gpt'

Next, create a new instance of the AskGpt::GPT class:

gpt = AskGpt::GPT.new(api_key)
  • The api_key parameter is required and represents your OpenAI API key. You can get it from here.

  • The model parameter is optional and represents the GPT model that you want to use. The default value is gpt-3.5-turbo. You can use gpt-4 if you have access to it.

  • The temperature parameter is also optional and represents the "creativity" of the model's responses. The default value is 0.7, which should provide a good balance between creativity and accuracy. Value ranges from 0.0 - 1.0 and the higher the value, the more creative the model's responses will be.

  • The unable_to_get_answer_text parameter is optional and represents the message that will be returned if the model is unable to generate a response. The default value is 'Unable to get answer from ChatGPT. Make sure API key is valid and has enough credits.'

Once you have created a new instance of the GPT class, you can ask questions by calling the ask method:

answer = gpt.ask("What is the capital of France?")

The ask method takes a single parameter, which is the question that you want to ask the model. If the question is empty, the method will return nil. Otherwise, it will use the context of previous questions and answers to generate a response. If the model is unable to generate a response, the ask method will return the unable_to_get_answer_text message.

If the model is able to generate a response, the ask method will return the answer as a string.

Example

Here's an example of how you can use AskGpt to ask a series of questions and get answers:

require 'ask_gpt'

api_key = 'your_api_key_here'
gpt = AskGpt::GPT.new(api_key)

questions = [
  "What is the capital of France?",
  "Who was the first president of the United States?",
  "What is the tallest mountain in the world?"
]

questions.each do |question|
  answer = gpt.ask(question)
  puts "Q: #{question}\nA: #{answer}\n\n"
end

In this example, we first create a new instance of the GPT class using our API key. We then define an array of questions that we want to ask the model. Finally, we loop through each question, ask the model for an answer, and print the question and answer to the console.

Projects using AskGpt

Remarks

This readme was generated by ChatGPT with some guidance and modifications.