chatsonic 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +116 -0
- data/Rakefile +6 -0
- data/lib/chatsonic/client.rb +39 -0
- data/lib/chatsonic/version.rb +3 -0
- data/lib/chatsonic.rb +46 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f3199c93ee4201cd12aded8c51fa036d159bc1553c69ab6a0cdf68ec5d8c0ab0
|
|
4
|
+
data.tar.gz: b05283969491a415e6877ef4fca1a1aa77331f5c68c7c75195aa72a2128be8e5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6672bc008492a975a879ff10cd625f6bc650a7becd25ae2900ad827fa50cf53a45b73bc48fadc048020beda27d56bed6fb33f5dcb7df46b1911824b74eb53220
|
|
7
|
+
data.tar.gz: c3c831c788a24d6d574bf3c71b6df637153d775395826311e275a29f8ecc859b8c608e1026bba32a5b5a62ba1884eb305ca1bfa87d0c32cde80ab15a44c7a32d
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Samala Sumanth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# ChatGPT Alternative Built With Superpowers - ChatSonic (Now GPT-4 Powered) Rails Gem
|
|
2
|
+
|
|
3
|
+
[](https://github.com/SamalaSumanth0262/chatsonic/blob/master/LICENSE)
|
|
4
|
+
[](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
|
|
5
|
+
|
|
6
|
+
Use the [ChatSonic API](https://writesonic.com/chat) with Ruby! 🤖❤️
|
|
7
|
+
|
|
8
|
+
Trusted by 1,000,000+ marketing teams, agencies, and freelancers. 10,000+ 5-star ratings.
|
|
9
|
+
|
|
10
|
+
### 1. Write Factual Trending Content
|
|
11
|
+
### 2. Generate AI Art
|
|
12
|
+
### 3. Write anywhere and everywhere
|
|
13
|
+
|
|
14
|
+
## How to Use ?
|
|
15
|
+
|
|
16
|
+
### Bundler
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem "chatsonic"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle install
|
|
27
|
+
|
|
28
|
+
### Gem install
|
|
29
|
+
|
|
30
|
+
Or install with:
|
|
31
|
+
|
|
32
|
+
$ gem install chatsonic
|
|
33
|
+
|
|
34
|
+
and require with:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
require "chatsonic"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
- Get your API key from [https://app.writesonic.com/settings/api](https://app.writesonic.com/settings/api)
|
|
44
|
+
|
|
45
|
+
### Quickstart
|
|
46
|
+
|
|
47
|
+
For a quick test you can pass your token directly to a new client:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
client = ChatSonic::Client.new(access_token: "Your API Key")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With Config
|
|
54
|
+
|
|
55
|
+
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](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
ChatSonic.configure do |config|
|
|
59
|
+
config.access_token = ENV.fetch('API-KEY')
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then you can create a client like this:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
client = ChatSonic::Client.new
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Custom timeout or base URI
|
|
70
|
+
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
client = ChatSonic::Client.new(
|
|
75
|
+
access_token: "access_token_goes_here",
|
|
76
|
+
uri_base: "https://api.writesonic.com/",
|
|
77
|
+
request_timeout: 240
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
or when configuring the gem:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
ChatSonic.configure do |config|
|
|
85
|
+
config.access_token = ENV.fetch("API_KEY")
|
|
86
|
+
config.uri_base = "https://api.writesonic.com/" # Optional
|
|
87
|
+
config.request_timeout = 240 # Optional
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### ChatSonic
|
|
92
|
+
|
|
93
|
+
ChatSonic is a model that can be used to generate text in a conversational style.
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
|
|
97
|
+
client.prompt(parameters: {
|
|
98
|
+
enable_google_results: true,
|
|
99
|
+
enable_memory: true,
|
|
100
|
+
input_text: 'Write Me a Poem'
|
|
101
|
+
})
|
|
102
|
+
# => "Hello! How may I assist you today?"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
input_text can be your prompt
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
110
|
+
|
|
111
|
+
## ToDo: Implement
|
|
112
|
+
1. Create a pull request template
|
|
113
|
+
2. Create a circle CI for CI/CD
|
|
114
|
+
3. Rspec to be implemented
|
|
115
|
+
4. Code of Coduct
|
|
116
|
+
5. Contributing
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module ChatSonic
|
|
2
|
+
class Client
|
|
3
|
+
def initialize(access_token: nil, api_version: nil, service_name: nil, uri_base: nil, request_timeout: nil)
|
|
4
|
+
ChatSonic.configuration.access_token = access_token if access_token
|
|
5
|
+
ChatSonic.configuration.api_version = api_version if api_version
|
|
6
|
+
ChatSonic.configuration.service_name = service_name if service_name
|
|
7
|
+
ChatSonic.configuration.uri_base = uri_base if uri_base
|
|
8
|
+
ChatSonic.configuration.request_timeout = request_timeout if request_timeout
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def prompt(parameters: {})
|
|
12
|
+
ChatSonic::Client.json_post(parameters: parameters)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def self.json_post(parameters:)
|
|
18
|
+
HTTParty.post(
|
|
19
|
+
uri,
|
|
20
|
+
headers: headers,
|
|
21
|
+
body: parameters&.to_json,
|
|
22
|
+
timeout: ChatSonic.configuration.request_timeout,
|
|
23
|
+
verify: false
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.headers
|
|
28
|
+
{
|
|
29
|
+
"Content-Type" => "application/json",
|
|
30
|
+
"accept" => "application/json",
|
|
31
|
+
"X-API-KEY" => ChatSonic.configuration.access_token
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.uri
|
|
36
|
+
ChatSonic.configuration.uri_base + ChatSonic.configuration.api_version + "/business/content/" + ChatSonic.configuration.service_name + "?engine=premium"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/chatsonic.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "openssl"
|
|
2
|
+
require "httparty"
|
|
3
|
+
|
|
4
|
+
require_relative "chatsonic/client"
|
|
5
|
+
|
|
6
|
+
module ChatSonic
|
|
7
|
+
class Error < StandardError; end
|
|
8
|
+
class ConfigurationError < Error; end
|
|
9
|
+
|
|
10
|
+
class Configuration
|
|
11
|
+
attr_writer :access_token, :service_name, :api_version, :uri_base, :request_timeout
|
|
12
|
+
attr_accessor :access_token, :service_name, :api_version, :uri_base, :request_timeout
|
|
13
|
+
|
|
14
|
+
DEFAULT_API_VERSION = "v2".freeze
|
|
15
|
+
DEFAULT_URI_BASE = "https://api.writesonic.com/".freeze
|
|
16
|
+
DEFAULT_REQUEST_TIMEOUT = 120
|
|
17
|
+
DEFAULT_SERVICE_NAME = "chatsonic".freeze
|
|
18
|
+
|
|
19
|
+
def initialize
|
|
20
|
+
@access_token = nil
|
|
21
|
+
@api_version = DEFAULT_API_VERSION
|
|
22
|
+
@uri_base = DEFAULT_URI_BASE
|
|
23
|
+
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
|
24
|
+
@service_name = DEFAULT_SERVICE_NAME
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def access_token
|
|
28
|
+
return @access_token if @access_token
|
|
29
|
+
|
|
30
|
+
error_text = "WriteSonic Access Token is missing! you can have token from here https://app.writesonic.com/settings/api"
|
|
31
|
+
raise ConfigurationError, error_text
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
attr_writer :configuration
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.configuration
|
|
40
|
+
@configuration ||= ChatSonic::Configuration.new
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.configure
|
|
44
|
+
yield configuration
|
|
45
|
+
end
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chatsonic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Samala Sumanth
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rubocop
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.60'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.60'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rubocop-performance
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.5'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.5'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rubocop-rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.37'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.37'
|
|
55
|
+
description: This gem allows interact with ChatSonic ( An Alternative to ChatGPT-4
|
|
56
|
+
) with Real Time Data Model
|
|
57
|
+
email:
|
|
58
|
+
- 'chintusamala96@gmail.com '
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files:
|
|
62
|
+
- README.md
|
|
63
|
+
files:
|
|
64
|
+
- CHANGELOG.md
|
|
65
|
+
- Gemfile
|
|
66
|
+
- LICENSE
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- lib/chatsonic.rb
|
|
70
|
+
- lib/chatsonic/client.rb
|
|
71
|
+
- lib/chatsonic/version.rb
|
|
72
|
+
homepage: https://github.com/SamalaSumanth0262/chatsonic
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata: {}
|
|
76
|
+
post_install_message:
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: 2.5.0
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubygems_version: 3.0.9
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: ChatSonic Integration with Rails
|
|
95
|
+
test_files: []
|