wm: irc-h2o-bot

Download patch

ref: fba8902621f2de389bb3af4aa55e3c0cc87e5871
parent: 5dd90f003508a4d47a4cc3880600f3164b19b336
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Tue Jul 11 18:23:32 EDT 2023

First Version of Working Bot

diff: cannot open a/.github/workflows//null: file does not exist: 'a/.github/workflows//null' diff: cannot open a/.github//null: file does not exist: 'a/.github//null' diff: cannot open b/.github0/workflows//null: file does not exist: 'b/.github0/workflows//null' diff: cannot open b/.github0//null: file does not exist: 'b/.github0//null'
--- a/.github/workflows/ruby.yml
+++ /dev/null
@@ -1,32 +1,0 @@
-
-name: Ruby
-
-on:
-  push:
-    branches: [ "master" ]
-  pull_request:
-    branches: [ "master" ]
-
-permissions:
-  contents: read
-
-jobs:
-  test:
-
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        ruby-version: ['2.6', '2.7', '3.0']
-
-    steps:
-      - uses: actions/checkout@v3
-      - name: Set up Ruby
-        # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
-        # change this to (see https://github.com/ruby/setup-ruby#versioning):
-        # uses: ruby/setup-ruby@v1
-        uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
-        with:
-          ruby-version: ${{ matrix.ruby-version }}
-          bundler-cache: true # runs 'bundle install' and caches installed gems automatically
-      - name: Run tests
-        run: ruby -r test.rb
\ No newline at end of file
--- /dev/null
+++ b/.github0/workflows/ruby.yml
@@ -1,0 +1,32 @@
+
+name: Ruby
+
+on:
+  push:
+    branches: [ "master" ]
+  pull_request:
+    branches: [ "master" ]
+
+permissions:
+  contents: read
+
+jobs:
+  test:
+
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        ruby-version: ['2.6', '2.7', '3.0']
+
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up Ruby
+        # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
+        # change this to (see https://github.com/ruby/setup-ruby#versioning):
+        # uses: ruby/setup-ruby@v1
+        uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
+        with:
+          ruby-version: ${{ matrix.ruby-version }}
+          bundler-cache: true # runs 'bundle install' and caches installed gems automatically
+      - name: Run tests
+        run: ruby -r test.rb
\ No newline at end of file
--- a/Test_HTTP.rb
+++ b/Test_HTTP.rb
@@ -2,6 +2,14 @@
 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
@@ -34,32 +42,3 @@
   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_Multi_Threading.rb
+++ b/Test_Multi_Threading.rb
@@ -1,15 +1,39 @@
+require 'thread'
 
+# 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..5 do
-    puts i;
-    # sleep(0.5)
+  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
\ No newline at end of file
+t2.join
+
--- a/test.rb
+++ b/test.rb
@@ -1,44 +1,108 @@
 require 'rubygems'
 require 'net/yail'
+require 'net/http'
+require 'uri'
+require 'json'
 
-irc = Net::YAIL.new(
+
+$irc = Net::YAIL.new(
   :address    => 'irc.ircnow.org',
   :username   => 'Moz_Bot',
   :realname   => 'Moz_Mozak',
-  :nicknames  => ['bot1']
+  :nicknames  => ['h2o-bot0']
 )
 
-# Register a proc callback
-irc.on_welcome proc { |event| irc.join('#fpc') }
 
-# Register a block
-irc.on_invite { |event| irc.join(event.channel) }
+$irc.on_welcome proc { |event| $irc.join('#fpc') }
 
-# Another way to register a block - note that this clobbers the prior callback
-irc.set_callback(:incoming_invite) { |event| irc.join(event.channel) }
 
-# Filter for all incoming pings so we can log them
-irc.hearing_ping {|event| $stderr.puts event.inspect}
+$irc.on_invite { |event| $irc.join(event.channel) }
 
-# Filter condition: if the message is a pm, ignore it by forcibly ending the event filter chain
-irc.hearing_message(:if => {:pm? => true}) do |event|
+$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
 
-def Send(x)
-  for i in 1..10 do
-    x.msg('#fpc', i)
-    sleep(1);
+$irc.on_invite     { |e| $irc.join(e.channel) }
+
+#:if => {:message => "bah"}
+
+def SendReq(peer, input, c)
+  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":"'+ 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 = 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
-end
 
-irc.heard_msg(:if => {:message => "bah"}) do
+  b = ''
+  parsed_json_objects.each do |json_obj|
+    result = json_obj['token']['text']
+    if result == '<|endoftext|>' then
+      break
+    elsif result.include?("\n")
+      begin
+        c.msg(peer, b)
+        b = ''
+      end
+    elsif (1) then
+      b += result
+    end
+  end
 
-  t = Thread.new{Send(irc)}
+  $irc.msg(peer, b)
+end
 
 
-  #puts "bah dige"
+$irc.heard_msg(:if => {:pm? => true}) do |e|
+  SendReq(e.nick, e.message, $irc)
+end
 
+$irc.heard_msg(:if => {:pm? => false}) do |e|
+  if (e.message.start_with?("h2o"))
+    SendReq(e.channel, e.message, $irc)
+  end
 end
 
-irc.start_listening!
\ No newline at end of file
+
+# $irc.heard_msg() do |e|
+#
+#
+#
+# end
+
+$irc.start_listening!
+#
+# def Tra
+#
+# end
+#
+# threads = []
+# threads << Thread.new { Tra() }
+# threads << Thread.new { Tra() }
+# threads << Thread.new { Tra() }
+#
+# # Wait for all threads to complete
+# threads.each(&:join)