text stringlengths 0 93.6k |
|---|
def construct_response(raw_response: str, user_id: str, question: str) -> str: |
"""Wraps the backend's response in a nice message for Discord.""" |
rating_emojis = { |
"👍": "if the response was helpful", |
"👎": "if the response was not helpful", |
} |
emoji_reaction_text = " or ".join( |
f"react with {emoji} {reason}" for emoji, reason in rating_emojis.items() |
) |
emoji_reaction_text = emoji_reaction_text.capitalize() + "." |
response = f"""<@{user_id}> asked: _{question}_ |
Here's my best guess at an answer, with sources so you can follow up: |
{raw_response} |
Emoji react to let us know how we're doing! |
{emoji_reaction_text} |
""" |
return response |
def construct_error_message(user_id: str) -> str: |
import os |
error_message = ( |
f"*Sorry <@{user_id}>, an error occured while answering your question." |
) |
if os.getenv("DISCORD_MAINTAINER_ID"): |
error_message += f" I've let <@{os.getenv('DISCORD_MAINTAINER_ID')}> know." |
else: |
pretty_log("No maintainer ID set") |
error_message += " Please try again later." |
error_message += "*" |
return error_message |
@stub.function() |
def create_slash_command(force: bool = False): |
"""Registers the slash command with Discord. Pass the force flag to re-register.""" |
import os |
import requests |
BOT_TOKEN = os.getenv("DISCORD_AUTH") |
CLIENT_ID = os.getenv("DISCORD_CLIENT_ID") |
headers = { |
"Content-Type": "application/json", |
"Authorization": f"Bot {BOT_TOKEN}", |
} |
url = f"https://discord.com/api/v10/applications/{CLIENT_ID}/commands" |
command_description = { |
"name": "ask", |
"description": "Ask a question about anything covered by Full Stack", |
"options": [ |
{ |
"name": "question", |
"description": "A question about LLMs, building AI applications, etc.", |
"type": DiscordApplicationCommandOptionType.STRING.value, |
"required": True, |
"max_length": 200, |
} |
], |
} |
# first, check if the command already exists |
response = requests.get(url, headers=headers) |
try: |
response.raise_for_status() |
except Exception as e: |
raise Exception("Failed to create slash command") from e |
commands = response.json() |
command_exists = any(command.get("name") == "ask" for command in commands) |
# and only recreate it if the force flag is set |
if command_exists and not force: |
return |
response = requests.post(url, headers=headers, json=command_description) |
try: |
response.raise_for_status() |
except Exception as e: |
raise Exception("Failed to create slash command") from e |
# <FILESEP> |
#!/usr/bin/env python3 |
""" |
fritzbox_helper - A munin plugin for Linux to monitor AVM Fritzbox |
Copyright (C) 2015 Christian Stade-Schuldt |
Author: Christian Stade-Schuldt |
Like Munin, this plugin is licensed under the GNU GPL v2 license |
http://www.opensource.org/licenses/GPL-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.