inloop-brain 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b41aa8aad41b500dc36f73a6e8ba189bc59fbb075d247b662701b78f8f4d39de
4
- data.tar.gz: 79193e316f4d9f0c61b77181b892323f8f5f6ac03732cbb6b626d849664fde48
3
+ metadata.gz: 61025b8763503388d32c42d1169bd9e4231da28b6d383a7e9039fe55bc5e951e
4
+ data.tar.gz: 3da29a86dca04caf0b20cb08bc1cc7a7c1597613bee59042d2cf0ef863b62499
5
5
  SHA512:
6
- metadata.gz: 48b3b27a5155159192447412051c89184bc74a664357ebc50e32b56a75db472cdd0cde7deecf90025bca3ca075010e52da199e371b30705782f23019e2e34d53
7
- data.tar.gz: ef570edf09d65eaec5f7712a29d8cddae885147863faafc1651d70a24101a33a8a1f2154a7b5b337f734e86f98bd5a27c198cc93ff9bf812f28bf4d06c9323eb
6
+ metadata.gz: 4c484e3325531265497f6e2e1bd914e0b6f4525505840095af558330b2c28edaf8528eb9325205bdb349725db605640af96c622298b46474009d8bc186e8d23e
7
+ data.tar.gz: 7f516136819c318c81718348a61598c414b931fa3d54c385f8d11868081035e0c251963bc760906674a111f0be6269754cf35e91ef8a4adfbe7c9ef9381791e4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Inloop Brain
2
2
 
3
- A command-line tool for interacting with the Inloop Brain Access Kit API.
3
+ A command-line tool for interacting with the Inloop Brain OpenAI-compatible API.
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,21 +15,30 @@ gem install inloop-brain
15
15
  ## Usage
16
16
 
17
17
  ```
18
- echo "What can you do?" | inloop-brain --key=YOUR_ACCESS_KEY
18
+ echo "What can you do?" | inloop-brain --key=YOUR_API_KEY
19
19
  ```
20
20
 
21
21
  Or
22
22
 
23
23
  ```
24
- echo "What can you do?" | inloop-brain -k YOUR_ACCESS_KEY > output.txt
24
+ echo "What can you do?" | inloop-brain -k YOUR_API_KEY > output.txt
25
25
  ```
26
26
 
27
27
  ### Environment Variables
28
28
 
29
- You can customize the target host and protocol:
29
+ Use an API key generated from the Brain API share link in app.inloop.studio. The API uses the published `llms.txt` context when available.
30
30
 
31
- - `INLOOP_BRAIN_HOST`: Host to connect to (default: localhost:3000)
32
- - `INLOOP_BRAIN_PROTOCOL`: Protocol to use (default: http)
31
+ - `INLOOP_BRAIN_API_KEY`: API key used for Authorization (recommended)
32
+ - `INLOOP_BRAIN_API_URL`: Full API URL (default: https://app.inloop.studio/api/v1/chat/completions)
33
+ - `INLOOP_BRAIN_MODEL`: Model name to send (default: inloop-brain)
34
+ - `INLOOP_BRAIN_HOST`: Host override (default: app.inloop.studio)
35
+ - `INLOOP_BRAIN_PROTOCOL`: Protocol override (default: https)
36
+
37
+ ### Options
38
+
39
+ - `--api-url`: Override API URL
40
+ - `--model`: Model name to send
41
+ - `--system`: System prompt to prepend
33
42
 
34
43
  ## Development
35
44
 
data/bin/inloop-brain CHANGED
@@ -1,18 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # bin/inloop-brain - A command-line tool to interact with the Brain Access Kit API
3
+ # bin/inloop-brain - A command-line tool to interact with the Inloop Brain API (OpenAI-compatible)
4
4
 
5
5
  require 'optparse'
6
6
  require 'net/http'
7
7
  require 'uri'
8
+ require 'json'
8
9
 
9
10
  # Parse command line options
10
11
  options = {}
11
12
  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|
13
+ opts.banner = "This is the Inloop Brain CLI\n\n Usage: inloop-brain [options]"
14
+ opts.on('-k KEY', '--key=KEY', 'API key for the Inloop Brain (OpenAI-compatible)') do |key|
14
15
  options[:key] = key
15
16
  end
17
+ opts.on('-m MODEL', '--model=MODEL', 'Model name (default: inloop-brain)') do |model|
18
+ options[:model] = model
19
+ end
20
+ opts.on('--system=TEXT', 'System prompt to prepend to the conversation') do |text|
21
+ options[:system] = text
22
+ end
23
+ opts.on('--api-url=URL', 'Override API URL (default: https://app.inloop.studio/api/v1/chat/completions)') do |url|
24
+ options[:api_url] = url
25
+ end
16
26
  opts.on('-d', '--debug', 'Enable debug mode') do
17
27
  options[:debug] = true
18
28
  end
@@ -31,8 +41,9 @@ rescue OptionParser::InvalidOption => e
31
41
  end
32
42
 
33
43
  # Validate required parameters
44
+ options[:key] ||= ENV['INLOOP_BRAIN_API_KEY']
34
45
  unless options[:key]
35
- STDERR.puts "Error: Missing required parameter 'key'"
46
+ STDERR.puts "Error: Missing required parameter 'key' (or set INLOOP_BRAIN_API_KEY)"
36
47
  STDERR.puts parser
37
48
  exit 1
38
49
  end
@@ -47,10 +58,13 @@ if input.empty?
47
58
  end
48
59
 
49
60
  # Configure the API request
50
- host = ENV['INLOOP_BRAIN_HOST'] || 'discovery.inloop.studio'
51
- protocol = ENV['INLOOP_BRAIN_PROTOCOL'] || 'https'
52
- endpoint = "/web_tools/brain_access_kit/#{options[:key]}/handle_prompt.txt"
53
- uri = URI.parse("#{protocol}://#{host}#{endpoint}")
61
+ api_url = options[:api_url] || ENV['INLOOP_BRAIN_API_URL']
62
+ if api_url.nil? || api_url.strip.empty?
63
+ host = ENV['INLOOP_BRAIN_HOST'] || 'app.inloop.studio'
64
+ protocol = ENV['INLOOP_BRAIN_PROTOCOL'] || 'https'
65
+ api_url = "#{protocol}://#{host}/api/v1/chat/completions"
66
+ end
67
+ uri = URI.parse(api_url)
54
68
 
55
69
  if options[:debug]
56
70
  puts "Making request to: #{uri}"
@@ -64,14 +78,21 @@ http.use_ssl = (uri.scheme == 'https')
64
78
  http.open_timeout = 10
65
79
  http.read_timeout = 60
66
80
 
67
- request = Net::HTTP::Post.new(uri.path)
81
+ request = Net::HTTP::Post.new(uri)
68
82
  # Set proper headers
69
- request['Content-Type'] = 'application/x-www-form-urlencoded'
70
- request['Accept'] = 'text/plain'
71
- request['User-Agent'] = 'Inloop-Brain-CLI/0.0.1'
83
+ request['Content-Type'] = 'application/json'
84
+ request['Accept'] = 'application/json'
85
+ request['Authorization'] = "Bearer #{options[:key]}"
86
+ request['User-Agent'] = 'Inloop-Brain-CLI/0.0.9'
72
87
 
73
- # Set form data
74
- request.set_form_data('prompt' => input)
88
+ messages = []
89
+ messages << { role: 'system', content: options[:system] } if options[:system].to_s.strip != ''
90
+ messages << { role: 'user', content: input }
91
+ body = {
92
+ model: options[:model] || ENV['INLOOP_BRAIN_MODEL'] || 'inloop-brain',
93
+ messages: messages
94
+ }
95
+ request.body = JSON.dump(body)
75
96
 
76
97
  # Send the request and handle the response
77
98
  begin
@@ -89,20 +110,26 @@ begin
89
110
  response.each_header { |key, value| puts " #{key}: #{value}" }
90
111
  end
91
112
 
113
+ begin
114
+ payload = JSON.parse(response.body.to_s)
115
+ rescue JSON::ParserError
116
+ payload = nil
117
+ end
118
+
92
119
  if response.code.to_i == 200
93
- puts response.body
120
+ content = payload.dig("choices", 0, "message", "content") if payload
121
+ content ||= payload.dig("choices", 0, "text") if payload
122
+ if content
123
+ puts content
124
+ else
125
+ STDERR.puts "Error: Unexpected response format"
126
+ STDERR.puts response.body
127
+ exit 1
128
+ end
94
129
  else
130
+ message = payload.dig("error", "message") if payload
95
131
  STDERR.puts "Error: API returned status code #{response.code}"
96
- STDERR.puts response.body
97
-
98
- # Additional troubleshooting for 422 errors
99
- if response.code.to_i == 422
100
- STDERR.puts "\nThe 422 error typically indicates a validation problem. Possible issues:"
101
- STDERR.puts "1. The endpoint format may have changed"
102
- STDERR.puts "2. The access key format may be incorrect"
103
- STDERR.puts "3. The prompt may be in an invalid format"
104
- STDERR.puts "\nTry running with --debug for more information."
105
- end
132
+ STDERR.puts(message || response.body)
106
133
  exit 1
107
134
  end
108
135
  rescue => e
data/inloop-brain.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "inloop-brain"
5
- spec.version = "0.0.8"
5
+ spec.version = "0.0.9"
6
6
  spec.authors = ["Abhishek Parolkar"]
7
7
  spec.email = ["abhishek@inloop.studio"]
8
8
 
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhishek Parolkar