From 59311dae51e304bab9e4d3ed1f13408e3131b7bc Mon Sep 17 00:00:00 2001 From: Elias2660 Date: Sun, 7 Jul 2024 19:38:42 +0000 Subject: [PATCH] Automated formatting changes --- cogs/ChatBotPrompts.py | 52 +++++++++++++++++++++++++---------------- testing/getStuff.py | 15 +++++++----- utils/gptFunctions.py | 5 +++- utils/scrapeWebsites.py | 16 ++++++------- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/cogs/ChatBotPrompts.py b/cogs/ChatBotPrompts.py index e0c3490..9a78ed4 100644 --- a/cogs/ChatBotPrompts.py +++ b/cogs/ChatBotPrompts.py @@ -46,29 +46,34 @@ async def on_ready(self): @app_commands.command() async def prompting_help(self, interaction: discord.Interaction): ... - - @app_commands.command(name="list_models", description="List all the models that can be used by prompting") + + @app_commands.command( + name="list_models", + description="List all the models that can be used by prompting", + ) async def list_models(self, interaction: discord.Interaction): models = { - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-3.5-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-turbo-preview", - "gpt-4-0125-preview", - "gpt-4-1106-preview", - "gpt-4", - "gpt-4-0613", - "gpt-4-0314", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo", - "gpt-3.5-turbo-1106", - "gpt-3.5-turbo-instruct", + "gpt-4o", + "gpt-4o-2024-05-13", + "gpt-3.5-turbo", + "gpt-4-turbo-2024-04-09", + "gpt-4-turbo-preview", + "gpt-4-0125-preview", + "gpt-4-1106-preview", + "gpt-4", + "gpt-4-0613", + "gpt-4-0314", + "gpt-3.5-turbo-0125", + "gpt-3.5-turbo", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-instruct", } await interaction.response.send_message("\n".join(models)) - - - @app_commands.command(name="max_tokens", description="lists the max number of context tokens a model can have") + + @app_commands.command( + name="max_tokens", + description="lists the max number of context tokens a model can have", + ) async def max_tokens(self, interaction: discord.Interaction): openAI_max_context = { "gpt-4o": 128000, @@ -86,7 +91,14 @@ async def max_tokens(self, interaction: discord.Interaction): "gpt-3.5-turbo-1106": 16385, "gpt-3.5-turbo-instruct": 4096, } - await interaction.response.send_message("\n".join([f"{key}:" + " {:,}".format(int(value)) for key, value in openAI_max_context.items()])) + await interaction.response.send_message( + "\n".join( + [ + f"{key}:" + " {:,}".format(int(value)) + for key, value in openAI_max_context.items() + ] + ) + ) async def setup(client): diff --git a/testing/getStuff.py b/testing/getStuff.py index 2ea5112..ec179ac 100644 --- a/testing/getStuff.py +++ b/testing/getStuff.py @@ -1,28 +1,31 @@ import asyncio from playwright.async_api import async_playwright + async def scrape_p_text(url): async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() await page.goto(url) - + # Get all text from

tags - p_tags = await page.query_selector_all('p') + p_tags = await page.query_selector_all("p") p_texts = [await p.text_content() for p in p_tags] - + await browser.close() - + return p_texts + async def main(): - url = 'https://www.bbc.com/news/articles/cq5xjzqree2o' # Replace with the URL you want to scrape + url = "https://www.bbc.com/news/articles/cq5xjzqree2o" # Replace with the URL you want to scrape p_texts = await scrape_p_text(url) print("Text in

tags:") text = " ".join(p_texts) text.replace(" ", " ") return text -if __name__ == '__main__': + +if __name__ == "__main__": print(asyncio.run(main())) # scrape_p_text("https://www.bbc.com/news/articles/cq5xjzqree2o") diff --git a/utils/gptFunctions.py b/utils/gptFunctions.py index 7d83f0c..273af78 100644 --- a/utils/gptFunctions.py +++ b/utils/gptFunctions.py @@ -106,7 +106,9 @@ async def createQOTW(websites: str, model: str = "gpt-4o") -> str: return f"Invalid model. Please run the prompting help command to find the right model to use." try: client = OpenAI(api_key=API_KEY) - website_list = [website.strip().replace("\"", "") for website in websites.split(",")] + website_list = [ + website.strip().replace('"', "") for website in websites.split(",") + ] data = "\n".join( [ f"Website Source: {website} \n {await scrape_p_text(website)}" @@ -167,6 +169,7 @@ async def main(): ) return response + if __name__ == "__main__": response = asyncio.run(main()) print(response) diff --git a/utils/scrapeWebsites.py b/utils/scrapeWebsites.py index 4c7d5cf..ca31aaf 100644 --- a/utils/scrapeWebsites.py +++ b/utils/scrapeWebsites.py @@ -2,23 +2,23 @@ from playwright.async_api import async_playwright -async def scrape_p_text(url:str) -> str: - ''' +async def scrape_p_text(url: str) -> str: + """ Scrapes all the text from the

tags on a webpage - + This usually only works for the websites BBC, the Verge, or AP News (which are the only websites I have tested this on) - ''' + """ async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() await page.goto(url) - + # Get all text from

tags - p_tags = await page.query_selector_all('p') + p_tags = await page.query_selector_all("p") p_texts = [await p.text_content() for p in p_tags] - + await browser.close() - + text = " ".join(p_texts) text.replace(" ", " ") return text