ref: 5dd90f003508a4d47a4cc3880600f3164b19b336
dir: /Test_HTTP.rb/
require 'net/http' require 'uri' require 'json' uri = URI('https://gpt-gm.h2o.ai/conversation/64ac1344245bd909c99ed909') https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Post.new(uri.path) request['Content-Type'] = 'application/json; charset=UTF-8' request['User-Agent'] = 'Mozilla/5.0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.127 Safari/537.36' request['Cookie'] = 'h2ogpt-chat=a4fc9f08-6c67-466c-8d36-dd425702d6b4' request.body = '{"inputs":"aa","parameters":{"temperature":0.1,"truncate":2048,"max_new_tokens":1024,"do_sample":true,"repetition_penalty":1.2,"return_full_text":false},"stream":true,"options":{"id":"6543eb99-e311-4f4e-b791-7af4fcbe556b","response_id":"b194833d-e13c-4390-9d7f-3cf4e4d95430","is_retry":false,"use_cache":false,"web_search_id":""}}' response = https.request(request) json_strings = response.body.split('data:') parsed_json_objects = [] json_strings.each do |json_str| if json_str != '' parsed_json_objects << JSON.parse(json_str) end end parsed_json_objects.each do |json_obj| result = json_obj['token']['text'] if result == '' then break end print result end url = URI.parse('https://gpt-gm.h2o.ai/conversation/64ac1344245bd909c99ed909') # Replace with your API endpoint # Create the HTTP object http = Net::HTTP.new(url.host, 443) # Build the request request = Net::HTTP::Post.new(url.path) # 'Cookie', 'h2ogpt-chat=a4fc9f08-6c67-466c-8d36-dd425702d6b4' # 'User-Agent', 'Mozilla/5.0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.127 Safari/537.36' request['Content-Type'] = 'application/json; charset=UTF-8' request['User-Agent'] = 'Mozilla/5.0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.127 Safari/537.36' request['Cookie'] = 'h2ogpt-chat=a4fc9f08-6c67-466c-8d36-dd425702d6b4' # Set the request body, if required request.body = '{"inputs":"aa","parameters":{"temperature":0.1,"truncate":2048,"max_new_tokens":1024,"do_sample":true,"repetition_penalty":1.2,"return_full_text":false},"stream":true,"options":{"id":"6543eb99-e311-4f4e-b791-7af4fcbe556b","response_id":"b194833d-e13c-4390-9d7f-3cf4e4d95430","is_retry":false,"use_cache":false,"web_search_id":""}}' request.timeout = 10000 # Send the request response = http.request(request) # Get the response puts response.code # HTTP response code puts response.body # Response body