ref: 2eebe5d9f9511c34cb90bf6852d01c42a60a66c2
dir: /Test_HTTP.rb/
require 'net/http' require 'uri' require 'json' # a = '\n\n' # if a.include?('\n') # puts "The string contains '\\n'" # else # puts "The string does not contain '\\n'" # end 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