https://github.com/st0012/irb-ai
IRB-AI is an experimental project that explores various ways to enhance users' IRB experience through AI (currently using ChatGPT).
https://github.com/st0012/irb-ai
chatgpt irb openai ruby
Last synced: about 1 year ago
JSON representation
IRB-AI is an experimental project that explores various ways to enhance users' IRB experience through AI (currently using ChatGPT).
- Host: GitHub
- URL: https://github.com/st0012/irb-ai
- Owner: st0012
- License: mit
- Created: 2023-05-29T20:28:17.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-31T16:55:48.000Z (almost 3 years ago)
- Last Synced: 2024-12-22T06:15:31.635Z (over 1 year ago)
- Topics: chatgpt, irb, openai, ruby
- Language: Ruby
- Homepage:
- Size: 29.3 KB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# IRB-AI
[](https://badge.fury.io/rb/irb-ai)
`IRB-AI` is an experimental project that explores various ways to enhance users' IRB experience through AI (currently using `ChatGPT`).
## Installation
Add this gem to your `Gemfile`:
```rb
gem "irb-ai", group: [:development, :test]
```
## Setup
Ensure you have your [OpenAI API](https://openai.com/blog/openai-api) key stored in `ENV["OPENAI_API_KEY"]`.
## Usage
At the moment, this gem only provides the `explain` command:
- `explain as ` explains the execution of `` by observing ``
- For instance, `explain Post.find_the_closest as Post` will trace `Post`'s method calls to collect runtime information.
- `explain ` is equivalent to `explain as self`
Including `` is advised because this project relies on [`ruby/tracer`](https://github.com/ruby/tracer)'s
[`ObjectTracer`](https://github.com/ruby/tracer#objecttracer), which only collects traces around the target object.
The more detailed [`CallTracer`](https://github.com/ruby/tracer#calltracer) is not used because the current ChatGPT models
have a relatively low token limit (`gpt-3.5-turbo` allows only `4000` tokens). Thus, using it can easily exceed that limit and
result in the request being rejected.
### Configurations
You can specify the model through `IRB::AI.model = ""`. The default is `gpt-3.5-turbo`.
## Example
Given this script:
```rb
require "bundler/inline"
gemfile do
gem "irb-ai"
gem "activesupport"
end
require "irb/ai"
require "active_support"
require "active_support/core_ext/object/blank"
old_secret = SecureRandom.base64(24)
old_encryptor = ActiveSupport::MessageEncryptor.new old_secret
new_secret = SecureRandom.base64(24)
new_encryptor = ActiveSupport::MessageEncryptor.new new_secret
new_encryptor.rotate old_secret
msg_from_old_encryptor = old_encryptor.encrypt_and_sign("test")
# Run `explain new_encryptor.decrypt_and_verify(msg_from_old_encryptor) as new_encryptor`
binding.irb
```
If you run the following command from the breakpoint:
```
explain new_encryptor.decrypt_and_verify(msg_from_old_encryptor) as new_encryptor
```
It will respond with answers like this as rendered markdown output:
```md
This is an analysis of the program's behaviour when running the expression `new_encryptor.decrypt_and_verify(msg_from_old_encryptor)`
### Code Summary
From the given information, there is no program source code provided.
### Execution Summary
The `decrypt_and_verify` method was called on an instance of `ActiveSupport::MessageEncryptor` with a message received from an old encryptor. The method returned the decrypted message "test".
### Execution Details
1. The `decrypt_and_verify` method was called on an instance of `ActiveSupport::MessageEncryptor` with a message received from an old encryptor.
2. The `decrypt_and_verify` method called the `verifier` method on the same instance of `ActiveSupport::MessageEncryptor`.
3. An `ActiveSupport::MessageVerifier::InvalidSignature` exception was raised at line 178 in `message_verifier.rb`, indicating that the message could not be authenticated with the given signature (which was generated by the old encryptor).
4. The exception was caught by `run_rotations` in `rotator.rb`.
5. `run_rotations` calls `decrypt_and_verify` again, this time with a different key used by the new encryptor.
6. `decrypt_and_verify` called `verifier` again, but this time with the new key used by the new encryptor.
7. The `verifier` method verified the signature of the message using the new key, and found it to be valid.
8. The `decrypt_and_verify` method decrypted the message using the new key, which was used to encrypt the message before it was signed.
9. The decrypted message "test" was returned from the `decrypt_and_verify` method.
Thus the program successfully decrypted and authenticated the message received from the old encryptor.
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests.
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`.
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/st0012/irb-ai.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/st0012/irb-ai/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the `IRB-AI` project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/st0012/irb-ai/blob/main/CODE_OF_CONDUCT.md).