Samala Sumanth
Posted on April 15, 2023
In today's fast-paced digital world, language generation has become a powerful tool for automating tasks, enhancing user experiences, and driving innovation in various industries.
In this blog, we will dive into the world of "chatsonic" and explore how this https://rubygems.org/gems/chatsonic Rails Gem can enable you to leverage the power of LLM ChatGPT in your Ruby on Rails applications. We will discuss the features, functionalities as well as provide examples and code snippets to demonstrate how it can be integrated into your Ruby on rails applications.
On a high level ChatSonic Gem is a wrapper around the writesonic OpenAPI that can be easily integrated into your rails application by installing this Gem.
Main Repository: https://github.com/SamalaSumanth0262/chatsonic
STEP 1: Installing Gem
In your rails root directory, run this command gem install chatsonic
STEP 2: Get the API Key
Now head to https://docs.writesonic.com/reference/finding-your-api-key, Create an account for first time users. please find the image below for reference
STEP 3: Initialising and Configuring the Gem
Add gem 'chatsonic', '~> 1.0', '>= 1.0.2'
to GemFile or Simply run gem install chatsonic
Now It's time to configure the gem with the help of API-KEY obtained from Step 1.
Create a file chatsonic.rb
in initialisers folder which is right place to configure gem. Insert the below small chunk of code.
ChatSonic.configure do |config|
config.access_token = "****" #required, Always fetch from ENV file, ENV["API-KEY"]
config.uri_base: "https://api.writesonic.com/", # Optional, Used to override the default
config.request_timeout: 240 # Optional, Used to override the default ( Just in case if the prompt take more 120 seconds)
end
Or You can directly initialise by creating a instance of the gem like below
client = ChatSonic::Client.new # if you have already initialised
# OR
client = ChatSonic::Client.new(access_token: "Your API Key")
STEP 4: Getting the Prompt
Now from anywhere in your rails application by using below chunk of the code you can get the PROMPT
response = client.prompt(parameters: {
enable_google_results: true,
enable_memory: true,
input_text: 'Hi'
})
enable_google_results: Gives your responses based on the data backed by google.
enable_memory: Stores all the previous conversations
input_text: Your prompt.
This will give prompt response "Hello! How may i assist you today ?"
Hurray !!! Thats it. Now you have integrated this Gem into your Rails Application.
Main Use Cases of this:
- Act like ChatGPT with steroids
- Conversational AI
- Translational
- Content Writer
- More use cases can be found here
Proposed Future Developments:
- Make this gem powerful and be compatible with all the features listed in this page: https://docs.writesonic.com/reference/introduction
Thanks for reading !!! Feel free to comment any kind of suggestions for this blog. I am all ears. Cheers !!!!
Thank you for inspiring !! Cheers. CEO Of writesonic @samanyougarg
Posted on April 15, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.