ref: b087007630e4e073ffca2a3be249645dc4db8713
parent: b717d027b8f6705d6b6eb11dd6ea2ecd0c1cb980
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Tue Jul 25 16:27:39 EDT 2023
Test Files Deleted
--- a/.idea/Test-IRC.iml
+++ b/.idea/Test-IRC.iml
@@ -20,7 +20,6 @@
<orderEntry type="library" scope="PROVIDED" name="fiber-annotation (v0.2.0, ruby-3.2.1-p31) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="fiber-local (v1.0.0, ruby-3.2.1-p31) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="io-event (v1.2.2, ruby-3.2.1-p31) [gem]" level="application" />
- <orderEntry type="library" scope="PROVIDED" name="net-yail (v1.6.2, ruby-3.2.1-p31) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="protocol-hpack (v1.4.2, ruby-3.2.1-p31) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="protocol-http (v0.24.4, ruby-3.2.1-p31) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="protocol-http1 (v0.15.0, ruby-3.2.1-p31) [gem]" level="application" />
--- a/Test_HTTP.rb
+++ /dev/null
@@ -1,44 +1,0 @@
-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
--- a/Test_JSON.rb
+++ /dev/null
@@ -1,109 +1,0 @@
-require 'json'
-
-# JSON string to be parsed
-#json_string = 'data:{"name": "John", "age": 30, "city": "New York"}'
-
-# Parse the JSON string
-
-#test = json_string.sub('data:', '')
-
-# parsed_json = JSON.parse(test)
-#
-# # Access the values from the parsed JSON
-# name = parsed_json['name']
-# age = parsed_json['age']
-# city = parsed_json['city']
-#
-# # Output the values
-# puts "Name: #{name}"
-# puts "Age: #{age}"
-# 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
-json_strings = data_string.scan(/data:(\{.*?\})/)
-
-parsed_data = []
-
-json_strings.each do |json_str|
- # Prepend "data:" to the JSON string since it was removed during splitting
- # json_str = "data:" + json_str
-
- # Parse the JSON string
- parsed_data << JSON.parse(json_str)
-end
-
-# Now you have an array of parsed JSON objects
-parsed_data.each do |data|
- puts data.inspect
-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}'
-
-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}';
-
-results = data_string.scan(/data:(\{.*?\})/)
-
-parsed_data = results.map { |item| JSON.parse(item[0]) }
-
-parsed_data.each do |data|
- puts "Name: #{data['token']['text']}"
- # puts "Age: #{data['age']}"
- # puts "City: #{data['city']}"
-end
-
--- a/Test_Multi_Threading.rb
+++ /dev/null
@@ -1,94 +1,0 @@
-require 'thread'
-require 'concurrent'
-require 'async'
-require 'async/http/internet'
-
-class Echo
- include Concurrent::Async
-
- def echo(msg)
- sleep(3)
- print "#{msg}\n"
- end
-end
-
-horn = Echo.new
-horn.echo('zero') # synchronous, not thread-safe
-# returns the actual return value of the method
-
-horn.async.echo('one') # asynchronous, non-blocking, thread-safe
-# returns an IVar in the :pending state
-
-horn.async.echo('two') # synchronous, blocking, thread-safe
-# returns an IVar in the :complete state
-
-start = Time.now
-
-Async do |task|
- http_client = Async::HTTP::Internet.new
-
- task.async do
- http_client.get("https://httpbin.org/delay/1.6")
- end
-
-end
-
-puts "Duration: #{Time.now - start}"
-
-
-executor = Concurrent::ThreadPoolExecutor.new(
- min_threads: 2,
- max_threads: 5,
- max_queue: 10
-)
-
-futures = []
-
-5.times do |i|
- futures << Concurrent::Future.execute(executor: executor) do
- puts "Async task #{i} started"
- sleep(rand(1..5))
- puts "Async task #{i} finished"
- end
-end
-
-futures.each(&:wait)
-executor.shutdown
-
-# Define a method that performs some asynchronous task
-def async_task(name)
- puts "Starting #{name}"
-
- # Simulate some work
- sleep(rand(5))
-
- puts "#{name} completed"
-end
-
-# Create multiple threads for asynchronous execution
-threads = []
-threads << Thread.new { async_task('Task 1') }
-threads << Thread.new { async_task('Task 2') }
-threads << Thread.new { async_task('Task 3') }
-
-# Wait for all threads to complete
-threads.each(&:join)
-
-puts "All tasks completed"
-
-
-
-def Test
- for i in 0..10 do
- puts i
- sleep(rand(0.1..1.0));
- end
-end
-
-t1 = Thread.new{Test()}
-t2 = Thread.new{Test()}
-puts 'moz'
-t1.join
-
-t2.join
-
--- a/Test_cinch.rb
+++ /dev/null
@@ -1,24 +1,0 @@
-require 'cinch'
-
-hash = { :invalid => :replace, :undef => :replace}
-string = hash.to_s
-
-puts string
-
-bot = Cinch::Bot.new do
- configure do |c|
- c.server = 'irc.ircnow.org'
- c.channels = ['#fpc']
- c.nick = 'moz0'
- end
-
- on :connect do
- # This block will be executed when the bot connects to the IRC server
- # You can put your async message sending logic here
- a = 'a'
- Channel('#channel').send(a.to_s) # Replace '#channel' with the actual channel name
- bot.quit # Quit the bot after sending the message
- end
-end
-
-bot.start
\ No newline at end of file
--- a/ruby-irc.rb
+++ /dev/null
@@ -1,12 +1,0 @@
-require 'IRC'
-
-bot = IRC.new("h2o", "irc.ircnow.org", "6667", "H2O")
-IRCEvent.add_callback('endofmotd') { |event| bot.add_channel('#fpc') }
-IRCEvent.add_callback('invite') { |event| bot.add_channel(event.message) }
-IRCEvent.add_callback('join') { |event|
- bot.send_message(event.channel, "Hello #{event.from}")
- IRCEvent.add_callback('privmsg') {|e|
- puts e.message
- }
-}
-bot.connect
\ No newline at end of file
--- a/test.rb
+++ /dev/null
@@ -1,254 +1,0 @@
-require 'rubygems'
-require 'net/yail'
-require 'net/http'
-require 'uri'
-require 'json'
-require 'concurrent'
-require 'async'
-require 'async/http/internet'
-require 'async/http/endpoint'
-require 'IRC'
-
-# executor = Concurrent::ThreadPoolExecutor.new(
-# min_threads: 2,
-# max_threads: 5,
-# max_queue: 10
-# )
-
-config = File.read('CONFIG')
-
-parsed_config = JSON.parse(config)
-Server = parsed_config['IRCServer']
-BotNick = parsed_config['BotNickName']
-$URL = parsed_config['SessionUrl']
-$Cookie = parsed_config['SessionCookie']
-
-$irc = Net::YAIL.new(
- :address => 'irc.ircnow.org',
- :username => 'Moz_Bot',
- :realname => 'Moz_Mozak',
- :nicknames => ['h2o-bot0']
-)
-
-
-$bot = IRC.new(
- BotNick,
- Server,
- "6667",
- "H2O")
-
-
-$is = false
-$currentid = ''
-
-
-$irc.on_welcome proc { |event| $irc.join('#fpc') }
-
-
-$irc.on_invite { |event| $irc.join(event.channel) }
-
-$irc.set_callback(:incoming_invite) { |event| $irc.join(event.channel) }
-
-$irc.hearing_ping {|event| $stderr.puts event.inspect}
-
-$irc.hearing_message(:if => {:pm? => true}) do |event|
- event.handle!
-end
-
-$irc.on_invite { |e| $irc.join(e.channel) }
-
-#:if => {:message => "bah"}
-@stack = []
-
-def Push(a,b)
- @stack << {:peer => a, :message => b}
-
-end
-
-def Send
- $bot.send_message(@stack[0][':peer'], @stack[0][':message'])
-end
-class Sender
- include Concurrent::Async
- $irc0 = Net::YAIL.new(
- :address => 'irc.ircnow.org',
- :username => 'Moz_Bot',
- :realname => 'Moz_Mozak',
- :nicknames => ['h2o-bot0']
- )
- def Wait(peer)
- $irc.msg(peer, 'Im thinking...')
- end
-
- def SendReq(peer, input, c)
- uri = URI($URL)
- 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'] = 'Pedaret 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'] = $Cookie
-
- request.body = '{"inputs":"'+ input.to_s() +'","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":""}}'
-
-
- # Async do |task|
-
- # Async do
- # endpoint = Async::HTTP::Endpoint.parse('https://gpt-gm.h2o.ai/conversation/64ac1344245bd909c99ed909')
- # http = Async::HTTP::Internet.new
- #
- # request = Async::HTTP::Request.new(:post, endpoint.path,
- # {'Content-Type' => 'application/json; charset=UTF-8'},
- # {'Cookie' => 'h2ogpt-chat=a4fc9f08-6c67-466c-8d36-dd425702d6b4'},
- # '{"inputs":"'+ input.to_s() +'","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 = http.call(endpoint, request)
- #
- # # Process the response
- # puts "Response code: #{response.status}"
- # puts "Response body: #{response.read}"
- #
- #
- # end
-
- # request = Async::HTTP::Internet.new
- #
- # 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":"'+ input.to_s() +'","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":""}}'
- #
-
- # task.async do
- # request.post(uri.host)
- # end
-
- # end
-
- begin
- response = https.request(request)
-
- #$irc.msg('#fpc', e.message)
-
- 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
-
- counts = 0
-
- b = ''
- parsed_json_objects.each do |json_obj|
- result = json_obj['token']['text']
- if result == '<|endoftext|>' then
- break
- elsif counts >= 50
- begin
- $bot.send_message(peer, 'limit reached!')
- break
- end
- elsif result.include?("\n")
- begin
- $bot.send_message(peer, b)
- sleep(0.2)
- counts += 1
- #$irc.msg(peer, b)
- b = ''
- end
- else
- b += result
- end
- end
-
- $bot.send_message(peer, b)
- #$irc.msg(peer, b)
-
- rescue StandardError => e
- $bot.send_message(peer, e)
- #$irc.msg(peer, e)
- end
- end
-
-end
-sender = Sender.new
-
-
-IRCConnection.add_IO_socket(STDIN)
-IRCEvent.add_callback('endofmotd') { |event| $bot.add_channel('#fpc') }
-IRCEvent.add_callback('invite') do |event|
- puts event.message
- puts event.channel
- $bot.add_channel(event.message)
-end
-# IRCEvent.add_callback('join') { |event|
-# bot.send_message(event.channel, "Hello #{event.from}")
-IRCEvent.add_callback('privmsg') {|event|
- if event.channel.eql?(BotNick)
- begin
- if (event.message.start_with?(".invite"))
- begin
- event.message.slice! ".invite "
- $bot.add_channel(event.message)
- end
- else
- $bot.send_message(event.from, "I'm thinking...")
- sender.SendReq(event.from, event.message, '')
- end
- end
- else
- if (event.message.start_with?("h2o"))
- Push(event.channel, 'Im')
- Send()
- # IRCConnection.output_push("PRIVMSG #{event.channel} : moz")
- $bot.send_message(event.channel, "#{event.from}, I'm thinking...")
- sender.SendReq(event.channel, event.message, '')
- end
- end
-
-}
-
-# }
-
-$bot.connect
-
-
-$irc.heard_msg(:if => {:pm? => true}) do |e|
- puts(e.nick)
- sender.async.Wait(e.nick)
- sender.async.SendReq(e.nick, e.message, $irc)
- puts('e')
-end
-
-$irc.heard_msg(:if => {:pm? => false}) do |e|
- if (e.message.start_with?("h2o"))
- puts(e.channel)
- sender.async.Wait(e.channel)
- sender.async.SendReq(e.channel, e.message, $irc)
- puts('e')
- end
-end
-
-#$irc.start_listening!
-
-futures = []
-
-
-
-3.times do |i|
- futures << Concurrent::Future.execute(executor: executor) do
-
- end
-end
-
-futures.each(&:wait)
-executor.shutdown
-