{"id":13642237,"url":"https://github.com/railsjazz/ask_chatgpt","last_synced_at":"2025-04-04T10:06:42.903Z","repository":{"id":154167290,"uuid":"631224923","full_name":"railsjazz/ask_chatgpt","owner":"railsjazz","description":"AI-Powered Assistant Gem right in your Rails console. Full power of ChatGPT in Rails","archived":false,"fork":false,"pushed_at":"2024-05-02T15:26:53.000Z","size":4245,"stargazers_count":268,"open_issues_count":5,"forks_count":13,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T09:05:04.238Z","etag":null,"topics":["chatgpt","openai","rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://www.railsjazz.com/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/railsjazz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"igorkasyanchuk"}},"created_at":"2023-04-22T10:41:00.000Z","updated_at":"2025-03-26T11:15:02.000Z","dependencies_parsed_at":"2024-01-14T09:30:37.703Z","dependency_job_id":"d45621c5-35e4-4974-afbb-4869118d6188","html_url":"https://github.com/railsjazz/ask_chatgpt","commit_stats":{"total_commits":42,"total_committers":4,"mean_commits":10.5,"dds":0.09523809523809523,"last_synced_commit":"f1b41262dd7da173c28cf1cb92ae68cf35c69a33"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsjazz%2Fask_chatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsjazz%2Fask_chatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsjazz%2Fask_chatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsjazz%2Fask_chatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/railsjazz","download_url":"https://codeload.github.com/railsjazz/ask_chatgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157045,"owners_count":20893202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","openai","rails","ruby","ruby-on-rails"],"created_at":"2024-08-02T01:01:28.867Z","updated_at":"2025-04-04T10:06:42.876Z","avatar_url":"https://github.com/railsjazz.png","language":"Ruby","funding_links":["https://patreon.com/igorkasyanchuk"],"categories":["Chatbots","Ruby"],"sub_categories":[],"readme":"# Ask ChatGPT\n\n[![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)\n[![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/o/railsjazz)\n\nAI-Powered Assistant Gem right in your Rails console.\n\nNEW UPDATE: Voice input using your microphone, demo: https://youtu.be/uBR0wnQvKao\n\n![AskChatGPT](docs/interactive.gif)\n\nA 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.\n+\nSee more [examples](#examples) below.\n\n## Usage\n\nGo to Rails console and run:\n\n```ruby\n  gpt.ask(\"how to get max age of user with projects from Ukraine\").with_model(User, Project, Country)\n  gpt.ask(\"convert json to xml\")\n  gpt.with_code(\"User.get_report\", Project).ask \"make it better\" # with_class alias for with_code\n  gpt.with_class(User).ask \"make it better\"\n  gpt.payload(json).ask(\"extract emails from json\")\n  gpt.refactor(\"User.get_report\")\n  gpt.improve(\"User.get_report\")\n  gpt.rspec_test(User)\n  gpt.unit_test(User)\n  gpt.code_review(User.method(:get_report))\n  gpt.find_bug('User#full_name')\n  gpt.explain(User)\n  gpt.improve %Q{\n    def full_name\n      [first_name, last_name].join\n    end\n  }\n  #\n  # --- NEW ---\n  #\n  gpt.speak # or with alias gpt.s\n```\n\nOR with CLI tool:\n\n```shell\n\u003eask_chatgpt -q \"134*1245\"\n166830\n\n\u003eask_chatgpt base64 this string \"hello world\"\naGVsbG8gd29ybGQ=\n\n\u003eask_chatgpt decode base64 this string \"aGVsbG8gd29ybGQ=\"\nhello world\n```\n\n\u003eask_chatgpt -s 1 # start voice input with CLI\n\nSee some examples below. You can also create your own prompts with just few lines of code [here](#options--configurations).\n\nAlso you can use a CLI tool, [how to use it](#cli-tool).\n\n## Examples\n\nTypical use-cases how you can use this plugin\n![AskChatGPT](docs/gpt6.png)\n\nAsk for code ideas:\n![AskChatGPT](docs/gpt1.png)\n\nDo you need help to write rspec test?\n![AskChatGPT](docs/gpt2.png)\n\nWhat about unit tests?\n![AskChatGPT](docs/gpt3.png)\n\nAsk ChatGPT to improve your code:\n![AskChatGPT](docs/gpt4.png)\n\nAsk ChatGPT to parse you JSON:\n![AskChatGPT](docs/gpt7.png)\n\nOr it can encode in Base64 your string:\n![AskChatGPT](docs/gpt8.png)\n\nCreate I18n YAML for your Model (custom prompt):\n![AskChatGPT](docs/gpt5.png)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"ask_chatgpt\"\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install ask_chatgpt\n```\n\n## Options \u0026 Configurations\n\nRun `rails g ask_chatgpt initializer`.\n\nAnd you can edit:\n\n```ruby\n  AskChatGPT.setup do |config|\n    # config.access_token    = ENV[\"OPENAI_API_KEY\"]\n\n    # async mode will use OpenAI streamming feature and will return results as they come\n    # config.mode             = :async # or :sync\n    # config.markdown         = true # try to output nicely Markdown response\n    # config.debug            = false\n    # config.model            = \"gpt-3.5-turbo\"\n    # config.temperature      = 0.1\n    # config.max_tokens       = 3000 # or nil by default\n    # config.included_prompts = []\n\n    # enable voice input with `gpt.speak` or `gpt.s`. Note, you also need to configure `audio_device_id`\n    # config.voice_enabled = true\n\n    # to get audio device ID (index in the input devices)\n    # install ffmpeg, and execute from the console\n    # `ffmpeg -f avfoundation -list_devices true -i \"\"`\n    # config.audio_device_id = 1\n\n    # after \"voice_max_duration\" seconds it will send audio to Open AI\n    # config.voice_max_duration = 10 # 10 seconds\n\n    # Examples of custom prompts:\n    # you can use them `gpt.extract_email(\"some string\")`\n\n    # config.register_prompt :extract_email do |arg|\n    #   \"Extract email from: #{arg} as JSON\"\n    # end\n\n    # config.register_prompt :extract_constants do |arg|\n    #   \"Extract constants from class: #{AskChatGPT::Helpers.extract_source(arg)}\"\n    # end\n\n    # config.register_prompt :i18n do |code|\n    #   \"Use I18n in this code:\\n#{AskChatGPT::Helpers.extract_source(code)}\"\n    # end\n  end\n```\n\nNote: 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.\n\nExample with `nano ~/.bash_profile`:\n\n```\nexport OPENAI_API_KEY=key\n```\n\nBUT make sure it won't be committed to the Github. Is must be private.\n\nYou can define you own prompts and use them using `.register_prompt`. For example:\n\n```ruby\n  config.register_prompt :extract_email do |arg|\n    \"Extract email from: #{arg} as JSON\"\n  end\n```\n\nAnd later you can call it with `gpt.extract_email(\"some text with email@site.com, user@email.com\")`.\nIf you believe your custom prompt will be useful - create a PR for this gem.\n\nIf you want to get source code use this helper `AskChatGPT::Helpers.extract_source(str)`.\n\nYou can pass:\n\n```ruby\n  AskChatGPT::Helpers.extract_source('User.some_class_method')\n  AskChatGPT::Helpers.extract_source('User#instance_method')\n  AskChatGPT::Helpers.extract_source('User')\n  AskChatGPT::Helpers.extract_source(User)\n  AskChatGPT::Helpers.extract_source(\"a = b\")\n```\n\nBy 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.\n\n## Debug Mode\n\nYou can enable debug mode to see request/response from the OpenAI using two ways:\n\n```ruby\nAskChatGPT.setup do |config|\n  config.debug = false\nend\n\n# or\n\n# gpt.on!(:debug)\n# gpt.off!(:debug)\n```\n\nor directly in console `gpt.debug!` (and finish `gpt.debug!(:off)`)\n\n## Voice Input\n\nDemo: https://youtu.be/uBR0wnQvKao\n\nFor now I consider this as an experimental and fun feature. Look forward seeing your feedback.\n\nWorks with command: `gpt.speak` or `gpt.s` (alias).\n\nThis command starts recording right away and it will stop after `voice_max_duration` seconds or if you press any key.\n\nTo exit recording mode press `Q`.\n\nVoice 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.\n\nAlso, you need to configure `audio_device_id`. Run `ffmpeg -f avfoundation -list_devices true -i \"\"`\n\nIt will give you list of all devices, like this:\n\n```s\nffmpeg -f avfoundation -list_devices true -i \"\"\nffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers\n  built with Apple clang version 14.0.0 (clang-1400.0.29.202)\n  configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox\n  libavutil      58.  2.100 / 58.  2.100\n  libavcodec     60.  3.100 / 60.  3.100\n  libavformat    60.  3.100 / 60.  3.100\n  libavdevice    60.  1.100 / 60.  1.100\n  libavfilter     9.  3.100 /  9.  3.100\n  libswscale      7.  1.100 /  7.  1.100\n  libswresample   4. 10.100 /  4. 10.100\n  libpostproc    57.  1.100 / 57.  1.100\n[AVFoundation indev @ 0x7f7fd1a04380] AVFoundation video devices:\n[AVFoundation indev @ 0x7f7fd1a04380] [0] FaceTime HD Camera\n[AVFoundation indev @ 0x7f7fd1a04380] [1] USB Camera VID:1133 PID:2085\n[AVFoundation indev @ 0x7f7fd1a04380] [2] Capture screen 0\n[AVFoundation indev @ 0x7f7fd1a04380] [3] Capture screen 1\n[AVFoundation indev @ 0x7f7fd1a04380] AVFoundation audio devices:\n[AVFoundation indev @ 0x7f7fd1a04380] [0] Microsoft Teams Audio\n[AVFoundation indev @ 0x7f7fd1a04380] [1] Built-in Microphone\n[AVFoundation indev @ 0x7f7fd1a04380] [2] Unknown USB Audio Device\n: Input/output error\n```\n\nIn my case I used \"1\", because it's `Built-in Microphone`.\n\n## CLI Tool\n\nYou can ask questions from cli or even start voice input.\n\nExample 1:\n![AskChatGPT](docs/unzip.gif)\n\nExample 2:\n![AskChatGPT](docs/avg_user_age_json.gif)\n\nHow to use:\n\n```\n  ask_chatgpt -q \"How to parse JSON file in Ruby?\"\n  ask_chatgpt -t 0.7 -q \"How to parse JSON file in Ruby?\"\n  ask_chatgpt -f app/models/user.rb -q \"find a bug in this Rails model\"\n  ask_chatgpt -f app/models/user.rb -q \"create RSpec spec for this model\"\n  ask_chatgpt -f test/dummy/Gemfile -q \"sort Ruby gems alphabetically\"\n  ask_chatgpt -m 3.5 -q \"How to parse JSON file in Ruby?\"\n  ask_chatgpt -m 4 -q \"Why Ruby is the best language?\"\n```\n\nYou can also create an alias \"a\" or \"q\" for example:\n\nEdit file: `nano ~/.bash_profile`\n\n```bash\nalias a='ask_chatgpt'\nalias q='ask_chatgpt'\n```\n\nand now you can use `q \"how to unzip file with Ruby\"`\n\n## Streaming (async vs sync mode)\n\nControl the mode from a console. Or, from the initializer, using `config.mode = :async` (or sync).\n\n```ruby\n  gpt.async!\n  gpt.sync!\n```\n\n## Random Tips\n\n![AskChatGPT](docs/random_facts.png)\n\nSurprise yourself with random facts and useful tips. To use just call `gpt.random` (or `gpt.tip`, `gpt.random_tip`).\n\nBy default it's using Ruby/Rails topics (see `RandomTip` class).\n\nBut you can also use other topics, e.g.:\n\n```ruby\n  gpt.tip\n  gpt.tip(\"active record\")\n  gpt.tip(\"sidekiq\")\n  gpt.tip(\"security\")\n```\n\n## Markdown\n\nTry to format response from Markdown and print it nicely in the console.\n\n```ruby\nAskChatGPT.setup do |config|\n  config.markdown = true\nend\n\n# or\n\n# gpt.on!(:markdown)\n# gpt.off!(:markdown)\n```\n\n## TODO\n\n- better CLI?\n- more prompts (cover controllers, sql, etc?), e.g. `with_controller`, `with_class`, ...\n- tests(rspec, vcr)\n- can it be used with pry/byebug/etc?\n- print tokens usage? `.with_usage`\n- support org_id? in the configs\n- use `gpt` in the code of the main app (e.g. model/controller)\n- when voice is used add support for payloads, e.g. `gpt.with_payload(json).speak` (and it will send payload with my question)\n- refactor voice input code :) as first version it's fine\n- can we discover audio device ID?\n- use tempfile for audio, instead of output.wav\n- handle case when empty response is returned in CLI (when for example non-existing model is specified)\n\n## Contributing\n\nWe are welcoming you to propose new prompts or adjust existing ones!\n\nTo start just clone this repo. Run bundle, and go to `cd test/dummy/`. Start `rails c` and test your prompts.\n\n[\u003cimg src=\"https://opensource-heroes.com/svg/embed/railsjazz/ask_chatgpt\"\n/\u003e](https://opensource-heroes.com/svg/embed/railsjazz/ask_chatgpt)\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n[\u003cimg src=\"https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true\"\n/\u003e](https://www.railsjazz.com/?utm_source=github\u0026utm_medium=bottom\u0026utm_campaign=ask_chatgpt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsjazz%2Fask_chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frailsjazz%2Fask_chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsjazz%2Fask_chatgpt/lists"}