Use the ChatSonic API with Ruby! 🤖❤️
Trusted by 1,000,000+ marketing teams, agencies, and freelancers. 10,000+ 5-star ratings.
Add this line to your application's Gemfile:
gem "chatsonic"
And then execute:
$ bundle install
Or install with:
$ gem install chatsonic
and require with:
require "chatsonic"
- Get your API key from https://app.writesonic.com/settings/api
For a quick test you can pass your token directly to a new client:
client = ChatSonic::Client.new(access_token: "Your API Key")
For a more robust setup, you can configure the gem with your API keys, for example in an chatsonic.rb
initializer file. Never hardcode secrets into your codebase - instead use something like dotenv to pass the keys safely into your environments.
ChatSonic.configure do |config|
config.access_token = ENV.fetch('API-KEY')
end
Then you can create a client like this:
client = ChatSonic::Client.new
The default timeout for any ChatSonic request is 120 seconds. You can change that passing the request_timeout
when initializing the client. You can also change the base URI used for all requests.
client = ChatSonic::Client.new(
access_token: "access_token_goes_here",
uri_base: "https://api.writesonic.com/",
request_timeout: 240
)
or when configuring the gem:
ChatSonic.configure do |config|
config.access_token = ENV.fetch("API_KEY")
config.uri_base = "https://api.writesonic.com/" # Optional
config.request_timeout = 240 # Optional
end
ChatSonic is a model that can be used to generate text in a conversational style.
client.prompt(parameters: {
enable_google_results: true,
enable_memory: true,
input_text: 'Hi'
})
# => "Hello! How may I assist you today?"
input_text can be your prompt
For Specs you can run bundle rake rspec
. Make sure all the specs are passed before raising a PR. PR template can be found here Pull Request Template
You can raise a feature request in this mentioned format Feature Request Format
You can raise a Bug report in this mentioned format Bug Report Format
The gem is available as open source under the terms of the MIT License.