inloop-brain 0.0.3 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/inloop-brain +70 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc3821a74432fd8caf104cf5e5025f1865cd9e4c058e8a42d00512755f321107
4
- data.tar.gz: 6d3c355aacc0733c7f5fc9d8b37fe9fce684b7f1879f160c311de2041a4c9cb5
3
+ metadata.gz: d1225dd8339b48516cc2cfc3642082181a19da5404900ebeffa2fcec17b9139f
4
+ data.tar.gz: 8f0925cd406f032862dafb9df8ed6b27c0a764086b51486098856aaaa26454ba
5
5
  SHA512:
6
- metadata.gz: b8a91cb7a242b657c35c59c57eae90b79661e4059f4f7603723a98dcc9f02a47896d5123847d58d2ab78b20d0e00e83495354ffb3ee395c50f0408f5fb9ac268
7
- data.tar.gz: 5683cad7c1cc6ce13c778b744750e9f1e2e15d2ad269d9f703757c822dd9ec52071ab02606e1078bf21be82f8533177167a7ce683ad96eeed064653e3826c6ec
6
+ metadata.gz: 52051ef4783af702e228cb3e55c0cea27ee2d8a09e88d5c282748850293ecd6327dfe1957c43a92899a1d12b8679e8ee8e162e438d183516eebe5876e376dfd7
7
+ data.tar.gz: 297cf080865234df41e84d3e603cf0eb2040164054a91a9b2f479d4652b88eac7d81e636ac972b42211bbf12b82e329da164e728cb9d29febf710715efd4faad
data/bin/inloop-brain CHANGED
@@ -1,5 +1,73 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative "../lib/inloop-brain"
3
+ # bin/inloop-brain - A command-line tool to interact with the Brain Access Kit API
4
4
 
5
- Inloop::Brain::CLI.start(ARGV)
5
+ require 'optparse'
6
+ require 'net/http'
7
+ require 'uri'
8
+
9
+ # Parse command line options
10
+ options = {}
11
+ parser = OptionParser.new do |opts|
12
+ opts.banner = "This is brain access kit of inloop.studio\n\n Usage: inloop-brain [options]"
13
+ opts.on('-k KEY', '--key=KEY', 'Access key for the Brain Access Kit') do |key|
14
+ options[:key] = key
15
+ end
16
+ opts.on('-h', '--help', 'Display this help message') do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ begin
23
+ parser.parse!
24
+ rescue OptionParser::InvalidOption => e
25
+ STDERR.puts e.message
26
+ STDERR.puts parser
27
+ exit 1
28
+ end
29
+
30
+ # Validate required parameters
31
+ unless options[:key]
32
+ STDERR.puts "Error: Missing required parameter 'key'"
33
+ STDERR.puts parser
34
+ exit 1
35
+ end
36
+
37
+ # Read input from STDIN
38
+ input = STDIN.read.strip
39
+
40
+ # Exit if no input provided
41
+ if input.empty?
42
+ STDERR.puts "Error: No input provided via STDIN"
43
+ exit 1
44
+ end
45
+
46
+ # Configure the API request
47
+ host = ENV['INLOOP_BRAIN_HOST'] || 'localhost:3000' # Default to localhost:3000
48
+ protocol = ENV['INLOOP_BRAIN_PROTOCOL'] || 'http' # Default to http
49
+ endpoint = "/web_tools/brain_access_kit/#{options[:key]}/handle_prompt.txt"
50
+ uri = URI.parse("#{protocol}://#{host}#{endpoint}")
51
+
52
+ # Setup the HTTP request
53
+ http = Net::HTTP.new(uri.host, uri.port)
54
+ http.use_ssl = (uri.scheme == 'https')
55
+
56
+ request = Net::HTTP::Post.new(uri.path)
57
+ request.set_form_data('prompt' => input)
58
+
59
+ # Send the request and handle the response
60
+ begin
61
+ response = http.request(request)
62
+
63
+ if response.code.to_i == 200
64
+ puts response.body
65
+ else
66
+ STDERR.puts "Error: API returned status code #{response.code}"
67
+ STDERR.puts response.body
68
+ exit 1
69
+ end
70
+ rescue => e
71
+ STDERR.puts "Error: Failed to connect to the API: #{e.message}"
72
+ exit 1
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inloop-brain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhishek Parolkar