inloop-brain 0.0.4 → 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.
- checksums.yaml +4 -4
 - data/bin/inloop-brain +70 -2
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d1225dd8339b48516cc2cfc3642082181a19da5404900ebeffa2fcec17b9139f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8f0925cd406f032862dafb9df8ed6b27c0a764086b51486098856aaaa26454ba
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            # bin/inloop-brain - A command-line tool to interact with the Brain Access Kit API
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     |