ran pre-commit and fixed issues

This commit is contained in:
Yannic Kilcher
2022-12-13 12:38:59 +01:00
parent ceda5481b9
commit d3d657e636
43 changed files with 213 additions and 154 deletions
+3
View File
@@ -1,11 +1,14 @@
# open-chat-gpt
This is the github repo for the open-chat-gpt project.
We are currently building a discord bot in order to make everyone contribute with great prompts and answers.
Join us!
https://discord.gg/ZUfPw6jP
## Project description
We are calling the community for help to collect ChatGPT-like Instruction-Fulfillment datasamples via Discord. People can post Instructions they think would make sense for ChatGPT-like systems & also provide a good reference answer for it.
## Todo
Figure out ouath flow for the app to work inside the open-chat-gpt testing channel here. https://discord.gg/JJSKtRhv
+14 -15
View File
@@ -1,13 +1,15 @@
bot_url = "https://discord.com/api/oauth2/authorize?client_id=1051614245940375683&permissions=8&scope=bot"
# -*- coding: utf-8 -*-
import discord
import json
import os
import requests
import discord
import requests
from discord import app_commands
from dotenv import load_dotenv
bot_url = "https://discord.com/api/oauth2/authorize?client_id=1051614245940375683&permissions=8&scope=bot"
# Load up all the important environment variables.
load_dotenv()
@@ -25,6 +27,7 @@ headers = {"X-API-Key": API_SERVER_KEY}
# For testing only.
TEST_GUILD = os.getenv("TEST_GUILD")
# Initiate the client and command tree to create slash commands.
class OpenChatGPTClient(discord.Client):
def __init__(self, *, intents: discord.Intents):
@@ -40,7 +43,7 @@ class OpenChatGPTClient(discord.Client):
await self.tree.sync(guild=guild)
else:
# This can take up to an hour for the commands to be registered.
await tree.sync()
await self.tree.sync()
print("Ready!")
@@ -63,7 +66,7 @@ async def register(interaction: discord.Interaction):
await interaction.response.send_message(f"Added you {interaction.user.name}")
else:
print(response)
await interaction.response.send_message(f"Failed to add you")
await interaction.response.send_message("Failed to add you")
@client.tree.command()
@@ -74,13 +77,11 @@ async def list_participants(interaction: discord.Interaction):
names = ",".join([labeler["display_name"] for labeler in response.json()])
await interaction.response.send_message(f"Found these users: {names}")
else:
await interaction.response.send_message(f"Failed to fetch participants")
await interaction.response.send_message("Failed to fetch participants")
@client.tree.command()
async def add_prompt(
interaction: discord.Interaction, prompt: str, response: str, language: str = "en"
):
async def add_prompt(interaction: discord.Interaction, prompt: str, response: str, language: str = "en"):
"""Uploads a single prompt to the server."""
prompt = {
"discord_username": f"{interaction.user.id}",
@@ -91,15 +92,13 @@ async def add_prompt(
}
response = requests.post(prompts_url, headers=headers, json=prompt)
if response.status_code == 200:
await interaction.response.send_message(f"Added your prompt")
await interaction.response.send_message("Added your prompt")
else:
await interaction.response.send_message(f"Failed to add the prompt")
await interaction.response.send_message("Failed to add the prompt")
@client.tree.command()
async def add_prompts_set(
interaction: discord.Interaction, prompts: discord.Attachment
):
async def add_prompts_set(interaction: discord.Interaction, prompts: discord.Attachment):
"""Uploads a batch of prompts to the server."""
# Loading a bunch of prompts from a file can take a while. So first defer
# the response to ensure we're able to later tell the user what happened.
@@ -122,7 +121,7 @@ async def add_prompts_set(
}
response = requests.post(prompts_url, headers=headers, json=prompt)
if response.status_code != 200:
await interaction.followup.send(f"Failed to upload")
await interaction.followup.send("Failed to upload")
return
count += 1
await interaction.followup.send(f"Loaded up {count} prompts")
+3 -8
View File
@@ -1,6 +1,5 @@
from setuptools import setup, find_packages
from pathlib import Path
import os
# -*- coding: utf-8 -*-
from setuptools import find_packages, setup
if __name__ == "__main__":
import os
@@ -8,11 +7,7 @@ if __name__ == "__main__":
def _read_reqs(relpath):
fullpath = os.path.join(os.path.dirname(__file__), relpath)
with open(fullpath) as f:
return [
s.strip()
for s in f.readlines()
if (s.strip() and not s.startswith("#"))
]
return [s.strip() for s in f.readlines() if (s.strip() and not s.startswith("#"))]
REQUIREMENTS = _read_reqs("requirements.txt")