wm: irc-h2o-bot

Download patch

ref: 5dd90f003508a4d47a4cc3880600f3164b19b336
parent: 0ba61b0c955f5652abbb488fd96d169398e7b2de
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Mon Jul 10 15:16:32 EDT 2023

Test_HTTPS Added

--- /dev/null
+++ b/Test_HTTP.rb
@@ -1,0 +1,65 @@
+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
\ No newline at end of file
--- a/Test_JSON.rb
+++ b/Test_JSON.rb
@@ -20,6 +20,48 @@
 # puts "City: #{city}"
 
 
+
+data_string = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null} data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}'
+
+m = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":12,"text":"!","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":1265,"text":" How","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":418,"text":" can","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":295,"text":" I","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":733,"text":" help","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":299,"text":" you","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":1722,"text":" today","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":42,"text":"?","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+  'data:{"token":{"id":11,"text":"<|endoftext|>","logprob":0.0,"special":true},"generated_text":"Hello! How can I help you today?","details":null}';
+
+
+
+# Split the data string into individual JSON strings
+json_strings = m.split('\n')
+
+# Initialize an array to store the parsed JSON objects
+parsed_json_objects = []
+
+# Iterate over each JSON string and parse it
+json_strings.each do |json_str|
+  if json_str.start_with?('data:')
+    # Remove the leading "data:" prefix
+    json_data = json_str[5..-1]
+
+    # Parse the JSON string and add it to the parsed_json_objects array
+    parsed_json_objects << JSON.parse(json_data)
+  end
+end
+
+# Print the parsed JSON objects
+parsed_json_objects.each do |json_obj|
+  # puts JSON.pretty_generate(json_obj)
+  print json_obj['token']['text']
+end
+
+
+
+
 data_string = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null} data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}'
 
 # Split the data_string on whitespace followed by "data:" to separate each JSON string