diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3cf95722..90279415 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,10 +11,8 @@ repos: - id: check-ast - id: check-yaml - id: check-json - - id: pretty-format-json - id: check-case-conflict - id: detect-private-key - - id: detect-aws-credentials - id: fix-encoding-pragma - id: forbid-submodules - id: mixed-line-ending diff --git a/.python-version b/.python-version index 5c3c83b3..36435ac6 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.10.8 \ No newline at end of file +3.10.8 diff --git a/README.md b/README.md index 964cad8a..f9bce6a1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Open-Chat-GPT + Open chat gpt is a project meant to give everyone access to a great chat based large language model. We believe that by doing this we will create a revolution in innovation in language. In the same way that stable-diffusion helped the world make art and images in new ways we hope open chat gpt can help improve the world by improving language itself. @@ -15,19 +16,26 @@ We live and collaborate the work in the LAION discord. Join us! ## How do I start helping out? -Check out these pages to learn more about the project. +Check out these pages to learn more about the project. Ping Birger on discord if you want help to get started. http://**discordapp.com/users/birger#6875** ## More information in the notion + https://roan-iguanadon-a58.notion.site/Open-Chat-Gpt-83dd217eeeb84907a155b8a9d716fa46 ## Code structure -## Bot +### Pre-commit + +Run `pre-commit install` to install the pre-commit hooks. + +### Bot + We have a folder named bot where code related to the bot lives. -## Backend +### Backend + We have a backend folder for backend development of the api that the discord bot sends it information to. diff --git a/backend/README.md b/backend/README.md index e35fb467..e619376c 100644 --- a/backend/README.md +++ b/backend/README.md @@ -4,7 +4,6 @@ Please edit `alembic.ini` and specify your database uri in the parameter `sqlalchemy.url`. - ## REST Server Configuration Please either use environment variables or create a `.env` file in the backend root directory (in which this readme file is located) to specify the `DATABASE_URI`. @@ -15,4 +14,4 @@ Example contents of a `.env` file for the backend: DATABASE_URI="postgresql://:@/" BACKEND_CORS_ORIGINS=["http://localhost", "http://localhost:4200", "http://localhost:3000", "http://localhost:8080", "https://localhost", "https://localhost:4200", "https://localhost:3000", "https://localhost:8080", "http://dev.ocgpt.laion.ai", "https://stag.ocgpt.laion.ai", "https://ocgpt.laion.ai"] -``` \ No newline at end of file +``` diff --git a/backend/alemic/README b/backend/alemic/README index 98e4f9c4..2500aa1b 100644 --- a/backend/alemic/README +++ b/backend/alemic/README @@ -1 +1 @@ -Generic single-database configuration. \ No newline at end of file +Generic single-database configuration. diff --git a/backend/alemic/env.py b/backend/alemic/env.py index 6626bfd0..af7461d5 100644 --- a/backend/alemic/env.py +++ b/backend/alemic/env.py @@ -1,9 +1,8 @@ +# -*- coding: utf-8 -*- from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool - from alembic import context +from sqlalchemy import engine_from_config, pool # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -64,9 +63,7 @@ def run_migrations_online() -> None: ) with connectable.connect() as connection: - context.configure( - connection=connection, target_metadata=target_metadata - ) + context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations() diff --git a/backend/alemic/versions/23e5fea252dd_first_revision.py b/backend/alemic/versions/23e5fea252dd_first_revision.py index 7e51e72a..87709d31 100644 --- a/backend/alemic/versions/23e5fea252dd_first_revision.py +++ b/backend/alemic/versions/23e5fea252dd_first_revision.py @@ -1,16 +1,16 @@ +# -*- coding: utf-8 -*- """first revision Revision ID: 23e5fea252dd -Revises: +Revises: Create Date: 2022-12-12 12:47:28.801354 """ -from alembic import op import sqlalchemy as sa - +from alembic import op # revision identifiers, used by Alembic. -revision = '23e5fea252dd' +revision = "23e5fea252dd" down_revision = None branch_labels = None depends_on = None @@ -23,25 +23,29 @@ def upgrade() -> None: sa.Column("name", sa.String(200), nullable=False), sa.Column("service_admin_email", sa.String(128), nullable=True), sa.Column("api_key", sa.String(300), nullable=False), - sa.Column("can_append", sa.Boolean, nullable=False, server_default='true'), - sa.Column("can_write", sa.Boolean, nullable=False, server_default='false'), - sa.Column("can_delete", sa.Boolean, nullable=False, server_default='false'), - sa.Column("can_read", sa.Boolean, nullable=False, server_default='true'), + sa.Column("can_append", sa.Boolean, nullable=False, server_default="true"), + sa.Column("can_write", sa.Boolean, nullable=False, server_default="false"), + sa.Column("can_delete", sa.Boolean, nullable=False, server_default="false"), + sa.Column("can_read", sa.Boolean, nullable=False, server_default="true"), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_service_client_api_key"), "service_client", ["api_key"], unique=True) - op.create_table( "labeler", sa.Column("id", sa.Integer, sa.Identity()), sa.Column("display_name", sa.String(96), nullable=False), sa.Column("discord_username", sa.String(96), nullable=True), - sa.Column("created_date", sa.DateTime, nullable=False, server_default=sa.func.current_timestamp()), - sa.Column("is_enabled", sa.Boolean, nullable=False, server_default='true'), - sa.Column("notes", sa.String(10*1024), nullable=True), + sa.Column( + "created_date", + sa.DateTime, + nullable=False, + server_default=sa.func.current_timestamp(), + ), + sa.Column("is_enabled", sa.Boolean, nullable=False, server_default="true"), + sa.Column("notes", sa.String(10 * 1024), nullable=True), sa.PrimaryKeyConstraint("id"), - sa.UniqueConstraint("discord_username") + sa.UniqueConstraint("discord_username"), ) op.create_table( @@ -51,8 +55,16 @@ def upgrade() -> None: sa.Column("prompt", sa.Text, nullable=False), sa.Column("response", sa.Text, nullable=True), sa.Column("lang", sa.String(32), nullable=True), - sa.Column("created_date", sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()), - sa.ForeignKeyConstraint(["labeler_id"], ["labeler.id"],), + sa.Column( + "created_date", + sa.DateTime(), + nullable=False, + server_default=sa.func.current_timestamp(), + ), + sa.ForeignKeyConstraint( + ["labeler_id"], + ["labeler.id"], + ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("prompt_labeler_id"), "prompt", ["labeler_id"], unique=False) diff --git a/backend/app/api/deps.py b/backend/app/api/deps.py index ba805075..deed0a3d 100644 --- a/backend/app/api/deps.py +++ b/backend/app/api/deps.py @@ -1,10 +1,11 @@ +# -*- coding: utf-8 -*- from typing import Generator -from sqlmodel import Session -from fastapi import Security, HTTPException -from fastapi.security.api_key import APIKeyQuery, APIKeyHeader, APIKey + from app.database import engine from app.models import ServiceClient - +from fastapi import HTTPException, Security +from fastapi.security.api_key import APIKey, APIKeyHeader, APIKeyQuery +from sqlmodel import Session from starlette.status import HTTP_403_FORBIDDEN @@ -28,16 +29,21 @@ async def get_api_key( def api_auth( - api_key: APIKey, db: Session, create: bool = False, read: bool = True, update: bool = False, delete: bool = False + api_key: APIKey, + db: Session, + create: bool = False, + read: bool = True, + update: bool = False, + delete: bool = False, ) -> ServiceClient: if api_key is not None: api_client = db.query(ServiceClient).filter(ServiceClient.api_key == api_key).first() if api_client is not None: if ( - (create == False or api_client.can_append) - and (read == False or api_client.can_read) - and (update == False or api_client.can_write) - and (delete == False or api_client.can_delete) + (create is False or api_client.can_append) + and (read is False or api_client.can_read) + and (update is False or api_client.can_write) + and (delete is False or api_client.can_delete) ): return api_client diff --git a/backend/app/api/v1/api.py b/backend/app/api/v1/api.py index 59cdd6c7..7c97c9cb 100644 --- a/backend/app/api/v1/api.py +++ b/backend/app/api/v1/api.py @@ -1,6 +1,6 @@ -from fastapi import APIRouter - +# -*- coding: utf-8 -*- from app.api.v1 import labelers, prompts +from fastapi import APIRouter api_router = APIRouter() api_router.include_router(labelers.router, prefix="/labelers", tags=["labelers"]) diff --git a/backend/app/api/v1/labelers.py b/backend/app/api/v1/labelers.py index 8161c3b4..c2a89181 100644 --- a/backend/app/api/v1/labelers.py +++ b/backend/app/api/v1/labelers.py @@ -1,13 +1,12 @@ +# -*- coding: utf-8 -*- from typing import Any, List -from fastapi import APIRouter, Depends, HTTPException -from fastapi.security.api_key import APIKey -from sqlmodel import Session -from starlette.status import HTTP_404_NOT_FOUND, HTTP_400_BAD_REQUEST - from app import crud, schemas from app.api import deps - +from fastapi import APIRouter, Depends, HTTPException +from fastapi.security.api_key import APIKey +from sqlmodel import Session +from starlette.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND router = APIRouter() diff --git a/backend/app/api/v1/prompts.py b/backend/app/api/v1/prompts.py index b7848229..b9cf2ce7 100644 --- a/backend/app/api/v1/prompts.py +++ b/backend/app/api/v1/prompts.py @@ -1,13 +1,12 @@ +# -*- coding: utf-8 -*- from typing import Any, List -from fastapi import APIRouter, Depends, HTTPException -from fastapi.security.api_key import APIKey -from sqlmodel import Session -from starlette.status import HTTP_404_NOT_FOUND, HTTP_400_BAD_REQUEST, HTTP_401_UNAUTHORIZED - from app import crud, schemas from app.api import deps - +from fastapi import APIRouter, Depends, HTTPException +from fastapi.security.api_key import APIKey +from sqlmodel import Session +from starlette.status import HTTP_400_BAD_REQUEST, HTTP_401_UNAUTHORIZED, HTTP_404_NOT_FOUND router = APIRouter() @@ -50,7 +49,7 @@ def create_prompt( raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="Invalid labeler user name") if not labeler.is_enabled: raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Labeler disabled") - + item_in.labeler_id = labeler.id item_in.discord_username = None item = crud.prompt.create(db=db, obj_in=item_in) diff --git a/backend/app/config.py b/backend/app/config.py index 895dbb00..06918435 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -1,4 +1,6 @@ +# -*- coding: utf-8 -*- from typing import List, Optional, Union + from pydantic import AnyHttpUrl, BaseSettings, PostgresDsn, validator diff --git a/backend/app/crud/__init__.py b/backend/app/crud/__init__.py index 00548245..50c02e61 100644 --- a/backend/app/crud/__init__.py +++ b/backend/app/crud/__init__.py @@ -1,2 +1,5 @@ +# -*- coding: utf-8 -*- from .crud_labeler import labeler -from .crud_prompt import prompt \ No newline at end of file +from .crud_prompt import prompt + +__all__ = ["labeler", "prompt"] diff --git a/backend/app/crud/base.py b/backend/app/crud/base.py index 927359d2..d863c4bc 100644 --- a/backend/app/crud/base.py +++ b/backend/app/crud/base.py @@ -1,10 +1,10 @@ +# -*- coding: utf-8 -*- from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from sqlmodel import Session, SQLModel - ModelType = TypeVar("ModelType", bound=SQLModel) CreateSchemaType = TypeVar("CreateSchemaType", bound=BaseModel) UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel) @@ -25,9 +25,7 @@ class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): def get(self, db: Session, id: Any) -> Optional[ModelType]: return db.query(self.model).filter(self.model.id == id).first() - def get_multi( - self, db: Session, *, begin_id: int = 0, limit: int = 100 - ) -> List[ModelType]: + def get_multi(self, db: Session, *, begin_id: int = 0, limit: int = 100) -> List[ModelType]: return db.query(self.model).filter(self.model.id >= begin_id).limit(limit).all() def create(self, db: Session, *, obj_in: CreateSchemaType) -> ModelType: @@ -38,13 +36,7 @@ class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): db.refresh(db_obj) return db_obj - def update( - self, - db: Session, - *, - db_obj: ModelType, - obj_in: Union[UpdateSchemaType, Dict[str, Any]] - ) -> ModelType: + def update(self, db: Session, *, db_obj: ModelType, obj_in: Union[UpdateSchemaType, Dict[str, Any]]) -> ModelType: obj_data = jsonable_encoder(db_obj) if isinstance(obj_in, dict): update_data = obj_in diff --git a/backend/app/crud/crud_labeler.py b/backend/app/crud/crud_labeler.py index a47aee34..0c388feb 100644 --- a/backend/app/crud/crud_labeler.py +++ b/backend/app/crud/crud_labeler.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from typing import Optional from app.crud.base import CRUDBase diff --git a/backend/app/crud/crud_prompt.py b/backend/app/crud/crud_prompt.py index 7288b82c..cf625084 100644 --- a/backend/app/crud/crud_prompt.py +++ b/backend/app/crud/crud_prompt.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from app.crud.base import CRUDBase from app.models.prompt import Prompt from app.schemas.prompt import PromptCreate diff --git a/backend/app/database.py b/backend/app/database.py index c9562b13..5191e8c2 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -1,4 +1,5 @@ -from sqlmodel import create_engine +# -*- coding: utf-8 -*- from app.config import settings +from sqlmodel import create_engine engine = create_engine(settings.DATABASE_URI) diff --git a/backend/app/db_test.py b/backend/app/db_test.py index f6d5a374..1a9346dc 100644 --- a/backend/app/db_test.py +++ b/backend/app/db_test.py @@ -1,16 +1,15 @@ -import dataclasses -from datetime import datetime -import json -from typing import Optional +# -*- coding: utf-8 -*- +# flake8: noqa import argparse +import dataclasses +import json from dataclasses import dataclass - - -from sqlmodel import Session, SQLModel, create_engine -from app.config import settings +from datetime import datetime +from typing import Optional import app.api.deps - +from app.config import settings +from sqlmodel import Session, SQLModel, create_engine def main(): @@ -24,14 +23,14 @@ def main(): app.api.deps.engine = engine """ - with Session(engine) as session: + with Session(engine) as session: # create a test serivice #sc1 = ServiceClient(name='blub', api_key='1234') #session.add(sc1) session.commit() """ - -if __name__ == '__main__': + +if __name__ == "__main__": main() diff --git a/backend/app/main.py b/backend/app/main.py index 343e142a..3cf36425 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,12 +1,10 @@ +# -*- coding: utf-8 -*- +from app.api.v1.api import api_router +from app.config import settings from fastapi import FastAPI from starlette.middleware.cors import CORSMiddleware -from app.api.v1.api import api_router -from app.config import settings - -app = FastAPI( - title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json" -) +app = FastAPI(title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json") # Set all CORS enabled origins if settings.BACKEND_CORS_ORIGINS: diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py index e54a9211..f12c41f3 100644 --- a/backend/app/models/__init__.py +++ b/backend/app/models/__init__.py @@ -1,3 +1,6 @@ -from .service_client import ServiceClient +# -*- coding: utf-8 -*- from .labeler import Labeler from .prompt import Prompt +from .service_client import ServiceClient + +__all__ = ["Labeler", "Prompt", "ServiceClient"] diff --git a/backend/app/models/labeler.py b/backend/app/models/labeler.py index bfef9232..9dd775b1 100644 --- a/backend/app/models/labeler.py +++ b/backend/app/models/labeler.py @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- from datetime import datetime +from typing import Optional + import sqlalchemy as sa from sqlmodel import Field, SQLModel -from typing import Optional class Labeler(SQLModel, table=True): @@ -9,6 +11,9 @@ class Labeler(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) display_name: str discord_username: str - created_date: Optional[datetime] = Field(sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()), nullable=False) + created_date: Optional[datetime] = Field( + sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()), + nullable=False, + ) is_enabled: bool notes: str diff --git a/backend/app/models/prompt.py b/backend/app/models/prompt.py index fdb3a002..71ec956a 100644 --- a/backend/app/models/prompt.py +++ b/backend/app/models/prompt.py @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- from datetime import datetime +from typing import Optional + import sqlalchemy as sa from sqlmodel import Field, SQLModel -from typing import Optional class Prompt(SQLModel, table=True): @@ -11,5 +13,7 @@ class Prompt(SQLModel, table=True): prompt: str response: Optional[str] lang: Optional[str] - created_date: Optional[datetime] = Field(sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()), nullable=False) - \ No newline at end of file + created_date: Optional[datetime] = Field( + sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()), + nullable=False, + ) diff --git a/backend/app/models/service_client.py b/backend/app/models/service_client.py index 54960636..f7b8295a 100644 --- a/backend/app/models/service_client.py +++ b/backend/app/models/service_client.py @@ -1,6 +1,8 @@ -from sqlmodel import Field, SQLModel +# -*- coding: utf-8 -*- from typing import Optional +from sqlmodel import Field, SQLModel + class ServiceClient(SQLModel, table=True): __tablename__ = "service_client" diff --git a/backend/app/schemas/__init__.py b/backend/app/schemas/__init__.py index 7fcc61b4..bc2e8709 100644 --- a/backend/app/schemas/__init__.py +++ b/backend/app/schemas/__init__.py @@ -1,2 +1,5 @@ +# -*- coding: utf-8 -*- from .labeler import Labeler, LabelerCreate, LabelerUpdate from .prompt import Prompt, PromptCreate + +__all__ = ["Labeler", "LabelerCreate", "LabelerUpdate", "Prompt", "PromptCreate"] diff --git a/backend/app/schemas/labeler.py b/backend/app/schemas/labeler.py index c0774426..936a4aa1 100644 --- a/backend/app/schemas/labeler.py +++ b/backend/app/schemas/labeler.py @@ -1,5 +1,7 @@ -from typing import Optional +# -*- coding: utf-8 -*- from datetime import datetime +from typing import Optional + from pydantic import BaseModel diff --git a/backend/app/schemas/prompt.py b/backend/app/schemas/prompt.py index 928ab74f..b4f818ed 100644 --- a/backend/app/schemas/prompt.py +++ b/backend/app/schemas/prompt.py @@ -1,5 +1,7 @@ -from typing import Optional +# -*- coding: utf-8 -*- from datetime import datetime +from typing import Optional + from pydantic import BaseModel diff --git a/backend/requirements.txt b/backend/requirements.txt index e271f16c..fa6bee77 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,9 +1,9 @@ +alembic==1.8.1 fastapi==0.88.0 +psycopg2-binary==2.9.5 pydantic==1.9.1 +python-dotenv==0.21.0 SQLAlchemy==1.4.41 sqlmodel==0.0.8 starlette==0.22.0 uvicorn==0.20.0 -psycopg2-binary==2.9.5 -alembic==1.8.1 -python-dotenv==0.21.0 diff --git a/backend/scripts/run-local.sh b/backend/scripts/run-local.sh index b6bc997a..d8bd86c6 100755 --- a/backend/scripts/run-local.sh +++ b/backend/scripts/run-local.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -uvicorn app.main:app --reload \ No newline at end of file +uvicorn app.main:app --reload diff --git a/bot/README.md b/bot/README.md index 09de56fe..935cfb6c 100644 --- a/bot/README.md +++ b/bot/README.md @@ -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 diff --git a/bot/bot.py b/bot/bot.py index ab0519c1..03da1483 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -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") diff --git a/bot/setup.py b/bot/setup.py index be44789a..25df4d9a 100644 --- a/bot/setup.py +++ b/bot/setup.py @@ -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") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..83b614a2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[tool.isort] +profile = "black" +filter_files = true +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true +ensure_newline_before_comments = true +line_length = 120 + +[tool.black] +line-length = 120 +target-version = ['py310'] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..f6a54661 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 120 +extend-ignore = E203, W503, E501, E741 diff --git a/website/package.json b/website/package.json index 6c05fa79..286930a4 100644 --- a/website/package.json +++ b/website/package.json @@ -13,8 +13,8 @@ "web-vitals": "^2.1.4" }, "scripts": { - "predeploy" : "npm run build", - "deploy" : "gh-pages -d build", + "predeploy": "npm run build", + "deploy": "gh-pages -d build", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", diff --git a/website/public/index.html b/website/public/index.html index 901f8be4..bc6ba7d3 100644 --- a/website/public/index.html +++ b/website/public/index.html @@ -5,10 +5,7 @@ - +