Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ask_gpt

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ask_gpt

  • 1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Remarks

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

FAQs

Package last updated on 14 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc