rsnchat 2.0.0
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/bin/cli.rb +162 -0
- data/lib/rsn_chat.rb +88 -0
- data/rsnchat_gem.gemspec +14 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f6b058a0a995b2756e2be485379885d098c77962224aa06e88789fe8ae76a118
|
|
4
|
+
data.tar.gz: f732cf60168449dd69b187186373a3ce9599cd226ce7f45296607afcb42e3fcf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 278b61d04c51fec78932cfe09c568a057d13d63daee641aef9ba0bc5f33053deb2cf3d18a61b45b5f0b66042c0082bd58d099d19734824074494de4b5e12d04c
|
|
7
|
+
data.tar.gz: 6ab821ffabcfa52331e23529d021fc5a194db89a0a93fd7e9437275b145fdb32d9619a5cfaa9238d1a896c278b72c19dd2debebed9c500b7e2fbc77bd505d768
|
data/bin/cli.rb
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'rest-client'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'colorize'
|
|
6
|
+
|
|
7
|
+
class RsnChat
|
|
8
|
+
def initialize(api_key)
|
|
9
|
+
raise 'Please provide an API key' unless api_key
|
|
10
|
+
|
|
11
|
+
@api_key = api_key
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def validate_api_key(api_key)
|
|
15
|
+
begin
|
|
16
|
+
payload = { key: api_key }.to_json
|
|
17
|
+
headers = { content_type: :json }
|
|
18
|
+
|
|
19
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/validate', payload, headers)
|
|
20
|
+
|
|
21
|
+
return response if response.code == 200
|
|
22
|
+
|
|
23
|
+
handle_error_response(response.code)
|
|
24
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
25
|
+
handle_error_response(e.response.code)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def gpt(prompt)
|
|
30
|
+
call_chat_method('gpt', prompt)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def bard(prompt)
|
|
34
|
+
call_chat_method('bard', prompt)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def openchat(prompt)
|
|
38
|
+
call_chat_method('openchat', prompt)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def llama(prompt)
|
|
42
|
+
call_chat_method('llama', prompt)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def gemini(prompt)
|
|
46
|
+
call_chat_method('gemini', prompt)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def mixtral(prompt)
|
|
50
|
+
call_chat_method('mixtral', prompt)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def call_chat_method(method, prompt)
|
|
56
|
+
begin
|
|
57
|
+
payload = { prompt: prompt }
|
|
58
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
59
|
+
|
|
60
|
+
response = RestClient.post("https://ai.rnilaweera.ovh/api/v1/user/#{method}", payload.to_json, headers)
|
|
61
|
+
return JSON.parse(response.body)
|
|
62
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
63
|
+
raise "RsnChat #{method.capitalize} Error: #{e.response}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def handle_error_response(status)
|
|
68
|
+
case status
|
|
69
|
+
when 403
|
|
70
|
+
puts 'Invalid API key. Please try again.'.red
|
|
71
|
+
when 503
|
|
72
|
+
puts 'Service Unavailable - Maintain Mode'.red
|
|
73
|
+
else
|
|
74
|
+
puts "Unexpected response from the server. Status: #{status}. Please try again.".red
|
|
75
|
+
end
|
|
76
|
+
prompt_api_key
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def prompt_api_key
|
|
81
|
+
puts_ascii_art
|
|
82
|
+
|
|
83
|
+
print('Enter your API key: '.green)
|
|
84
|
+
api_key = gets.chomp
|
|
85
|
+
|
|
86
|
+
begin
|
|
87
|
+
response = RsnChat.new('').validate_api_key(api_key)
|
|
88
|
+
|
|
89
|
+
if response&.code == 200
|
|
90
|
+
username = response.body['user']
|
|
91
|
+
rsn_chat = RsnChat.new(api_key)
|
|
92
|
+
start_chat(rsn_chat, response)
|
|
93
|
+
else
|
|
94
|
+
handle_error_response(response&.code)
|
|
95
|
+
end
|
|
96
|
+
rescue RuntimeError => e
|
|
97
|
+
puts e.message.red
|
|
98
|
+
prompt_api_key
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def puts_ascii_art
|
|
103
|
+
puts "
|
|
104
|
+
##
|
|
105
|
+
#### #### ## ##
|
|
106
|
+
## # #### # ## ### # ## # ### #####
|
|
107
|
+
## # ## ## ## ## ##### ## ##
|
|
108
|
+
#### #### ## ## ## ## ## #### ##
|
|
109
|
+
## # #### ## ## ## ## ## ## ## ##
|
|
110
|
+
## # ## ## ## ### ## ## ## ## ##
|
|
111
|
+
## # #### ## ## #### ## ## ## # ###
|
|
112
|
+
".green.bold
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def start_chat(rsn_chat, response)
|
|
116
|
+
response_body = JSON.parse(response.body) rescue nil
|
|
117
|
+
if response_body && response_body['success']
|
|
118
|
+
username = response_body['user']
|
|
119
|
+
puts "\nWelcome to #{username}'s RsnChat CLI!\n".yellow
|
|
120
|
+
prompt_chat_method(rsn_chat)
|
|
121
|
+
else
|
|
122
|
+
handle_error_response(response&.code)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def prompt_chat_method(rsn_chat)
|
|
127
|
+
print('Select a chat method (GPT, BARD, OPENCHAT, LLAMA, GEMINI, MIXTRAL), or type "exit" to exit: '.cyan)
|
|
128
|
+
method = gets.chomp.upcase
|
|
129
|
+
|
|
130
|
+
case method
|
|
131
|
+
when 'EXIT'
|
|
132
|
+
puts "\nExiting RsnChat CLI. Goodbye!\n".yellow
|
|
133
|
+
when 'GPT', 'BARD', 'OPENCHAT', 'LLAMA', 'GEMINI', 'MIXTRAL'
|
|
134
|
+
prompt_user(method, rsn_chat)
|
|
135
|
+
else
|
|
136
|
+
puts 'Invalid chat method. Please select GPT, BARD, OPENCHAT, LLAMA, GEMINI, MIXTRAL, or type "exit" to exit.'.red
|
|
137
|
+
prompt_chat_method(rsn_chat)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def prompt_user(method, rsn_chat)
|
|
142
|
+
print("Enter your #{method} prompt (or type \"exit\" to exit): ".green)
|
|
143
|
+
prompt = gets.chomp
|
|
144
|
+
|
|
145
|
+
case prompt.downcase
|
|
146
|
+
when 'chat'
|
|
147
|
+
prompt_chat_method(rsn_chat)
|
|
148
|
+
when 'exit'
|
|
149
|
+
puts "\nExiting RsnChat CLI. Goodbye!\n".yellow
|
|
150
|
+
else
|
|
151
|
+
begin
|
|
152
|
+
response = rsn_chat.send(method.downcase, prompt)
|
|
153
|
+
puts "#{method} Response:".blue.bold + " #{response['message']}"
|
|
154
|
+
rescue RuntimeError => e
|
|
155
|
+
puts "Error calling #{method}: #{e.message}".red
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
prompt_user(method, rsn_chat)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
prompt_api_key
|
data/lib/rsn_chat.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'rest-client'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class RsnChat
|
|
5
|
+
def initialize(api_key)
|
|
6
|
+
raise 'Please provide an API key' unless api_key
|
|
7
|
+
|
|
8
|
+
@api_key = api_key
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def gpt(prompt)
|
|
12
|
+
begin
|
|
13
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
14
|
+
payload = { prompt: prompt }
|
|
15
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
16
|
+
|
|
17
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/gpt', payload.to_json, headers)
|
|
18
|
+
return JSON.parse(response.body)
|
|
19
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
20
|
+
raise "RsnChat GPT Error: #{e.response}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def openchat(prompt)
|
|
25
|
+
begin
|
|
26
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
27
|
+
payload = { prompt: prompt }
|
|
28
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
29
|
+
|
|
30
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/openchat', payload.to_json, headers)
|
|
31
|
+
return JSON.parse(response.body)
|
|
32
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
33
|
+
raise "RsnChat OpenChat Error: #{e.response}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def bard(prompt)
|
|
38
|
+
begin
|
|
39
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
40
|
+
payload = { prompt: prompt }
|
|
41
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
42
|
+
|
|
43
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/bard', payload.to_json, headers)
|
|
44
|
+
return JSON.parse(response.body)
|
|
45
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
46
|
+
raise "RsnChat Bard Error: #{e.response}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def gemini(prompt)
|
|
51
|
+
begin
|
|
52
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
53
|
+
payload = { prompt: prompt }
|
|
54
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
55
|
+
|
|
56
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/gemini', payload.to_json, headers)
|
|
57
|
+
return JSON.parse(response.body)
|
|
58
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
59
|
+
raise "RsnChat Gemimi Error: #{e.response}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def llama(prompt)
|
|
64
|
+
begin
|
|
65
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
66
|
+
payload = { prompt: prompt }
|
|
67
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
68
|
+
|
|
69
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/llama', payload.to_json, headers)
|
|
70
|
+
return JSON.parse(response.body)
|
|
71
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
72
|
+
raise "RsnChat LlaMa Error: #{e.response}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def mixtral(prompt)
|
|
77
|
+
begin
|
|
78
|
+
#puts "DEBUG: Prompt before request: #{prompt}"
|
|
79
|
+
payload = { prompt: prompt }
|
|
80
|
+
headers = { Authorization: "Bearer #{@api_key}", content_type: :json }
|
|
81
|
+
|
|
82
|
+
response = RestClient.post('https://ai.rnilaweera.ovh/api/v1/user/mixtral', payload.to_json, headers)
|
|
83
|
+
return JSON.parse(response.body)
|
|
84
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
85
|
+
raise "RsnChat Mixtral Error: #{e.response}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
data/rsnchat_gem.gemspec
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Gem::Specification.new do |spec|
|
|
2
|
+
spec.name = 'rsnchat'
|
|
3
|
+
spec.version = '2.0.0'
|
|
4
|
+
spec.summary = 'The Ultimate AI Powered Package'
|
|
5
|
+
spec.description = 'A package for interacting with GPT4-based chat services, OpenChat, Bard, Gemini, LlaMa, and Mixtral'
|
|
6
|
+
spec.authors = ['rnilaweera']
|
|
7
|
+
spec.email = ['stacxdev@gmail.com']
|
|
8
|
+
spec.license = 'MIT'
|
|
9
|
+
spec.homepage = 'https://github.com/RsnGPT/rsnchat-gem'
|
|
10
|
+
spec.files = Dir.glob("{lib,bin}/**/*") + ['rsnchat_gem.gemspec']
|
|
11
|
+
spec.required_ruby_version = '>= 3.0.0'
|
|
12
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
|
13
|
+
spec.executables = ['cli.rb']
|
|
14
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rsnchat
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- rnilaweera
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: minitest
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.0'
|
|
27
|
+
description: A package for interacting with GPT4-based chat services, OpenChat, Bard,
|
|
28
|
+
Gemini, LlaMa, and Mixtral
|
|
29
|
+
email:
|
|
30
|
+
- stacxdev@gmail.com
|
|
31
|
+
executables:
|
|
32
|
+
- cli.rb
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- bin/cli.rb
|
|
37
|
+
- lib/rsn_chat.rb
|
|
38
|
+
- rsnchat_gem.gemspec
|
|
39
|
+
homepage: https://github.com/RsnGPT/rsnchat-gem
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
metadata: {}
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 3.0.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.4.6
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: The Ultimate AI Powered Package
|
|
62
|
+
test_files: []
|