Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Ifiht/Shikigami
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
Ifiht committed Jul 5, 2024
2 parents 6bec0b2 + 31fe4ff commit b083340
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 53 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ source "https://rubygems.org"
#gem "telegram-bot-ruby", "~> 1.0" -- not used right now
gem "solargraph"
gem "beaneater"
gem "discordrb"
gem "discordrb", :git => "https://github.com/Ifiht/discordrb.git", :branch => "main"
gem "net-ping", "~> 1.7", ">= 1.7.8"
gem "jemalloc"
gem "spriggan", :git => "https://github.com/Ifiht/Spriggan", :branch => "main"
gem "redfairy", :git => "https://github.com/Ifiht/RedFairyBook", :branch => "main"
gem "sibyl", :git => "https://github.com/Ifiht/Sibyl", :branch => "main"
gem "listen", "~> 2.0"
gem "httpx"
gem "http"
Expand Down
77 changes: 39 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ GIT
specs:
redfairy (0.1.2)

GIT
remote: https://github.com/Ifiht/Sibyl
revision: 9ce494453d5fc855071b123941fbd5223d56edfb
branch: main
specs:
sibyl (0.0.4)

GIT
remote: https://github.com/Ifiht/Spriggan
revision: 09e4efb4b9eae47d2e4ffeb5008aa5f7364f5a8e
Expand All @@ -13,6 +20,20 @@ GIT
spriggan (0.1.7)
beaneater (~> 1.1, >= 1.1.0)

GIT
remote: https://github.com/Ifiht/discordrb.git
revision: 833aa37af927287cc01097eab303edd10aed2db1
branch: main
specs:
discordrb (3.5.1)
discordrb-webhooks (~> 3.5.0)
ffi (>= 1.9.24)
opus-ruby
rest-client (>= 2.0.0)
websocket-client-simple (>= 0.3.0)
discordrb-webhooks (3.5.0)
rest-client (>= 2.0.0)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -26,18 +47,10 @@ GEM
celluloid (0.16.0)
timers (~> 4.0.0)
diff-lcs (1.5.1)
discordrb (3.5.0)
discordrb-webhooks (~> 3.5.0)
ffi (>= 1.9.24)
opus-ruby
rest-client (>= 2.0.0)
websocket-client-simple (>= 0.3.0)
discordrb-webhooks (3.5.0)
rest-client (>= 2.0.0)
domain_name (0.6.20240107)
e2mmap (0.1.0)
event_emitter (0.2.6)
ffi (1.16.3)
ffi (1.17.0-x86_64-linux-gnu)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
Expand All @@ -50,12 +63,12 @@ GEM
http-form_data (~> 2.2)
llhttp-ffi (~> 0.5.0)
http-accept (1.7.0)
http-cookie (1.0.5)
http-cookie (1.0.6)
domain_name (~> 0.5)
http-form_data (2.3.0)
httpx (1.2.4)
httpx (1.2.5)
http-2-next (>= 1.0.3)
jaro_winkler (1.5.6)
jaro_winkler (1.6.0)
jemalloc (1.0.1)
json (2.7.2)
kramdown (2.4.0)
Expand All @@ -72,48 +85,39 @@ GEM
rake (~> 13.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0507)
mime-types-data (3.2024.0604)
net-ping (1.7.8)
netrc (0.11.0)
nokogiri (1.16.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.4-arm-linux)
racc (~> 1.4)
nokogiri (1.16.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.4-x86-linux)
racc (~> 1.4)
nokogiri (1.16.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.4-x86_64-linux)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
opus-ruby (1.0.1)
ffi
parallel (1.24.0)
parser (3.3.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
pp (0.5.0)
prettyprint
prettyprint (0.2.0)
public_suffix (5.0.5)
racc (1.7.3)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (2.8.4)
regexp_parser (2.9.1)
regexp_parser (2.9.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.6)
rubocop (1.63.5)
rexml (3.2.8)
strscan (>= 3.0.9)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -127,7 +131,7 @@ GEM
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
rufo (0.17.1)
rufo (0.18.0)
solargraph (0.50.0)
backport (~> 1.2)
benchmark
Expand All @@ -144,6 +148,7 @@ GEM
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
strscan (3.1.0)
thor (1.3.1)
tilt (2.3.0)
timers (4.0.4)
Expand All @@ -156,16 +161,11 @@ GEM
yard (0.9.36)

PLATFORMS
aarch64-linux
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux

DEPENDENCIES
beaneater
discordrb
discordrb!
http
httpx
jemalloc
Expand All @@ -175,8 +175,9 @@ DEPENDENCIES
rake
redfairy!
rufo
sibyl!
solargraph
spriggan!

BUNDLED WITH
2.5.6
2.3.27
7 changes: 3 additions & 4 deletions src/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#=============<[ Instance Vars ]>=============#
@cwd = %x(pwd).chomp
@procs = []
@modules1 = []
@modules2 = []
@beanstalk_host = core_config.get("beanstalk_host")
Expand Down Expand Up @@ -46,16 +45,16 @@ def eval_string(str)
}
@sprig.add_thread {
loop do
@modules2 = %x[ ls #{cwd}/src/modules ].split
@modules2 = %x[ ls #{@cwd}/src/modules ].split
if @modules1 != @modules2
@modules1 = @modules2
pm2_proclist = @sprig.pm2_procs
@modules1.each do |m|
if pm2_proclist.include? m
@sprig.pm2_log("Skipping running module: #{m}")
else
if %x[ ls #{cwd}/src/modules/#{m} ].split.include? "wrapper.sh"
%x[ cd #{cwd}/src/modules/#{m} && pm2 start #{cwd}/src/modules/#{m}/wrapper.sh --name #{m}]
if %x[ ls #{@cwd}/src/modules/#{m} ].split.include? "wrapper.sh"
%x[ cd #{@cwd}/src/modules/#{m} && pm2 start #{@cwd}/src/modules/#{m}/wrapper.sh --name #{m}]
@sprig.pm2_log("Starting module: #{m}")
else
@sprig.pm2_log("No wrapper for module: #{m}")
Expand Down
6 changes: 6 additions & 0 deletions src/core.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/env bash

echo "Starting core..."
# The default directory pm2 runs from is the root of the repo,
# so we have to specify the relative path including src/
bundle exec ruby src/core.rb
54 changes: 54 additions & 0 deletions src/modules/chat/chat.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#=============<[ Gems ]>=============#
require "http"
require "json"
require "spriggan"
require "redfairy"

#=============<[ Constants ]>================#
INST = "A chat between a very important human and an artificial intelligence assistant. The assistant gives quick and truthful answers to the human's questions. The assistant's responses are thorough, but succinct."
CHAT = "\n@User: Hello.\n@Wayland: Greetings.\n@User: What do you call yourself?\n@Wayland: Wayland.\n@User: What is the closest star to our sun?\n@Wayland: The closest star to our sun Sol is Alpha Centauri."

#=============<[ Local Vars ]>================#
core_config = RedFairy.new("shikigami")

Expand Down Expand Up @@ -31,6 +37,54 @@ def eval_string(str)
end #begin
end #def

# Parameters passed to llama.cpp running Llama 3
def format_question(prompt)
i = rand(99)
request = {
"stream" => false, # keep false, breaks if true
"seed" => i, # Set the random number generator (RNG) seed.
"n_predict" => 500, # notes
"temperature" => 0.54, # was:0, def:0-1, higher is more creative (0.49 failed to answer question about unicorns)
"stop" => ["\n@User:"], # notes
"repeat_last_n" => 128, # Last n tokens to consider for penalizing repetition. 0 is disabled and -1 is ctx-size.
"repeat_penalty" => 1.1, # Control the repetition of token sequences in the generated text.
"top_k" => 32, # def:40, Limit the next token selection to the K most probable tokens.
"top_p" => 0.9, # def:0.95, higher finds better predictions, but slower
"min_p" => 0.06, # def:0.05, The minimum probability for a token to be considered, relative to the probability of the most likely token.
"tfs_z" => 1, # def:1(disabled) https://www.trentonbricken.com/Tail-Free-Sampling/
"typical_p" => 1, # def:1(disabled)
"presence_penalty" => 0, # def:0(disabled)
"frequency_penalty" => 0, # def:0(disabled)
"mirostat" => 0, # def:0(disabled), 1=Mirostat 1.0, 2=Mirostat 2.0
"mirostat_tau" => 4.0, # Set the Mirostat target entropy, parameter tau.
"mirostat_eta" => 0.1, # Set the Mirostat learning rate, parameter eta.
"prompt" => prompt, # https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md
}
return request
end #def

# HTTP request interface to llama.cpp server
def ask_question(q)
question = format_question(q)
response = HTTP.post("http://localhost:4242/completion", :json => question)
h = JSON.parse(response.body)
return h["content"]
end #def

# Discord chat logic to receive msg and send response
def respond(e)
@sprig.pm2_log("Received msg: #{e.message.content}")
msg_body = e.message.content.gsub("<@1211423563475849236>", "Wayland").gsub("<@&1211432785353637999>", "Wayland").to_s
e.channel.start_typing
a = ask_question(INST + CHAT + "\n@User: " + msg_body + "\n@Wayland:")
@sprig.pm2_log("Sending msg: #{a}")
if a.include? "@Wayland:"
e.respond a.gsub("@Wayland:", "").to_s
else
e.respond a.to_s
end #if
end #def

#============================================#
#+++----- <[ Main Body ]> -----+++#
#============================================#
Expand Down
12 changes: 7 additions & 5 deletions src/modules/database/init.example.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ CREATE TABLE Personas(
);

CREATE TABLE Conversations(
ConvoID INTEGER NOT NULL PRIMARY KEY,
PersonID INTEGER NOT NULL,
BodyText TEXT,
TimeStamp TEXT DEFAULT CURRENT_TIMESTAMP,
Reactions TEXT,
ConversationID INTEGER NOT NULL PRIMARY KEY,
PersonID INTEGER NOT NULL,
Location TEXT,
Participants TEXT,
BodyText TEXT,
TimeStamp TEXT DEFAULT CURRENT_TIMESTAMP,
Reactions TEXT,
FOREIGN KEY(PersonID) REFERENCES Personas(PersonID)
);

Expand Down
11 changes: 7 additions & 4 deletions src/modules/discord/discord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def ask_question(q)

# Discord chat logic to receive msg and send response
def respond(e)
@sprig.pm2_log("Received msg: #{e.message.content}")
#@sprig.pm2_log("Received msg: #{e.message.content}")
msg_body = e.message.content.gsub("<@1211423563475849236>", "Wayland").gsub("<@&1211432785353637999>", "Wayland").to_s
e.channel.start_typing
a = ask_question(INST + CHAT + "\n@User: " + msg_body + "\n@Wayland:")
Expand Down Expand Up @@ -99,10 +99,13 @@ def respond(e)
}
@sprig.add_thread {
bot = Discordrb::Bot.new token: @discord_token
bot.message(starting_with: "<@1211423563475849236>") do |event|
respond(event)
#bot.message(starting_with: "<@1211423563475849236>") do |event|
#bot.message(starting_with: "<@&1211432785353637999>") do |event|
bot.message do |event|
@sprig.pm2_log("Received message #{event.message}")
end
bot.message(starting_with: "<@&1211432785353637999>") do |event|
bot.mention do |event|
@sprig.pm2_log("Responding to event")
respond(event)
end
at_exit { bot.stop }
Expand Down
2 changes: 1 addition & 1 deletion src/modules/habitica/habitica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "redfairy"
require "spriggan"
#==========<[ Local Libs ]>==========#
require_relative "lib_habitica"
require "./lib_habitica"

#=============<[ Local Vars ]>================#
core_config = RedFairy.new("shikigami")
Expand Down

0 comments on commit b083340

Please sign in to comment.