Skip to content

Commit

Permalink
discord live test-001
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifiht committed Apr 20, 2024
1 parent 41135ab commit 7486e64
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/modules/chat/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require_rel "../../lib/app_settings"
require_rel "../../lib/shiki_stdlib"

shiki = Shiki.new("chat")
sgram = ShikiGram.new
core_config = AppSettings.new
beanstalk_host = core_config.get("beanstalk_host")
beanstalk_port = core_config.get("beanstalk_port")
Expand Down Expand Up @@ -64,6 +64,9 @@ def ask_question(str)
log_to_pm2("Received job: #{str}")
begin
a = ask_question(str)
response = sgram.wrap_msg(a)
beansource = bstalk.tubes["discord"]
beansource.put response
rescue Exception => e
log_to_pm2("Rescued job: #{e}")
end
Expand Down
47 changes: 41 additions & 6 deletions src/modules/discord/discord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
bstalk.tubes.find("discord") # also creates the tube
bstalk.tubes.watch!("discord")

@bot = Discordrb::Bot.new token: discord_token

def log_to_pm2(message)
$stdout.puts message
$stdout.flush
Expand All @@ -33,6 +35,39 @@ def eval_string(str)
end #begin
end #def

def format_question(prompt)
request = {
"stream"=> false,
"n_predict"=> 400,
"temperature"=> 0,
"stop"=> [
"</s>",
],
"repeat_last_n"=> 256,
"repeat_penalty"=> 1,
"top_k"=> 20,
"top_p"=> 0.75,
"tfs_z"=> 1,
"typical_p"=> 1,
"presence_penalty"=> 0,
"frequency_penalty"=> 0,
"mirostat"=> 0,
"mirostat_tau"=> 5,
"mirostat_eta"=> 0.1,
"grammar"=> "",
"n_probs"=> 0,
"prompt"=> prompt
}
return request.to_json
end #def

def ask_question(str)
question = format_question(str)
response = HTTP.post("http://localhost:4242/completion", :json => question)
h = JSON.parse(response.body)
return h["content"]
end #def

core_threads << Thread.new {
loop do
job = bstalk.tubes.reserve
Expand All @@ -51,15 +86,15 @@ def eval_string(str)
}
# join url: https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=274878155840
core_threads << Thread.new {
bot = Discordrb::Bot.new token: discord_token
bot.message(starting_with: "<@1211423563475849236>") do |event|
event.respond "What's up?"
@bot.message(starting_with: "<@1211423563475849236>") do |event|
a = ask_question(str)
event.respond a
end
bot.message() do |event|
@bot.message() do |event|
puts event.inspect
end
at_exit { bot.stop }
bot.run
at_exit { @bot.stop }
@bot.run
}

#[[[[[[ CATCH INTERRUPT ]]]]]]
Expand Down

0 comments on commit 7486e64

Please sign in to comment.