百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

ask_chatgpt

> 后端框架
开源

AI 驱动的助手 Gem 就放在 Rails 控制台中。ChatGPT 在 Rails 中的全部功能

269 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

AI 驱动的助手 Gem 就放在 Rails 控制台中。ChatGPT 在 Rails 中的全部功能

Ask ChatGPT

AI-Powered Assistant Gem right in your Rails console.

NEW UPDATE: Voice input using your microphone, demo: https://youtu.be/uBR0wnQvKao

A Gem that leverages the power of AI to make your development experience more efficient and enjoyable. With this gem, you can streamline your coding process, effortlessly refactor and improve your code, and even generate tests on the fly. + See more examples below.

Usage

Go to Rails console and run:

…

OR with CLI tool:

bash
>ask_chatgpt -q "134*1245"
166830

>ask_chatgpt base64 this string "hello world"
aGVsbG8gd29ybGQ=

>ask_chatgpt decode base64 this string "aGVsbG8gd29ybGQ="
hello world

ask_chatgpt -s 1 # start voice input with CLI

See some examples below. You can also create your own prompts with just few lines of code here.

Also you can use a CLI tool, how to use it.

Examples

Typical use-cases how you can use this plugin

Ask for code ideas:

Do you need help to write rspec test?

What about unit tests?

Ask ChatGPT to improve your code:

Ask ChatGPT to parse you JSON:

Or it can encode in Base64 your string:

Create I18n YAML for your Model (custom prompt):

Installation

Add this line to your application's Gemfile:

ruby
gem "ask_chatgpt"

And then execute:

bash
$ bundle

Or install it yourself as:

bash
$ gem install ask_chatgpt

Options & Configurations

Run rails g ask_chatgpt initializer.

And you can edit:

…

Note: that you need to setup your API Key https://platform.openai.com/account/api-keys. You can store it in the .env or .bash_profile.

Example with nano ~/.bash_profile:

bash
export OPENAI_API_KEY=key

BUT make sure it won't be committed to the Github. Is must be private.

You can define you own prompts and use them using .register_prompt. For example:

ruby
  config.register_prompt :extract_email do |arg|
    "Extract email from: #{arg} as JSON"
  end

And later you can call it with gpt.extract_email("some text with [email protected], [email protected]"). If you believe your custom prompt will be useful - create a PR for this gem.

If you want to get source code use this helper AskChatGPT::Helpers.extract_source(str).

You can pass:

ruby
  AskChatGPT::Helpers.extract_source('User.some_class_method')
  AskChatGPT::Helpers.extract_source('User#instance_method')
  AskChatGPT::Helpers.extract_source('User')
  AskChatGPT::Helpers.extract_source(User)
  AskChatGPT::Helpers.extract_source("a = b")

By default when you use in Rails app default one prompt is included (.included_prompts) which is sending Ruby/Rails versions, and name of the database adapter.

Debug Mode

You can enable debug mode to see request/response from the OpenAI using two ways:

ruby
AskChatGPT.setup do |config|
  config.debug = false
end

# or

# gpt.on!(:debug)
# gpt.off!(:debug)

or directly in console gpt.debug! (and finish gpt.debug!(:off))

Voice Input

Demo: https://youtu.be/uBR0wnQvKao

For now I consider this as an experimental and fun feature. Look forward seeing your feedback.

Works with command: gpt.speak or gpt.s (alias).

This command starts recording right away and it will stop after voice_max_duration seconds or if you press any key.

To exit recording mode press Q.

Voice is using ffmpeg tool, so you need to install it. Some instruction like this will work: https://www.hostinger.com/tutorials/how-to-install-ffmpeg.

Also, you need to configure audio_device_id. Run ffmpeg -f avfoundation -list_devices true -i ""

It will give you list of all devices, like this:

…

In my case I used "1", because it's Built-in Microphone.

CLI Tool

You can ask questions from cli or even start voice input.

Example 1:

Example 2:

How to use:

  ask_chatgpt -q "How to parse JSON file in Ruby?"
  ask_chatgpt -t 0.7 -q "How to parse JSON file in Ruby?"
  ask_chatgpt -f app/models/user.rb -q "find a bug in this Rails model"
  ask_chatgpt -f app/models/user.rb -q "create RSpec spec for this model"
  ask_chatgpt -f test/dummy/Gemfile -q "sort Ruby gems alphabetically"
  ask_chatgpt -m 3.5 -q "How to parse JSON file in Ruby?"
  ask_chatgpt -m 4 -q "Why Ruby is the best language?"

You can also create an alias "a" or "q" for example:

Edit file: nano ~/.bash_profile

bash
alias a='ask_chatgpt'
alias q='ask_chatgpt'

and now you can use q "how to unzip file with Ruby"

Streaming (async vs sync mode)

Control the mode from a console. Or, from the initializer, using config.mode = :async (or sync).

ruby
  gpt.async!
  gpt.sync!

Random Tips

Surprise yourself with random facts and useful tips. To use just call gpt.random (or gpt.tip, gpt.random_tip).

By default it's using Ruby/Rails topics (see RandomTip class).

But you can also use other topics, e.g.:

ruby
  gpt.tip
  gpt.tip("active record")
  gpt.tip("sidekiq")
  gpt.tip("security")

Markdown

Try to format response from Markdown and print it nicely in the console.

ruby
AskChatGPT.setup do |config|
  config.markdown = true
end

# or

# gpt.on!(:markdown)
# gpt.off!(:markdown)

TODO

  • better CLI?
  • more prompts (cover controllers, sql, etc?), e.g. with_controller, with_class, ...
  • tests(rspec, vcr)
  • can it be used with pry/byebug/etc?
  • print tokens usage? .with_usage
  • support org_id? in the configs
  • use gpt in the code of the main app (e.g. model/controller)
  • when voice is used add support for payloads, e.g. gpt.with_payload(json).speak (and it will send payload with my question)
  • refactor voice input code :) as first version it's fine
  • can we discover audio device ID?
  • use tempfile for audio, instead of output.wav
  • handle case when empty response is returned in CLI (when for example non-existing model is specified)

Contributing

We are welcoming you to propose new prompts or adjust existing ones!

To start just clone this repo. Run bundle, and go to cd test/dummy/. Start rails c and test your prompts.

License

The gem is available as open source under the terms of the MIT License.

Issues· 5 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubychatgptopenairailsruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架