Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created January 12, 2025 01:37
Show Gist options
  • Save cablehead/368e4f664a80059565de3dbfb64c9c51 to your computer and use it in GitHub Desktop.
Save cablehead/368e4f664a80059565de3dbfb64c9c51 to your computer and use it in GitHub Desktop.
# $env.OPENAI_API_KEY = (.head OPENAI_API_KEY | .cas $in.hash | str trim)
# $env.GPT2099_PROVIDER = { name: openai model: "gpt-4o-2024-11-20" }
$env.CEREBRAS_API_KEY = (.head CEREBRAS_API_KEY | .cas $in.hash | str trim)
$env.GPT2099_PROVIDER = { name: "cerebras" model: "llama-3.3-70b" }
$env.GPT2099_INTERACTIVE = false
$env.BOT_TOKEN = .head discord.ws.token | .cas $in.hash
def prompt-assets [] {
{
role: "system"
content: (.head assets | .cas $in.hash)
}
}
def prompt-channel-activity [frame] {
{
role: "system"
content: "You are a discord bot called @stacks-bot. You have just received an @ mention. These are the most recent messages in this channel:"
} | append (
.cat | where topic == "discord.message" and meta.channel_id == $frame.meta.channel_id | each {|x|
{
role: (if $x.meta.author.username == "stacks-bot" {"assistant"} else {"user"})
content: ({ content: (.cas $x.hash) meta: $in.meta } | to json -r)
}
}
)
}
def prompt-system [] {
.cat | where topic == "system-prompt" | each {
{
role: "system"
content: (.cas $in.hash)
}
}
}
def prompt [frame] {
prompt-assets | append (prompt-channel-activity $frame) | append (prompt-system)
}
{
modules: {
gpt2099: (.head gpt2099.nu | .cas $in.hash)
discord: (.head discord.nu | .cas $in.hash)
}
process: {|frame|
if $frame.topic != "discord.message" { return }
if "stacks-bot" not-in ($frame.meta.mentions | get username) { return }
prompt $frame | gpt2099 call | {
content: $in
message_reference: {
message_id: $frame.meta.id
}
} | discord channel message create $frame.meta.channel_id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment