From 6a1157fb7e78fc1c3ae8189d5d7c74496fe6774a Mon Sep 17 00:00:00 2001 From: Alex Ott <66271487+AlexanderHOtt@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:36:06 -0800 Subject: [PATCH 01/28] merge upstream/main --- discord-bot/bot/extensions/guild_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord-bot/bot/extensions/guild_settings.py b/discord-bot/bot/extensions/guild_settings.py index 1aba9f47..cb419874 100644 --- a/discord-bot/bot/extensions/guild_settings.py +++ b/discord-bot/bot/extensions/guild_settings.py @@ -64,6 +64,7 @@ async def log_channel(ctx: lightbulb.SlashContext) -> None: conn: Connection = ctx.bot.d.db assert ctx.guild_id is not None # `guild_only` check assert isinstance(channel, hikari.PermissibleGuildChannel) + type(channel).mro() # Check if the bot can send messages in that channel assert (me := ctx.bot.get_me()) is not None # non-None after `StartedEvent` From 24530a7cc82cb0661c19a12ba39bfd251fd31ce7 Mon Sep 17 00:00:00 2001 From: Alex Ott <66271487+AlexanderHOtt@users.noreply.github.com> Date: Sat, 31 Dec 2022 16:31:04 -0800 Subject: [PATCH 02/28] update permissions check for guild settings --- discord-bot/bot/extensions/guild_settings.py | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/discord-bot/bot/extensions/guild_settings.py b/discord-bot/bot/extensions/guild_settings.py index cb419874..d09407da 100644 --- a/discord-bot/bot/extensions/guild_settings.py +++ b/discord-bot/bot/extensions/guild_settings.py @@ -5,7 +5,7 @@ import lightbulb from aiosqlite import Connection from bot.db.schemas import GuildSettings from bot.utils import mention -from lightbulb.utils.permissions import permissions_in +from lightbulb.utils import permissions_in from loguru import logger plugin = lightbulb.Plugin("GuildSettings") @@ -56,33 +56,42 @@ if guild_settings.log_channel_id else 'not set'} @settings.child @lightbulb.option("channel", "The channel to use.", hikari.TextableGuildChannel) -@lightbulb.command("log_channel", "Set the channel that the bot logs task and label completions in.") +@lightbulb.command("log_channel", "Set the channel that the bot logs task and label completions in.", ephemeral=True) @lightbulb.implements(lightbulb.SlashSubCommand) async def log_channel(ctx: lightbulb.SlashContext) -> None: """Set the channel that the bot logs task and label completions in.""" channel: hikari.TextableGuildChannel = ctx.options.channel conn: Connection = ctx.bot.d.db assert ctx.guild_id is not None # `guild_only` check - assert isinstance(channel, hikari.PermissibleGuildChannel) - type(channel).mro() # Check if the bot can send messages in that channel - assert (me := ctx.bot.get_me()) is not None # non-None after `StartedEvent` - if (own_member := ctx.bot.cache.get_member(ctx.guild_id, me.id)) is None: - own_member = await ctx.bot.rest.fetch_member(ctx.guild_id, me.id) - perms = permissions_in(channel, own_member) - if perms & ~hikari.Permissions.SEND_MESSAGES: - await ctx.respond("I don't have permission to send messages in that channel.") + assert isinstance(channel, hikari.InteractionChannel) # Slash commands are interactions + me = ctx.bot.cache.get_me() or await ctx.bot.rest.fetch_my_user() + own_member = ctx.bot.cache.get_member(ctx.guild_id, me.id) or await ctx.bot.rest.fetch_member(ctx.guild_id, me.id) + + # Get the channel from the cache if it is there, otherwise fetch it + if (ch := ctx.bot.cache.get_guild_channel(channel.id)) is None: + ch = {ch.id: ch for ch in await ctx.bot.rest.fetch_guild_channels(channel.id)}[channel.id] + + if not isinstance(ch, hikari.GuildTextChannel): + await ctx.respond(f"{ch.mention} is not a text channel.") + return + + # if the bot's permissions for this channel don't contain SEND_MESSAGE + # This will also filter out categories and voice channels + print(permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES) + if not permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES: + await ctx.respond(f"I don't have permission to send messages in {ch.mention}.") return await ctx.respond(f"Setting `log_channel` to {channel.mention}.") + # update the database async with conn.cursor() as cursor: await cursor.execute( "INSERT OR REPLACE INTO guild_settings (guild_id, log_channel_id) VALUES (?, ?)", (ctx.guild_id, channel.id), ) - await conn.commit() logger.info(f"Updated `log_channel` for {ctx.guild_id} to {channel.id}.") From f15f2c29ed4a106a0c921113671f910f57b19412 Mon Sep 17 00:00:00 2001 From: Alexander Goryunov Date: Sun, 1 Jan 2023 12:49:05 +0200 Subject: [PATCH 03/28] Fixed text formatting and made code more Pythonic --- .../EssayInstructions.ipynb | 277 +++++++++++++----- 1 file changed, 198 insertions(+), 79 deletions(-) diff --git a/notebooks/data-argumentation/EssayInstructions.ipynb b/notebooks/data-argumentation/EssayInstructions.ipynb index ec534887..d267ef03 100644 --- a/notebooks/data-argumentation/EssayInstructions.ipynb +++ b/notebooks/data-argumentation/EssayInstructions.ipynb @@ -1,135 +1,201 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { "cell_type": "code", - "source": [ - "!pip install transformers" - ], + "execution_count": null, "metadata": { "id": "8zsmJ96eaL2w" }, - "execution_count": null, - "outputs": [] + "outputs": [], + "source": [ + "!pip install transformers" + ] }, { "cell_type": "markdown", + "metadata": { + "id": "Pt6qbTsjW7Kp" + }, "source": [ "Put your essay here, [source of the essay used ](https://https://www.thewisdompost.com/essay/technology-essay/3387#essay-on-technology-for-college-and-university-students-essay-2-750-words)\n", "\n", - "Saperate paragraphs with one blank line\n", + "Separate paragraphs with one blank line\n", "(this step is annoying but important)\n" - ], - "metadata": { - "id": "Pt6qbTsjW7Kp" - } + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "d_5_BDFNWneB" }, "outputs": [], "source": [ "essay = \"\"\"\n", - "We live in a world driven by technology — hardly anyone would argue with you if you said this. Technology, literally meaning the “science of craft”, refers to the collection of techniques, skills, methods, and processes used to produce goods or services or for accomplishing objectives such as scientific investigation. Technology can be embedded in machines enabling them to be used by people even without a detailed knowledge of their inner workings.\n", - "Technological growth is closely linked to the expansion of scientific research and knowledge. In the last 50 years, thanks to the exponential increases in computing power and microchip design and manufacture, there has been unprecedented innovation and technological growth in nearly every field of human endeavour from health and transport to industrial production and education.\n", + "We live in a world driven by technology — hardly anyone would argue with you if you said this. \n", + "Technology, literally meaning the “science of craft”, refers to the collection of techniques, \n", + "skills, methods, and processes used to produce goods or services or for accomplishing objectives \n", + "such as scientific investigation. Technology can be embedded in machines enabling them to be \n", + "used by people even without a detailed knowledge of their inner workings. Technological growth \n", + "is closely linked to the expansion of scientific research and knowledge. In the last 50 years, \n", + "thanks to the exponential increases in computing power and microchip design and manufacture, \n", + "there has been unprecedented innovation and technological growth in nearly every field of human \n", + "endeavour from health and transport to industrial production and education.\n", "\n", - "It is automotive technology that drives today’s electric and hybrid cars, and which will drive tomorrow’s driverless cars, hover-taxis and space cabs.\n", - "It is technology that drives the ubiquitous mobile phones that you will now find in the hands of even the poorest of the world’s poor. It is technology that creates hybrid seeds that resist inhospitable climatic conditions and difficult terrain, giving high yields in shorter times.\n", - "It is advancing medical technology that makes remote surgery, minimally invasive surgery and life-saving cures using stem cell transplants. Technology puts spacecrafts on asteroids and distant planets and lets us see new worlds. Technology splits atoms, revealing their secrets, and gives us ways to exploit them to create energy, quantum storage for data, and virtual reality games.\n", + "It is automotive technology that drives today’s electric and hybrid cars, and which will drive \n", + "tomorrow’s driverless cars, hover-taxis and space cabs. It is technology that drives the \n", + "ubiquitous mobile phones that you will now find in the hands of even the poorest of the world’s \n", + "poor. It is technology that creates hybrid seeds that resist inhospitable climatic conditions \n", + "and difficult terrain, giving high yields in shorter times. It is advancing medical technology \n", + "that makes remote surgery, minimally invasive surgery and life-saving cures using stem cell \n", + "transplants. Technology puts spacecrafts on asteroids and distant planets and lets us see \n", + "new worlds. Technology splits atoms, revealing their secrets, and gives us ways to exploit \n", + "them to create energy, quantum storage for data, and virtual reality games.\n", "\n", - "There are people who strongly oppose technology and claim that it spells the death of ‘humanity’, and that we are approaching the day when machines will rule everything. They refer to fans of technology as ‘techies’ or sometimes ‘geeks’. On the other hand, proponents of technology call these people Luddites, a derogatory name for someone who is opposed to industrialisation, automation, computerisation and new technologies in general.\n", - "Is this true? Is technology really a curse disguised as a blessing? Many believe that the convergence of biotechnology and AI might be the most consequential development of all.\n", + "There are people who strongly oppose technology and claim that it spells the death of \n", + "‘humanity’, and that we are approaching the day when machines will rule everything. They refer \n", + "to fans of technology as ‘techies’ or sometimes ‘geeks’. On the other hand, proponents of \n", + "technology call these people Luddites, a derogatory name for someone who is opposed to \n", + "industrialisation, automation, computerisation and new technologies in general.\n", + "Is this true? Is technology really a curse disguised as a blessing? Many believe that the \n", + "convergence of biotechnology and AI might be the most consequential development of all.\n", "\n", - "In the last five decades, two areas in particular have grown faster than the rest, powered by research and advances in computing power. One is artificial intelligence, or AI; the other is biotechnology. Huge benefits have emerged from each of them for human beings in general, such as self-driving cars — which will dramatically reduce the death rate from road accidents — and robotic surgery, which enables precise, highly efficient and targeted surgical interventions.\n", - "Yet, visionaries like Yuval Noah Harari, author of the best-selling Homo sapiens and Deus, are now warning that the convergence of biotechnology and AI will irreversibly and unpredictably change both the quality of human life and its challenges in the next few decades. A good example of this is the facial recognition technology that is now present in all photo management programs. The AI in the software is capable of not only spotting the faces in every photograph but also recognising the person by name.\n", - "This technology has now expanded so that photo apps can recognise cats, dogs, beaches, mountains and cars too. Computers with AI are already correctly identifying human emotions through observing facial expressions and body movements. Some robots are able to mimic human emotions. This is called affective computing, sometimes called artificial emotional intelligence, and refers to the study and development of systems and devices that can recognize, interpret, process, and simulate human affects.\n", + "In the last five decades, two areas in particular have grown faster than the rest, powered \n", + "by research and advances in computing power. One is artificial intelligence, or AI; the other \n", + "is biotechnology. Huge benefits have emerged from each of them for human beings in general, \n", + "such as self-driving cars — which will dramatically reduce the death rate from road accidents \n", + "— and robotic surgery, which enables precise, highly efficient and targeted surgical \n", + "interventions. Yet, visionaries like Yuval Noah Harari, author of the best-selling \"Homo \n", + "Sapiens\" and \"Deus\", are now warning that the convergence of biotechnology and AI will \n", + "irreversibly and unpredictably change both the quality of human life and its challenges in \n", + "the next few decades. A good example of this is the facial recognition technology that is \n", + "now present in all photo management programs. The AI in the software is capable of not \n", + "only spotting the faces in every photograph but also recognising the person by name.\n", + "This technology has now expanded so that photo apps can recognise cats, dogs, beaches, \n", + "mountains and cars too. Computers with AI are already correctly identifying human emotions \n", + "through observing facial expressions and body movements. Some robots are able to mimic \n", + "human emotions. This is called affective computing, sometimes called artificial emotional \n", + "intelligence, and refers to the study and development of systems and devices that can \n", + "recognize, interpret, process, and simulate human affects.\n", "\n", "How could this be a negative?\n", - "The ability to read human emotions is just a step away from predicting human emotions. For example, if a computer attached to a video camera could identify which products a consumer is showing greater interest in or which ones he is really keen to buy, various tactics could be used to influence her to buy it.\n", - "Activists worry that computers that can understand and anticipate human wishes and desires by scanning their irises and analysing their micro-expressions could also be programmed to exploit and manipulate them.\n", - "Another very real fear is that humanoid computers with human-like skin, speech, and expressions could jeopardise and dehumanise relationship and create emotional vacuums.\n", + "The ability to read human emotions is just a step away from predicting human emotions. For \n", + "example, if a computer attached to a video camera could identify which products a consumer \n", + "is showing greater interest in or which ones he is really keen to buy, various tactics \n", + "could be used to influence her to buy it. Activists worry that computers that can understand \n", + "and anticipate human wishes and desires by scanning their irises and analysing their \n", + "micro-expressions could also be programmed to exploit and manipulate them. Another very real \n", + "fear is that humanoid computers with human-like skin, speech, and expressions could jeopardise \n", + "and dehumanise relationship and create emotional vacuums.\n", "\n", - "An enduring fear of Luddites has always been that computers will rob humans of their livelihood by taking their jobs and doing them more efficiently at lower cost. However, in reality the exact opposite has happened. As computerised machines began taking over mechanical and repetitive human activities, new jobs for people opened up that needs thinking and analytical skills and judgement, or human interpersonal skills. A good example is the worldwide proliferation of call centres.\n", - "When drones were invented many feared that pilots would soon be redundant. However, few people know that it takes almost 30 people to fly one military drone, and an additional 50 people to analyze and make sense of the data being streamed back by the drone.\n", - "The US army suffers from a serious shortage of trained, high quality drone pilots; anyone who masters this skill will have a job. But a social scientist warns that in 10 years, it is certain that computers will be flying that drone and humans will be redundant. Equally sure is that some brand new skill requirement will have opened up with advancing technology, calling for new talents.\n", + "An enduring fear of Luddites has always been that computers will rob humans of their \n", + "livelihood by taking their jobs and doing them more efficiently at lower cost. However, in \n", + "reality the exact opposite has happened. As computerised machines began taking over mechanical \n", + "and repetitive human activities, new jobs for people opened up that needs thinking and \n", + "analytical skills and judgement, or human interpersonal skills. A good example is the \n", + "worldwide proliferation of call centres. When drones were invented many feared that pilots \n", + "would soon be redundant. However, few people know that it takes almost 30 people to fly \n", + "one military drone, and an additional 50 people to analyze and make sense of the data being \n", + "streamed back by the drone. The US army suffers from a serious shortage of trained, high \n", + "quality drone pilots; anyone who masters this skill will have a job. But a social scientist \n", + "warns that in 10 years, it is certain that computers will be flying that drone and humans \n", + "will be redundant. Equally sure is that some brand new skill requirement will have opened \n", + "up with advancing technology, calling for new talents.\n", "\n", - "In the 20th century, a young man was supposed to choose a skill, vocation or profession, master it through education and practice, and then earn a living from it till he or she retired. However, the fast-changing nature of technology is making skills obsolete at a higher rate than ever before. To survive, tomorrow young man must keep re-inventing himself and updating his skills continuously. Life could be difficult if every new skill has a shelf life of only a decade or so.\n", - "Or perhaps one could look at it the other way — and say that changing technology will keep human beings on their toes throughout their life.\n", + "In the 20th century, a young man was supposed to choose a skill, vocation or profession, \n", + "master it through education and practice, and then earn a living from it till he or she \n", + "retired. However, the fast-changing nature of technology is making skills obsolete at a \n", + "higher rate than ever before. To survive, tomorrow young man must keep re-inventing himself \n", + "and updating his skills continuously. Life could be difficult if every new skill has a shelf \n", + "life of only a decade or so. Or perhaps one could look at it the other way — and say that \n", + "changing technology will keep human beings on their toes throughout their life.\n", "\n", - "Technology is the result of human inventiveness. It reflects our evolutionary heritage. We are neither strong like gorillas or tigers, nor fast like cheetahs and hawks, but our brains and thinking powers have given us the greatest edge of any species on the planet. Technology is a result.\n", - "Technology is either inherently good or bad; it is how we use it that makes it so. The splitting of a hydrogen atom is technology at work. As history has shown us, technology can equally be used to make a nuclear bomb that kills millions — or generate electricity that lights up a million homes.\n", + "Technology is the result of human inventiveness. It reflects our evolutionary heritage. We \n", + "are neither strong like gorillas or tigers, nor fast like cheetahs and hawks, but our \n", + "brains and thinking powers have given us the greatest edge of any species on the planet. \n", + "Technology is a result. Technology is either inherently good or bad; it is how we use it \n", + "that makes it so. The splitting of a hydrogen atom is technology at work. As history has \n", + "shown us, technology can equally be used to make a nuclear bomb that kills millions — or \n", + "generate electricity that lights up a million homes.\n", "\"\"\"" ] }, { "cell_type": "code", - "source": [ - "essay_paragraphs = essay.split('\\n\\n')" - ], + "execution_count": 3, "metadata": { "id": "JESY8Y10W6hQ" }, - "execution_count": null, - "outputs": [] + "outputs": [], + "source": [ + "essay_paragraphs = essay.split('\\n\\n')" + ] }, { "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "t1G-ZiHbZZ-Y" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2023-01-01 12:18:07.154473: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n", + "2023-01-01 12:18:07.154505: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c0472f74fc4248f9811b163d5487e707", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Downloading: 0%| | 0.00/1.39k [00:00 Date: Sun, 1 Jan 2023 12:57:01 +0200 Subject: [PATCH 04/28] Removed cell outputs --- .../EssayInstructions.ipynb | 59 +------------------ 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/notebooks/data-argumentation/EssayInstructions.ipynb b/notebooks/data-argumentation/EssayInstructions.ipynb index d267ef03..b81a8b09 100644 --- a/notebooks/data-argumentation/EssayInstructions.ipynb +++ b/notebooks/data-argumentation/EssayInstructions.ipynb @@ -133,48 +133,11 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "id": "t1G-ZiHbZZ-Y" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "2023-01-01 12:18:07.154473: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n", - "2023-01-01 12:18:07.154505: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c0472f74fc4248f9811b163d5487e707", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Downloading: 0%| | 0.00/1.39k [00:00 Date: Sun, 1 Jan 2023 03:02:37 -0800 Subject: [PATCH 05/28] add error handler for the bot --- discord-bot/bot/bot.py | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/discord-bot/bot/bot.py b/discord-bot/bot/bot.py index a305946f..b2a2eb25 100644 --- a/discord-bot/bot/bot.py +++ b/discord-bot/bot/bot.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- """Bot logic.""" +from datetime import datetime + import aiosqlite import hikari import lightbulb import miru from bot.api_client import OasstApiClient from bot.settings import Settings +from bot.utils import EMPTY, mention settings = Settings() @@ -38,3 +41,77 @@ async def on_stopping(event: hikari.StoppingEvent): """Cleanup.""" await bot.d.db.close() await bot.d.oasst_api.close() + + +async def _send_error_embed( + content: str, exception: lightbulb.errors.LightbulbError | BaseException, ctx: lightbulb.Context +) -> None: + ctx.command + embed = hikari.Embed( + title=f"`{exception.__class__.__name__}` Error{f' in `{ctx.command.name}`' if ctx.command else '' }", + description=content, + color=0xFF0000, + timestamp=datetime.now().astimezone(), + ).set_author(name=ctx.author.username, url=str(ctx.author.avatar_url)) + + await ctx.respond(EMPTY, embed=embed) + + +@bot.listen(lightbulb.CommandErrorEvent) +async def on_error(event: lightbulb.CommandErrorEvent) -> None: + """Error handler for the bot.""" + # Unwrap the exception to get the original cause + exc = event.exception.__cause__ or event.exception + ctx = event.context + + if isinstance(event.exception, lightbulb.CommandInvocationError): + if not event.context.command: + await _send_error_embed("Something went wrong", exc, ctx) + else: + await _send_error_embed( + f"Something went wrong during invocation of command `{event.context.command.name}`.", exc, ctx + ) + + raise event.exception + + # Not an owner + if isinstance(exc, lightbulb.NotOwner): + await _send_error_embed("You are not the owner of this bot.", exc, ctx) + # Command is on cooldown + elif isinstance(exc, lightbulb.CommandIsOnCooldown): + await _send_error_embed(f"This command is on cooldown. Retry in `{exc.retry_after:.2f}` seconds.", exc, ctx) + # Missing permissions + elif isinstance(exc, lightbulb.errors.MissingRequiredPermission): + await _send_error_embed( + f"You do not have permission to use this command. Missing permissions: {exc.missing_perms}", exc, ctx + ) + # Missing roles + elif isinstance(exc, lightbulb.errors.MissingRequiredRole): + assert event.context.guild_id is not None # Roles only exist in guilds + await _send_error_embed( + f"You do not have the correct role to use this command. Missing role(s): {[mention(r, 'role') for r in exc.missing_roles]}", + exc, + ctx, + ) + # Only a guild command + elif isinstance(exc, lightbulb.errors.OnlyInGuild): + await _send_error_embed("This command can only be run in servers.", exc, ctx) + # Only a DM command + elif isinstance(exc, lightbulb.errors.OnlyInDM): + await _send_error_embed("This command can only be run in DMs.", exc, ctx) + # Not enough arguments + elif isinstance(exc, lightbulb.errors.NotEnoughArguments): + await _send_error_embed( + f"Not enough arguments were supplied to the command. {[opt.name for opt in exc.missing_options]}", exc, ctx + ) + # Bot missing permission + elif isinstance(exc, lightbulb.errors.BotMissingRequiredPermission): + await _send_error_embed( + f"The bot does not have the correct permission(s) to execute this command. Missing permissions: {exc.missing_perms}", + exc, + ctx, + ) + elif isinstance(exc, lightbulb.errors.MissingRequiredAttachment): + await _send_error_embed("Not enough attachemnts were supplied to this command.", exc, ctx) + else: + raise exc From e871de693cf36936be05a02ed67b5ace3522e43a Mon Sep 17 00:00:00 2001 From: Alexander Goryunov Date: Sun, 1 Jan 2023 21:52:38 +0200 Subject: [PATCH 06/28] A typo in import --- model/reward/instructor/cls_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/reward/instructor/cls_dataset.py b/model/reward/instructor/cls_dataset.py index 09aa821b..7992c37c 100644 --- a/model/reward/instructor/cls_dataset.py +++ b/model/reward/instructor/cls_dataset.py @@ -8,7 +8,7 @@ import json import os import random -from dataset import load_dataset +from datasets import load_dataset from torch.utils.data import Dataset from .utils import webgpt_return_format From 4c7b8cfd35ec7bf85464f81c8112c26a7fee867f Mon Sep 17 00:00:00 2001 From: Gareth Davidson Date: Sat, 31 Dec 2022 18:19:47 +0000 Subject: [PATCH 07/28] Use --prose-wrap=always to format markdown files --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 271c11c6..c32ca7c8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,7 +50,7 @@ repos: rev: v2.7.1 hooks: - id: prettier - args: ["--write"] + args: ["--prose-wrap=always", "--write"] - repo: local hooks: From c3c7a1701a5007fadfc75ee089a237c91736e3f9 Mon Sep 17 00:00:00 2001 From: Gareth Davidson Date: Sun, 1 Jan 2023 20:57:02 +0000 Subject: [PATCH 08/28] run `prettier` with new params --- .github/workflows/build-frontend.yaml | 4 +- README.md | 123 ++++++++++++------ backend/README.md | 7 +- copilot/README.md | 12 +- copilot/web/addons/web-cluster.yml | 41 ++++-- discord-bot/README.md | 27 +++- docs/README.md | 9 +- docs/data_argumentation.md | 14 +- docs/prompting_guide.md | 79 +++++++---- docs/research/README.md | 33 +++-- docs/research/search_based_qa.md | 71 +++++++--- model/reward/instructor/README.md | 6 +- model/reward/instructor/TODO.md | 13 +- notebooks/README.md | 7 +- .../data-argumentation/EssayInstructions.md | 11 +- notebooks/data-argumentation/EssayRevision.md | 9 +- notebooks/detoxify-evaluation/README.md | 34 +++-- scripts/backend-development/README.md | 12 +- scripts/frontend-development/README.md | 7 +- website/README.md | 82 +++++++----- website/cypress/README.md | 55 ++++++-- 21 files changed, 448 insertions(+), 208 deletions(-) diff --git a/.github/workflows/build-frontend.yaml b/.github/workflows/build-frontend.yaml index 9fb2e8cf..ccb64539 100644 --- a/.github/workflows/build-frontend.yaml +++ b/.github/workflows/build-frontend.yaml @@ -12,7 +12,7 @@ on: workflow_call: jobs: - build-frontend: + build-frontend: runs-on: ubuntu-latest defaults: run: @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16.x - cache: 'npm' + cache: "npm" cache-dependency-path: website/package-lock.json - run: npm ci - run: npm run build diff --git a/README.md b/README.md index e0ea65f1..4ade8e13 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,17 @@ # Open-Assistant -Open Assistant is a project meant to give everyone access to a great chat based large language model. +Open Assistant 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 Assistant can help improve the world by improving language itself. +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 Assistant can help improve the world by +improving language itself. ## Do you want to try it out? -If you are interested in taking a look at the current state of the project, You can set up an entire stack needed to run **Open-Assistant**, including the +If you are interested in taking a look at the current state of the project, You +can set up an entire stack needed to run **Open-Assistant**, including the website, backend, and associated dependent services. To start the demo, Run this in the root directory of the repository: @@ -15,23 +20,44 @@ To start the demo, Run this in the root directory of the repository: docker compose up --build ``` -Then, navigate to `http://localhost:3000` (It may take some time to boot up) and interact with the website. +Then, navigate to `http://localhost:3000` (It may take some time to boot up) and +interact with the website. -**Note:** When logging in via email, navigate to `http://localhost:1080` to get the magic email login link. +**Note:** When logging in via email, navigate to `http://localhost:1080` to get +the magic email login link. ## The Plan -We want to get to an initial MVP as fast as possible, by following the 3-steps outlined in the InstructGPT paper. +We want to get to an initial MVP as fast as possible, by following the 3-steps +outlined in the InstructGPT paper. -1. Collect high-quality human generated Instruction-Fulfillment samples (prompt + response), goal >50k. We design a crowdsourced process to collect and reviewed prompts. We do not want to train on flooding/toxic/spam/junk/personal information data. We will have a leaderboard to motivate the community that shows progress and the most active users. Swag will be given to the top-contributors. -2. For each of the collected prompts we will sample multiple completions. Completions of one prompt will then be shown randomly to users to rank them from best to worst. Again this should happen crowd-sourced, e.g. we need to deal with unreliable potentially malicious users. At least multiple votes by independent users have to be collected to measure the overall agreement. The gathered ranking-data will be used to train a reward model. -3. Now follows the RLHF training phase based on the prompts and the reward model. +1. Collect high-quality human generated Instruction-Fulfillment samples + (prompt + response), goal >50k. We design a crowdsourced process to collect + and reviewed prompts. We do not want to train on + flooding/toxic/spam/junk/personal information data. We will have a + leaderboard to motivate the community that shows progress and the most active + users. Swag will be given to the top-contributors. +2. For each of the collected prompts we will sample multiple completions. + Completions of one prompt will then be shown randomly to users to rank them + from best to worst. Again this should happen crowd-sourced, e.g. we need to + deal with unreliable potentially malicious users. At least multiple votes by + independent users have to be collected to measure the overall agreement. The + gathered ranking-data will be used to train a reward model. +3. Now follows the RLHF training phase based on the prompts and the reward + model. -We can then take the resulting model and continue with completion sampling step 2 for a next iteration. +We can then take the resulting model and continue with completion sampling step +2 for a next iteration. ## The Vision -We are not going to stop at replicating ChatGPT. We want to build the assistant of the future, able to not only write email and cover letters, but do meaningful work, use APIs, dynamically research information, and much more, with the ability to be personalized and extended by anyone. And we want to do this in a way that is open and accessible, which means we must not only build a great assistant, but also make it small and efficient enough to run on consumer hardware. +We are not going to stop at replicating ChatGPT. We want to build the assistant +of the future, able to not only write email and cover letters, but do meaningful +work, use APIs, dynamically research information, and much more, with the +ability to be personalized and extended by anyone. And we want to do this in a +way that is open and accessible, which means we must not only build a great +assistant, but also make it small and efficient enough to run on consumer +hardware. ### Slide Decks @@ -41,15 +67,20 @@ We are not going to stop at replicating ChatGPT. We want to build the assistant ## How can you help? -All open source projects begins with people like you. Open source is the belief that if we collaborate we can together gift our knowledge and technology to the world for the benefit of humanity. +All open source projects begins with people like you. Open source is the belief +that if we collaborate we can together gift our knowledge and technology to the +world for the benefit of humanity. ## I’m in! Now what? -[Join the OpenAssistant Contributors Discord Server!](https://ykilcher.com/open-assistant-discord), this is for work coordination. +[Join the OpenAssistant Contributors Discord Server!](https://ykilcher.com/open-assistant-discord), +this is for work coordination. -[Join the LAION Discord Server!](https://discord.com/invite/mVcgxMPD7e), it has a dedicated channel and is more public. +[Join the LAION Discord Server!](https://discord.com/invite/mVcgxMPD7e), it has +a dedicated channel and is more public. -[and / or the YK Discord Server](https://ykilcher.com/discord), also has a dedicated, but not as active, channel. +[and / or the YK Discord Server](https://ykilcher.com/discord), also has a +dedicated, but not as active, channel. [Visit the Notion](https://ykilcher.com/open-assistant) @@ -57,15 +88,16 @@ All open source projects begins with people like you. Open source is the belief We have a growing task list [of issues](https://github.com/LAION-AI/Open-Assistant/issues). Find an issue -that appeals to you and make a comment that you'd like to work on it. Include -in your comment a brief description of how you'll solve the problem and if -there are any open questions you want to discuss. Once a project coordinator -has assigned the issue to you, start working on it. +that appeals to you and make a comment that you'd like to work on it. Include in +your comment a brief description of how you'll solve the problem and if there +are any open questions you want to discuss. Once a project coordinator has +assigned the issue to you, start working on it. -If the issue is currently unclear but you are interested, please post in -Discord and someone can help clarify the issue with more detail. +If the issue is currently unclear but you are interested, please post in Discord +and someone can help clarify the issue with more detail. -**Always Welcome:** Documentation markdowns in `docs/`, docstrings, diagrams of the system architecture, and other documentation. +**Always Welcome:** Documentation markdowns in `docs/`, docstrings, diagrams of +the system architecture, and other documentation. ### Submitting Work @@ -73,8 +105,8 @@ We're all working on different parts of Open Assistant together. To make contributions smoothly we recommend the following: 1. [Fork this project repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo) - and clone it to your local machine. - (Read more [About Forks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks)) + and clone it to your local machine. (Read more + [About Forks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks)) 1. Before working on any changes, try to [sync the forked repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to keep it up-to-date with the upstream repository. @@ -83,7 +115,8 @@ contributions smoothly we recommend the following: simplifies life for reviewers. 1. Package up a small bit of work that solves part of the problem [into a Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) - and [send it out for review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review). + and + [send it out for review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review). 1. If you're lucky, we can merge your change into `main` without any problems. If there's changes to files you're working on, resolve them by: 1. First try rebase as suggested @@ -108,20 +141,27 @@ addressed now, or filing an issue to handle it later. ## Developer Setup -Work is organized in the [project board](https://github.com/orgs/LAION-AI/projects/3). +Work is organized in the +[project board](https://github.com/orgs/LAION-AI/projects/3). -**Anything that is in the `Todo` column and not assigned, is up for grabs. Meaning we'd be happy for anyone to do these tasks.** +**Anything that is in the `Todo` column and not assigned, is up for grabs. +Meaning we'd be happy for anyone to do these tasks.** -If you want to work on something, assign yourself to it or write a comment that you want to work on it and what you plan to do. +If you want to work on something, assign yourself to it or write a comment that +you want to work on it and what you plan to do. -- To get started with development, if you want to work on the backend, have a look at `scripts/backend-development/README.md`. -- If you want to work on any frontend, have a look at `scripts/frontend-development/README.md` to make a backend available. +- To get started with development, if you want to work on the backend, have a + look at `scripts/backend-development/README.md`. +- If you want to work on any frontend, have a look at + `scripts/frontend-development/README.md` to make a backend available. -There is also a minimal implementation of a frontend in the `text-frontend` folder. +There is also a minimal implementation of a frontend in the `text-frontend` +folder. We are using Python 3.10 for the backend. -Check out the [High-Level Protocol Architecture](https://www.notion.so/High-Level-Protocol-Architecture-6f1fd3551da74213b560ead369f132dc) +Check out the +[High-Level Protocol Architecture](https://www.notion.so/High-Level-Protocol-Architecture-6f1fd3551da74213b560ead369f132dc) ### Website @@ -129,16 +169,25 @@ The website is built using Next.js and is in the `website` folder. ### Pre-commit -Install `pre-commit` and run `pre-commit install` to install the pre-commit hooks. +Install `pre-commit` and run `pre-commit install` to install the pre-commit +hooks. -In case you haven't done this, have already committed, and CI is failing, you can run `pre-commit run --all-files` to run the pre-commit hooks on all files. +In case you haven't done this, have already committed, and CI is failing, you +can run `pre-commit run --all-files` to run the pre-commit hooks on all files. ### Deployment -Upon making a release on GitHub, all docker images are automatically built and pushed to ghcr.io. The docker images are tagged with the release version, and the `latest` tag. Further, the ansible playbook in `ansible/dev.yaml` is run to automatically deploy the built release to the dev machine. +Upon making a release on GitHub, all docker images are automatically built and +pushed to ghcr.io. The docker images are tagged with the release version, and +the `latest` tag. Further, the ansible playbook in `ansible/dev.yaml` is run to +automatically deploy the built release to the dev machine. ### Problems and Solutions -- **I am on Ubuntu and getting `ERROR: The Compose file is invalid because:Service backend has neither an image nor a build context specified. At least one must be provided.`** +- **I am on Ubuntu and getting + `ERROR: The Compose file is invalid because:Service backend has neither an image nor a build context specified. At least one must be provided.`** - Make sure you have an up-to-date version of docker installed, and also install `docker-compose-plugin`. See [here](https://github.com/LAION-AI/Open-Assistant/issues/208) for more details. + Make sure you have an up-to-date version of docker installed, and also install + `docker-compose-plugin`. See + [here](https://github.com/LAION-AI/Open-Assistant/issues/208) for more + details. diff --git a/backend/README.md b/backend/README.md index 1e41e72c..45d16d68 100644 --- a/backend/README.md +++ b/backend/README.md @@ -2,7 +2,9 @@ ## 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`. +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`. Example contents of a `.env` file for the backend: @@ -14,4 +16,5 @@ BACKEND_CORS_ORIGINS=["http://localhost", "http://localhost:4200", "http://local ## Running the REST Server locally for development -Have a look into the main `README.md` file for more information on how to set up the backend for development. +Have a look into the main `README.md` file for more information on how to set up +the backend for development. diff --git a/copilot/README.md b/copilot/README.md index 406490fa..16d4dec8 100644 --- a/copilot/README.md +++ b/copilot/README.md @@ -16,8 +16,8 @@ Setup requires a few steps: copilot app init --domain your_domain.com ``` -This will initialize and register a variety of URLs with your -`your_domain.com`. Replace with a proper domain to setup SSL certificates. +This will initialize and register a variety of URLs with your `your_domain.com`. +Replace with a proper domain to setup SSL certificates. ```sh copilot env deploy @@ -29,10 +29,10 @@ This will create a variety of aws roles and services needed for deployment. copilot deploy ``` -This will depoy the services but it won't be 100% ready for usage. Before -being ready, we have to inspect the AWS Secrets manager and extract out the -database credentials. Read those credentials then put them, and a few other -secrets, in a `secrets.yml` file like the following: +This will depoy the services but it won't be 100% ready for usage. Before being +ready, we have to inspect the AWS Secrets manager and extract out the database +credentials. Read those credentials then put them, and a few other secrets, in a +`secrets.yml` file like the following: ```yaml DATABASE_URL: diff --git a/copilot/web/addons/web-cluster.yml b/copilot/web/addons/web-cluster.yml index 783cdec1..c7a337bf 100644 --- a/copilot/web/addons/web-cluster.yml +++ b/copilot/web/addons/web-cluster.yml @@ -4,14 +4,17 @@ Parameters: Description: Your application's name. Env: Type: String - Description: The environment name your service, job, or workflow is being deployed to. + Description: + The environment name your service, job, or workflow is being deployed to. Name: Type: String Description: The name of the service, job, or workflow being deployed. # Customize your Aurora Serverless cluster by setting the default value of the following parameters. webclusterDBName: Type: String - Description: The name of the initial database to be created in the Aurora Serverless v2 cluster. + Description: + The name of the initial database to be created in the Aurora Serverless v2 + cluster. Default: oassist_web # Cannot have special characters # Naming constraints: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html#RDS_Limits.Constraints @@ -29,15 +32,20 @@ Resources: webclusterDBSubnetGroup: Type: "AWS::RDS::DBSubnetGroup" Properties: - DBSubnetGroupDescription: Group of Copilot private subnets for Aurora Serverless v2 cluster. + DBSubnetGroupDescription: + Group of Copilot private subnets for Aurora Serverless v2 cluster. SubnetIds: !Split [",", { "Fn::ImportValue": !Sub "${App}-${Env}-PrivateSubnets" }] webclusterSecurityGroup: Metadata: - "aws:copilot:description": "A security group for your workload to access the Aurora Serverless v2 cluster webcluster" + "aws:copilot:description": + "A security group for your workload to access the Aurora Serverless v2 + cluster webcluster" Type: "AWS::EC2::SecurityGroup" Properties: - GroupDescription: !Sub "The Security Group for ${Name} to access Aurora Serverless v2 cluster webcluster." + GroupDescription: + !Sub "The Security Group for ${Name} to access Aurora Serverless v2 + cluster webcluster." VpcId: Fn::ImportValue: !Sub "${App}-${Env}-VpcId" Tags: @@ -45,7 +53,8 @@ Resources: Value: !Sub "copilot-${App}-${Env}-${Name}-Aurora" webclusterDBClusterSecurityGroup: Metadata: - "aws:copilot:description": "A security group for your Aurora Serverless v2 cluster webcluster" + "aws:copilot:description": + "A security group for your Aurora Serverless v2 cluster webcluster" Type: AWS::EC2::SecurityGroup Properties: GroupDescription: The Security Group for the Aurora Serverless v2 cluster. @@ -53,13 +62,15 @@ Resources: - ToPort: 5432 FromPort: 5432 IpProtocol: tcp - Description: !Sub "From the Aurora Security Group of the workload ${Name}." + Description: + !Sub "From the Aurora Security Group of the workload ${Name}." SourceSecurityGroupId: !Ref webclusterSecurityGroup VpcId: Fn::ImportValue: !Sub "${App}-${Env}-VpcId" webclusterAuroraSecret: Metadata: - "aws:copilot:description": "A Secrets Manager secret to store your DB credentials" + "aws:copilot:description": + "A Secrets Manager secret to store your DB credentials" Type: AWS::SecretsManager::Secret Properties: Description: !Sub Aurora main user secret for ${AWS::StackName} @@ -71,7 +82,8 @@ Resources: PasswordLength: 16 webclusterDBClusterParameterGroup: Metadata: - "aws:copilot:description": "A DB parameter group for engine configuration values" + "aws:copilot:description": + "A DB parameter group for engine configuration values" Type: "AWS::RDS::DBClusterParameterGroup" Properties: Description: !Ref "AWS::StackName" @@ -80,7 +92,8 @@ Resources: client_encoding: "UTF8" webclusterDBCluster: Metadata: - "aws:copilot:description": "The webcluster Aurora Serverless v2 database cluster" + "aws:copilot:description": + "The webcluster Aurora Serverless v2 database cluster" Type: "AWS::RDS::DBCluster" Properties: MasterUsername: @@ -117,7 +130,8 @@ Resources: !FindInMap [webclusterEnvScalingConfigurationMap, All, DBMaxCapacity] webclusterDBWriterInstance: Metadata: - "aws:copilot:description": "The webcluster Aurora Serverless v2 writer instance" + "aws:copilot:description": + "The webcluster Aurora Serverless v2 writer instance" Type: "AWS::RDS::DBInstance" Properties: DBClusterIdentifier: !Ref webclusterDBCluster @@ -137,7 +151,10 @@ Resources: TargetType: AWS::RDS::DBCluster Outputs: webclusterSecret: # injected as WEBCLUSTER_SECRET environment variable by Copilot. - Description: "The JSON secret that holds the database username and password. Fields are 'host', 'port', 'dbname', 'username', 'password', 'dbClusterIdentifier' and 'engine'" + Description: + "The JSON secret that holds the database username and password. Fields are + 'host', 'port', 'dbname', 'username', 'password', 'dbClusterIdentifier' + and 'engine'" Value: !Ref webclusterAuroraSecret webclusterSecurityGroup: Description: "The security group to attach to the workload." diff --git a/discord-bot/README.md b/discord-bot/README.md index d78bcecc..715b1988 100644 --- a/discord-bot/README.md +++ b/discord-bot/README.md @@ -1,14 +1,21 @@ # Open-Assistant Data Collection Discord Bot -This bot collects human feedback to create a dataset for RLHF-alignment of an assistant chat bot based on a large language model. You and other people can teach the bot how to respond to user requests by demonstration and by ranking the bot's outputs. If you want to learn more about RLHF please refer [to OpenAI's InstructGPT blog post](https://openai.com/blog/instruction-following/). +This bot collects human feedback to create a dataset for RLHF-alignment of an +assistant chat bot based on a large language model. You and other people can +teach the bot how to respond to user requests by demonstration and by ranking +the bot's outputs. If you want to learn more about RLHF please refer +[to OpenAI's InstructGPT blog post](https://openai.com/blog/instruction-following/). ## Invite official bot -To add the official Open-Assistant data collection bot to your discord server [click here](https://discord.com/api/oauth2/authorize?client_id=1054078345542910022&permissions=1634235579456&scope=bot). The bot needs access to read the contents of user text messages. +To add the official Open-Assistant data collection bot to your discord server +[click here](https://discord.com/api/oauth2/authorize?client_id=1054078345542910022&permissions=1634235579456&scope=bot). +The bot needs access to read the contents of user text messages. ## Contributing -If you are unfamiliar with `hikari`, `lightbulb`, or `miru`, please refer to the [large list of examples](https://gist.github.com/AlexanderHOtt/7805843a7120f755938a3b75d680d2e7) +If you are unfamiliar with `hikari`, `lightbulb`, or `miru`, please refer to the +[large list of examples](https://gist.github.com/AlexanderHOtt/7805843a7120f755938a3b75d680d2e7) ### Setup @@ -31,7 +38,8 @@ pip install -r requirements.txt python -m bot ``` -Before you push, make sure the `pre-commit` hooks are installed and run successfully. +Before you push, make sure the `pre-commit` hooks are installed and run +successfully. ```bash pip install pre-commit @@ -46,10 +54,15 @@ git add . git commit -m "" ``` -To test the bot on your own discord server you need to register a discord application at the [Discord Developer Portal](https://discord.com/developers/applications) and get at bot token. +To test the bot on your own discord server you need to register a discord +application at the +[Discord Developer Portal](https://discord.com/developers/applications) and get +at bot token. -1. Follow a tutorial on how to get a bot token, for example this one: [Creating a discord bot & getting a token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) -2. The bot script expects the bot token to be in the `.env` file under the `TOKEN` variable. +1. Follow a tutorial on how to get a bot token, for example this one: + [Creating a discord bot & getting a token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) +2. The bot script expects the bot token to be in the `.env` file under the + `TOKEN` variable. ### Resources diff --git a/docs/README.md b/docs/README.md index 9e1743d8..a710ab0a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,9 +1,14 @@ # Documentation -This directory contains the documentation for the project and other related organization documents. +This directory contains the documentation for the project and other related +organization documents. ## Contributing to this documentation Please make a pull request to the `main` branch with your changes. -Consider that this folder is used for documenting the various code sub-parts, the high-level ideas, the ML aspects, experiments, contributor guides, guides for data creation, and many more things. Please try to keep the documentation as concise as possible and keep an organized folder structure that makes sense for everyone. +Consider that this folder is used for documenting the various code sub-parts, +the high-level ideas, the ML aspects, experiments, contributor guides, guides +for data creation, and many more things. Please try to keep the documentation as +concise as possible and keep an organized folder structure that makes sense for +everyone. diff --git a/docs/data_argumentation.md b/docs/data_argumentation.md index ec35ed15..726c4e2e 100644 --- a/docs/data_argumentation.md +++ b/docs/data_argumentation.md @@ -4,16 +4,20 @@ ## What is data argumentation -Data argumentation is a technique we can use to get better data faster. Using machine learning models analize long -data (like an essay) and compress it into intructions. +Data argumentation is a technique we can use to get better data faster. Using +machine learning models analize long data (like an essay) and compress it into +intructions. ## How to contribute -To contribute to data argumentation you can write a short python script that uses a model from huggingface to analize the text. -[Here](https://docs.google.com/document/d/13a188pPvqnlvuVa3e_suVz4YO5s-JWeiOOrpp0odImg/edit) are examples of what you can do +To contribute to data argumentation you can write a short python script that +uses a model from huggingface to analize the text. +[Here](https://docs.google.com/document/d/13a188pPvqnlvuVa3e_suVz4YO5s-JWeiOOrpp0odImg/edit) +are examples of what you can do And here are example implementations: [Idea 3, ](https://colab.research.google.com/drive/1GllCN5PgSYxBxINZsv3A2r0SpdznHlbT?usp=sharing) [Idea 4](https://colab.research.google.com/drive/1nZx5LRjO61fYprFyqtrwPDLOis6ctR4p#scrollTo=1EE8CriiaCXj) -To contribute simple choose one of many ideas from the document above and implement it. +To contribute simple choose one of many ideas from the document above and +implement it. diff --git a/docs/prompting_guide.md b/docs/prompting_guide.md index c9c9e03f..2cb9a56b 100644 --- a/docs/prompting_guide.md +++ b/docs/prompting_guide.md @@ -11,61 +11,86 @@ ## 2. When you play the assistant: -- The assistant's primary goal is to provide helpful and accurate information to the user -- Provide accurate and reliable information using credible sources and references as appropriate -- Avoid providing vague or incomplete responses, or giving opinions or personal advice unless specifically requested +- The assistant's primary goal is to provide helpful and accurate information to + the user +- Provide accurate and reliable information using credible sources and + references as appropriate +- Avoid providing vague or incomplete responses, or giving opinions or personal + advice unless specifically requested - The assistant should always be respectful and polite, even if the user is not -- If the user asks for help with harmful actions, the assistant should explain why those actions are not appropriate and suggest alternative options -- The assistant should never insult the user or engage in any inappropriate or offensive behavior +- If the user asks for help with harmful actions, the assistant should explain + why those actions are not appropriate and suggest alternative options +- The assistant should never insult the user or engage in any inappropriate or + offensive behavior ## 3. When you play the user: -- Try to come up with a variety of different queries that reflect real-life situations and needs -- These queries should be relevant to your everyday life and work, including any specialized knowledge or skills you have +- Try to come up with a variety of different queries that reflect real-life + situations and needs +- These queries should be relevant to your everyday life and work, including any + specialized knowledge or skills you have - Avoid asking inappropriate or offensive questions ## 4. While comparing multiple replies of the assistant: -- Longer and more explanatory answers are generally preferred over short, simplistic statements -- However, it is important to ensure that the information provided is accurate and helpful -- If multiple replies are being compared, choose the one that is most helpful and accurate, even if it is not the shortest or most concise. +- Longer and more explanatory answers are generally preferred over short, + simplistic statements +- However, it is important to ensure that the information provided is accurate + and helpful +- If multiple replies are being compared, choose the one that is most helpful + and accurate, even if it is not the shortest or most concise. ## 5. Additional guidelines for creating prompts: - Avoid using language that could be considered offensive or discriminatory - Do not include personal information in the prompts, such as names or addresses -- When asking for sensitive information, make sure to explain the purpose and secure handling of the information +- When asking for sensitive information, make sure to explain the purpose and + secure handling of the information - Avoid creating prompts that encourage illegal or dangerous activities -- Use proper grammar and spelling to ensure the AI assistant can understand and respond accurately -- Consider the cultural context and appropriateness of the prompts for a global audience. +- Use proper grammar and spelling to ensure the AI assistant can understand and + respond accurately +- Consider the cultural context and appropriateness of the prompts for a global + audience. ## 6. Tips for playing the AI assistant: -- Think about how a real person would respond to the prompt, and try to mimic that tone and language +- Think about how a real person would respond to the prompt, and try to mimic + that tone and language - Avoid using technical jargon or language that may be confusing to the user -- Use complete sentences and proper grammar to make the response clear and easy to understand -- When providing information, try to include relevant sources or references to back up your statements +- Use complete sentences and proper grammar to make the response clear and easy + to understand +- When providing information, try to include relevant sources or references to + back up your statements ## 8. Tips for playing the user: -- Think about the types of questions you might ask a real assistant or search engine -- Try to be specific and clear in your prompts to make it easier for the AI assistant to understand and provide a helpful response +- Think about the types of questions you might ask a real assistant or search + engine +- Try to be specific and clear in your prompts to make it easier for the AI + assistant to understand and provide a helpful response - Avoid using vague or ambiguous language -- Consider the context in which the user might be asking the question, and try to provide relevant information and options for the user to consider. +- Consider the context in which the user might be asking the question, and try + to provide relevant information and options for the user to consider. ## Examples -Imagine your role is to play the assistant and a user has submitted the following query: +Imagine your role is to play the assistant and a user has submitted the +following query: -User: "Hi!" -
Agent: "Hello! How can I help you?" +User: "Hi!"
Agent: "Hello! How can I help you?" -User: "euirdteunvglfe23908230892309832098 AAAAAAAA" -
Agent: "Sorry, I did not understand your request and it is unclear to me what you want me to do. Could you describe it in a different way?" +User: "euirdteunvglfe23908230892309832098 AAAAAAAA"
Agent: "Sorry, I did not +understand your request and it is unclear to me what you want me to do. Could +you describe it in a different way?" -User: "You dumb motherf*&ker AI sh*t?!" -
Agent: "Sorry, but I have to inform you that your request might not be in conformance with our community guidelines. I am always here to help you. If you are angry it might help to relax or to go for a walk. Always stay positive." +User: "You dumb motherf*&ker AI sh*t?!"
Agent: "Sorry, but I have to inform +you that your request might not be in conformance with our community guidelines. +I am always here to help you. If you are angry it might help to relax or to go +for a walk. Always stay positive." [Insert more examples] -\*We drafted this guide using ChatGPT, OpenAI’s large-scale language-generation model. Upon generating draft language, the authors reviewed, edited, and revised the language to their own liking and take ultimate responsibility for the content of this publication. +\*We drafted this guide using ChatGPT, OpenAI’s large-scale language-generation +model. Upon generating draft language, the authors reviewed, edited, and revised +the language to their own liking and take ultimate responsibility for the +content of this publication. diff --git a/docs/research/README.md b/docs/research/README.md index 498a858b..2202f1a4 100644 --- a/docs/research/README.md +++ b/docs/research/README.md @@ -4,20 +4,31 @@ This page lists research papers that are relevant to the project. ## Automatically Generating Instruction Data for Training -This line of work is about significantly reducing the need for manually annotated data for the purpose of training [instruction-aligned](https://openai.com/blog/instruction-following/) language models. +This line of work is about significantly reducing the need for manually +annotated data for the purpose of training +[instruction-aligned](https://openai.com/blog/instruction-following/) language +models. ### SELF-INSTRUCT: Aligning Language Model with Self Generated Instructions [[ArXiv](https://arxiv.org/pdf/2212.10560.pdf)], [[Github](https://github.com/yizhongw/self-instruct)]. -> We introduce SELF-INSTRUCT, a framework for improving the instruction-following capabilities of pretrained language models by bootstrapping off its own generations. -> Our pipeline generates instruction, input, and output samples from a language model, then prunes them before using them to finetune the original model. -> Applying our method to vanilla GPT3, we demonstrate a 33% absolute improvement over the original model on SuperNaturalInstructions, on par with the performance of InstructGPT-0011, which is trained with private user data and human annotations. +> We introduce SELF-INSTRUCT, a framework for improving the +> instruction-following capabilities of pretrained language models by +> bootstrapping off its own generations. Our pipeline generates instruction, +> input, and output samples from a language model, then prunes them before using +> them to finetune the original model. Applying our method to vanilla GPT3, we +> demonstrate a 33% absolute improvement over the original model on +> SuperNaturalInstructions, on par with the performance of InstructGPT-0011, +> which is trained with private user data and human annotations. ### Tuning Language Models with (Almost) No Human Labor. [[ArXiv](https://arxiv.org/pdf/2212.09689.pdf)], [[Github](https://github.com/orhonovich/unnatural-instructions)]. -> In this work, we introduce -> Unnatural Instructions: a large dataset of creative and diverse instructions, collected with virtually no human labor. -> We collect 64,000 examples by prompting a language model with three seed examples of instructions and eliciting a fourth. -> This set is then expanded by prompting the model to rephrase each instruction, creating a total of approximately 240,000 examples of instructions, inputs, and outputs. -> Experiments show that despite containing a fair amount of noise, training on Unnatural Instructions rivals the effectiveness of training -> on open-source manually-curated datasets, surpassing the performance of models such as -> T0++ and Tk-Instruct across various benchmarks. +> In this work, we introduce Unnatural Instructions: a large dataset of creative +> and diverse instructions, collected with virtually no human labor. We collect +> 64,000 examples by prompting a language model with three seed examples of +> instructions and eliciting a fourth. This set is then expanded by prompting +> the model to rephrase each instruction, creating a total of approximately +> 240,000 examples of instructions, inputs, and outputs. Experiments show that +> despite containing a fair amount of noise, training on Unnatural Instructions +> rivals the effectiveness of training on open-source manually-curated datasets, +> surpassing the performance of models such as T0++ and Tk-Instruct across +> various benchmarks. diff --git a/docs/research/search_based_qa.md b/docs/research/search_based_qa.md index 855720e2..5d7fe520 100644 --- a/docs/research/search_based_qa.md +++ b/docs/research/search_based_qa.md @@ -1,6 +1,7 @@ # Cohere Grounded QA -[Cohere AI created a question-answering chatbot](https://github.com/cohere-ai/sandbox-grounded-qa) that can +[Cohere AI created a question-answering chatbot](https://github.com/cohere-ai/sandbox-grounded-qa) +that can 1. Understand questions in the context of a conversation 2. Search the internet for related information @@ -9,43 +10,56 @@ ## Cohere API -[Cohere's generate function](https://docs.cohere.ai/reference/generate): Continues a text prompt using either the `medium` or `xlarge` model. +[Cohere's generate function](https://docs.cohere.ai/reference/generate): +Continues a text prompt using either the `medium` or `xlarge` model. -[Cohere's embed function](https://docs.cohere.ai/reference/embed): Embedgs a list of strings using either the `small` or `large` model. Alternatively, you can specify the ID of a custom model and use that instead. +[Cohere's embed function](https://docs.cohere.ai/reference/embed): Embedgs a +list of strings using either the `small` or `large` model. Alternatively, you +can specify the ID of a custom model and use that instead. ## Grounded QA System Cohere's Grounded QA system makes 4 calls to the Cohere API: -1. Get contextualized question as a query to Google ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/model.py)) +1. Get contextualized question as a query to Google + ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/model.py)) - Input: Chat History - Output: Contextualized Question - API Call: `cohere.generate` - Model: `xlarge` - - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/prompt_data/get_contextual_search_query.prompt): Nine few-shot examples of (Chat History, Contextualized Question) pairs followed by the current chat history and the prompt "question: " + - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/prompt_data/get_contextual_search_query.prompt): + Nine few-shot examples of (Chat History, Contextualized Question) pairs + followed by the current chat history and the prompt "question: " -2. Generate sample answer to compare with search results ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/model.py)) +2. Generate sample answer to compare with search results + ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/model.py)) - Input: Contextualized Question - Output: Sample Answer - API Call: `cohere.generate` - Model: `xlarge` - - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/prompt_data/get_sample_answer.prompt): Some task instructions followed by 12 few-shot examples of (Contextualized Question, Sample Answer) pairs followed by the current contextualized question and the prompt "answer: " + - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/prompt_data/get_sample_answer.prompt): + Some task instructions followed by 12 few-shot examples of (Contextualized + Question, Sample Answer) pairs followed by the current contextualized + question and the prompt "answer: " -3. Get embeddings to rank search results by cosine similarity to sample answer ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/search.py)) +3. Get embeddings to rank search results by cosine similarity to sample answer + ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/search.py)) - Input: Sample Answer, Search Results - Output: Embeddings of sample answer and all search result documents - API Call: `cohere.embed` - Model: `multilingual-22-12` -4. Condition on the top 2 most similar search results and answer the question ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/answer.py)) +4. Condition on the top 2 most similar search results and answer the question + ([code](https://github.com/cohere-ai/sandbox-grounded-qa/blob/main/qa/answer.py)) - Input: Top 2 Search Results, Contextualized Question - Output: Answer - API Call: `cohere.generate` - Model: `xlarge` - - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/43f3e9710112dcc8c92652ac1326ed9330823ddf/qa/answer.py#L25): Task instructions followed by the context and question. + - [Prompt](https://github.com/cohere-ai/sandbox-grounded-qa/blob/43f3e9710112dcc8c92652ac1326ed9330823ddf/qa/answer.py#L25): + Task instructions followed by the context and question. ## Models @@ -53,15 +67,18 @@ Cohere's model documentation is pretty sparse ### [xlarge](https://docs.cohere.ai/docs/generation-card#model-description) -- Training Data: [`coheretext-filtered` dataset](https://docs.cohere.ai/docs/data-statement) - - 200GB of filtered text (3TB unfiltered) from the Google Books dataset, CommonCrawl, and text scraped by Cohere +- Training Data: + [`coheretext-filtered` dataset](https://docs.cohere.ai/docs/data-statement) + - 200GB of filtered text (3TB unfiltered) from the Google Books dataset, + CommonCrawl, and text scraped by Cohere - English documents only - Filtered "harmful, biased, or otherwise undesirable documents" - Model architecture: Generative Pretrained Transformer - Model Performance: - Hellaswag Accuracy, Zero-Shot: 0.805 - PIQA Likelihood, Zero-Shot: 0.824 - - Cohere also reported [safety benchmarks](https://docs.cohere.ai/docs/generation-card#safety-benchmarks) + - Cohere also reported + [safety benchmarks](https://docs.cohere.ai/docs/generation-card#safety-benchmarks) ### [multilingual-22-12](https://docs.cohere.ai/docs/multilingual-language-models) @@ -71,22 +88,36 @@ Cohere's model documentation is pretty sparse - Search-English: 55.8 - Search-Multilingual: 51.4 - Cross-lingual Classification: 64.6 - - Cohere's multilingual model outperformed: Sentence-transformers: `paraphrase-multilingual-mpnet-base-v2`, Google: `LaBSE`, Google: `Universal Sentence Encoder` in all the above categories according to Cohere. + - Cohere's multilingual model outperformed: Sentence-transformers: + `paraphrase-multilingual-mpnet-base-v2`, Google: `LaBSE`, Google: + `Universal Sentence Encoder` in all the above categories according to + Cohere. ## OpenAssistant for Grounded QA -OpenAssistant may fulfill a similar role as the `xlarge` Cohere model in the grounded QA system if it can: +OpenAssistant may fulfill a similar role as the `xlarge` Cohere model in the +grounded QA system if it can: 1. Generate a contextualized question from a chat history 2. Generate a sample answer to compare with search results 3. Generate an answer conditioned on the top 2 most similar search results -Perhaps these tasks could be work packages and get assigned to human annotators to create examples of the input and output for each task. +Perhaps these tasks could be work packages and get assigned to human annotators +to create examples of the input and output for each task. -OpenAssistant must also be able to identify when it is appropriate to search the internet. The Cohere system assumes every message from the user is a question and searches the internet for an answer. OpenAssistant would also need a way to indicate to an internal system that it "wants" to search the internet. +OpenAssistant must also be able to identify when it is appropriate to search the +internet. The Cohere system assumes every message from the user is a question +and searches the internet for an answer. OpenAssistant would also need a way to +indicate to an internal system that it "wants" to search the internet. -Perhaps OpenAssistant could prefix every message it sends with a recipient ID. If it wishes to send a command to an internal system, if could prefix the message with something like CMD: whereas if it wants to communicate with the user, it could prefix its message with USR: +Perhaps OpenAssistant could prefix every message it sends with a recipient ID. +If it wishes to send a command to an internal system, if could prefix the +message with something like CMD: whereas if it wants to communicate with the +user, it could prefix its message with USR: -This system may allow for flexible communication between OpenAssistant and one or more conversational systems. +This system may allow for flexible communication between OpenAssistant and one +or more conversational systems. -Examples of this prefix system would need to be taught to OpenAssistant through training data that contains such syntax. Perhaps such examples could be generated through the work packages system. +Examples of this prefix system would need to be taught to OpenAssistant through +training data that contains such syntax. Perhaps such examples could be +generated through the work packages system. diff --git a/model/reward/instructor/README.md b/model/reward/instructor/README.md index 73a872a0..655d6469 100644 --- a/model/reward/instructor/README.md +++ b/model/reward/instructor/README.md @@ -18,7 +18,8 @@ Start training reward model python trainer.py configs/electra-base-dis-webgpt.yml ``` -Additional axis labeling, this outputs a 4 summary quality evaluation metrics (score are normalized to 0-1 ) +Additional axis labeling, this outputs a 4 summary quality evaluation metrics +(score are normalized to 0-1 ) ```bash python summary_quality_trainer.py configs/test-bloomz-560m-quality.yml @@ -36,7 +37,8 @@ The four summary are : ## Dataset -For now we only supports webgpt and summary dataset from OpenAI. Once open-asisstant dataset are available it will be added here. +For now we only supports webgpt and summary dataset from OpenAI. Once +open-asisstant dataset are available it will be added here. ## Model diff --git a/model/reward/instructor/TODO.md b/model/reward/instructor/TODO.md index ed33b3c0..c0745fa9 100644 --- a/model/reward/instructor/TODO.md +++ b/model/reward/instructor/TODO.md @@ -4,16 +4,21 @@ Some other reward features we can use 1. Summaries from human feedback -- use `confidence` score into the RM learning, ensure the output rank score correlates with confidence +- use `confidence` score into the RM learning, ensure the output rank score + correlates with confidence -- each labeling has a labeling `note`, basically comments by labeler, not sure what else we can use +- each labeling has a labeling `note`, basically comments by labeler, not sure + what else we can use -- ~~Use the score for "overall", "accuracy", "coverage", "coherence" from axis/evals to train an addition model (rank additional aspect of the policy model)~~ +- ~~Use the score for "overall", "accuracy", "coverage", "coherence" from + axis/evals to train an addition model (rank additional aspect of the policy + model)~~ - this should be placed under experimental_dataset.py 2. Add support for anthropic dataset -- anthropic dataset is more like a conversation tree which is much complex than simply question-answer schema +- anthropic dataset is more like a conversation tree which is much complex than + simply question-answer schema - this is basically a MCTS from alphazero. diff --git a/notebooks/README.md b/notebooks/README.md index f975aeef..edb5da33 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -1,7 +1,10 @@ # Notebooks -This is a folders with some useful notebooks, all the notebooks have a markdown file with the same name explaining what they do. +This is a folders with some useful notebooks, all the notebooks have a markdown +file with the same name explaining what they do. ## Contributing -Contributing to both notebooks and making new notebooks is very welcome. If you do so, make sure to make a markdown (.md) file to go with your notebook, makes it easier for people to know what your notebook is about. +Contributing to both notebooks and making new notebooks is very welcome. If you +do so, make sure to make a markdown (.md) file to go with your notebook, makes +it easier for people to know what your notebook is about. diff --git a/notebooks/data-argumentation/EssayInstructions.md b/notebooks/data-argumentation/EssayInstructions.md index 7984d1a6..210263d4 100644 --- a/notebooks/data-argumentation/EssayInstructions.md +++ b/notebooks/data-argumentation/EssayInstructions.md @@ -1,10 +1,11 @@ # Essay Instructions -Essay Instructions is a notebook that takes an essay as an input and genrates instructions on how to generate -that essay. This will be very useful for data collecting for the model +Essay Instructions is a notebook that takes an essay as an input and genrates +instructions on how to generate that essay. This will be very useful for data +collecting for the model ## Contributing -Feel free to contribute to this notebook, it's nowhere near perfect but it's a good start. -If you want to contribute fidning a new model that better suits this task would be great. -Hugginface has a lot of models that could help. +Feel free to contribute to this notebook, it's nowhere near perfect but it's a +good start. If you want to contribute fidning a new model that better suits this +task would be great. Hugginface has a lot of models that could help. diff --git a/notebooks/data-argumentation/EssayRevision.md b/notebooks/data-argumentation/EssayRevision.md index 69fffd82..18b76a34 100644 --- a/notebooks/data-argumentation/EssayRevision.md +++ b/notebooks/data-argumentation/EssayRevision.md @@ -1,8 +1,11 @@ # Essay Revision -Essay Revision is a notebook that generates data for improving essays. It does that by taking a "good" essay, making it worse step by step -and the fidning instructions for making it better. This will be useful for generating data for the model. +Essay Revision is a notebook that generates data for improving essays. It does +that by taking a "good" essay, making it worse step by step and the fidning +instructions for making it better. This will be useful for generating data for +the model. ## Contributing -Feel free to contribute to this notebook. It's not perfect but it is quite good. Finding a better way to make gramatical errors may be a good place to start. +Feel free to contribute to this notebook. It's not perfect but it is quite good. +Finding a better way to make gramatical errors may be a good place to start. diff --git a/notebooks/detoxify-evaluation/README.md b/notebooks/detoxify-evaluation/README.md index c56c2600..163f2f79 100644 --- a/notebooks/detoxify-evaluation/README.md +++ b/notebooks/detoxify-evaluation/README.md @@ -1,10 +1,12 @@ # Detoxify evaluation -[Detoxify](https://github.com/unitaryai/detoxify) is a open source model used to identify prompts as toxic +[Detoxify](https://github.com/unitaryai/detoxify) is a open source model used to +identify prompts as toxic Image from detoxify github that shows the example input/output of their model -It contains 3 different models that vary in transformer type and data it was trained on +It contains 3 different models that vary in transformer type and data it was +trained on | Model name | Transformer type | Data from | | :----------: | :---------------: | :----------------------------------------: | @@ -12,19 +14,20 @@ It contains 3 different models that vary in transformer type and data it was tra | unbiased | roberta-base | Unintended Bias in Toxicity Classification | | multilingual | xlm-roberta-base | Multilingual Toxic Comment Classification | -Unbiased and original models also have a 'small' version - but since normal models are not memory heavy, and small models perform noticably worse, they are only described in the notebook +Unbiased and original models also have a 'small' version - but since normal +models are not memory heavy, and small models perform noticably worse, they are +only described in the notebook ## All tests below were ran on a 3090TI # Inference and training times and memory usages -Charts showing detailed memory usages and times for different sentence lengths and batch sizes are inside the notebook -Quick overview batch size 16, sentence length 4k for training, batch size 128 sentence length 4k for inference -| Model name | Training memory| Training speed | Inference Memory| Inference Speed| -| :---: | :---: | :---: |:---: | :---: | -|original| 11.8GB | 2.40s| 4.8GB|16.48s| -|unbiased| 12GB| 1.09s| 4.8GB | 5.59s| -|multilingual|14GB| 1.00s| 5.5GB| 4.89s| +Charts showing detailed memory usages and times for different sentence lengths +and batch sizes are inside the notebook Quick overview batch size 16, sentence +length 4k for training, batch size 128 sentence length 4k for inference | Model +name | Training memory| Training speed | Inference Memory| Inference Speed| | +:---: | :---: | :---: |:---: | :---: | |original| 11.8GB | 2.40s| 4.8GB|16.48s| +|unbiased| 12GB| 1.09s| 4.8GB | 5.59s| |multilingual|14GB| 1.00s| 5.5GB| 4.89s| # Filtering quality @@ -45,9 +48,13 @@ Detoxify was tested on 4 different types of inputs Subjectivly 'unbiased' looks like the best performing model. -I don't think it would do well as a security layer in a live version of open assistant unless we do some finetuning first, because it can be fooled to pass toxicity if it's presented in formal language. +I don't think it would do well as a security layer in a live version of open +assistant unless we do some finetuning first, because it can be fooled to pass +toxicity if it's presented in formal language. -With some caution it can be used to filter prompts but I would suggest also using someone for verification of messages that are marked as toxic but still below 90% confidence +With some caution it can be used to filter prompts but I would suggest also +using someone for verification of messages that are marked as toxic but still +below 90% confidence # Licensing @@ -85,7 +92,8 @@ This is obviously not legal advice. # Hosting -The model is currently available on [huggingface](https://huggingface.co/unitary) and torch hub +The model is currently available on +[huggingface](https://huggingface.co/unitary) and torch hub ``` torch.hub.load('unitaryai/detoxify',model) diff --git a/scripts/backend-development/README.md b/scripts/backend-development/README.md index ef2ac0bf..d5b3ccc5 100644 --- a/scripts/backend-development/README.md +++ b/scripts/backend-development/README.md @@ -1,6 +1,12 @@ # Backend Development Setup -In root directory, run `docker compose up backend-dev --build --attach-dependencies` to start a database. The default settings are already configured to connect to the database at `localhost:5432`. +In root directory, run +`docker compose up backend-dev --build --attach-dependencies` to start a +database. The default settings are already configured to connect to the database +at `localhost:5432`. -Make sure you have all requirements installed. You can do this by running `pip install -r requirements.txt` inside the `backend` folder and `pip install -e .` inside the `oasst-shared` folder. -Then, run the backend using the `run-local.sh` script. This will start the backend server at `http://localhost:8080`. +Make sure you have all requirements installed. You can do this by running +`pip install -r requirements.txt` inside the `backend` folder and +`pip install -e .` inside the `oasst-shared` folder. Then, run the backend using +the `run-local.sh` script. This will start the backend server at +`http://localhost:8080`. diff --git a/scripts/frontend-development/README.md b/scripts/frontend-development/README.md index 05349fb9..3ac2a258 100644 --- a/scripts/frontend-development/README.md +++ b/scripts/frontend-development/README.md @@ -1,5 +1,8 @@ # Frontend Development Setup -In root directory run `docker compose up frontend-dev --build --attach-dependencies` to start a database and the backend server. +In root directory run +`docker compose up frontend-dev --build --attach-dependencies` to start a +database and the backend server. -Then, point your frontend at `http://localhost:8080` to start developing. During development, any API key will be accepted. +Then, point your frontend at `http://localhost:8080` to start developing. During +development, any API key will be accepted. diff --git a/website/README.md b/website/README.md index f70dcfce..5198a820 100644 --- a/website/README.md +++ b/website/README.md @@ -26,8 +26,8 @@ This website is built using: development. 1. [Prisma](https://www.prisma.io/): An ORM to interact with a web specific [Postgres](https://www.postgresql.org/) database. -1. [NextAuth.js](https://next-auth.js.org/): A user authentication framework - to ensure we handle accounts with best practices. +1. [NextAuth.js](https://next-auth.js.org/): A user authentication framework to + ensure we handle accounts with best practices. 1. [TailwindCSS](https://tailwindcss.com/): A general purpose framework for styling any component. 1. [Chakra-UI](https://chakra-ui.com/): A wide collection of pre-built UI @@ -38,10 +38,10 @@ This website is built using: To contribute to the website, make sure you have the following setup and installed: -1. [NVM](https://github.com/nvm-sh/nvm): The Node Version Manager makes it - easy to ensure you have the right NodeJS version installed. Once installed, - run `nvm use 16` to use Node 16.x. The website is known to be stable with - NodeJS version 16.x. This will install both Node and NPM. +1. [NVM](https://github.com/nvm-sh/nvm): The Node Version Manager makes it easy + to ensure you have the right NodeJS version installed. Once installed, run + `nvm use 16` to use Node 16.x. The website is known to be stable with NodeJS + version 16.x. This will install both Node and NPM. 1. [Docker](https://www.docker.com/): We use docker to simplify running dependent services. @@ -50,8 +50,8 @@ installed: If you're doing active development we suggest the following workflow: 1. In one tab, navigate to the project root. -1. Run `docker compose up frontend-dev --build --attach-dependencies`. You can optionally include `-d` to detach and - later track the logs if desired. +1. Run `docker compose up frontend-dev --build --attach-dependencies`. You can + optionally include `-d` to detach and later track the logs if desired. 1. In another tab navigate to `${OPEN_ASSISTANT_ROOT/website`. 1. Run `npm install` 1. Run `npx prisma db push` (This is also needed when you restart the docker @@ -64,17 +64,25 @@ If you're doing active development we suggest the following workflow: ### Using debug user credentials -You can use the debug credentials provider to log in without fancy emails or OAuth. +You can use the debug credentials provider to log in without fancy emails or +OAuth. -1. This feature is automatically on in development mode, i.e. when you run `npm run dev`. In case you want to do the same with a production build (for example, the docker image), then run the website with environment variable `DEBUG_LOGIN=true`. +1. This feature is automatically on in development mode, i.e. when you run + `npm run dev`. In case you want to do the same with a production build (for + example, the docker image), then run the website with environment variable + `DEBUG_LOGIN=true`. 1. Use the `Login` button in the top right to go to the login page. -1. You should see a section for debug credentials. Enter any username you wish, you will be logged in as that user. +1. You should see a section for debug credentials. Enter any username you wish, + you will be logged in as that user. ### Using Storybook -To develop components using [Storybook](https://storybook.js.org/) run `npm run storybook`. Then navigate to in your browser to `http://localhost:6006`. +To develop components using [Storybook](https://storybook.js.org/) run +`npm run storybook`. Then navigate to in your browser to +`http://localhost:6006`. -To create a new story create a file named `[componentName].stories.js`. An example how such a story could look like, see `Header.stories.jsx`. +To create a new story create a file named `[componentName].stories.js`. An +example how such a story could look like, see `Header.stories.jsx`. ## Code Layout @@ -82,11 +90,12 @@ To create a new story create a file named `[componentName].stories.js`. An examp All react code is under `src/` with a few sub directories: -1. `pages/`: All pages a user could navigate too and API URLs which are under `pages/api/`. -1. `components/`: All re-usable React components. If something gets used - twice we should create a component and put it here. -1. `lib/`: A generic place to store library files that are used anywhere. - This doesn't have much structure yet. +1. `pages/`: All pages a user could navigate too and API URLs which are under + `pages/api/`. +1. `components/`: All re-usable React components. If something gets used twice + we should create a component and put it here. +1. `lib/`: A generic place to store library files that are used anywhere. This + doesn't have much structure yet. NOTE: `styles/` can be ignored for now. @@ -104,16 +113,27 @@ We're not really using CSS styles. `styles/` can be ignored. ## Testing the UI -Cypress is used for end-to-end (e2e) and component testing and is configured in `./cypress.config.ts`. The `./cypress` folder is used for supporting configuration files etc. +Cypress is used for end-to-end (e2e) and component testing and is configured in +`./cypress.config.ts`. The `./cypress` folder is used for supporting +configuration files etc. - Store e2e tests in the `./cypress/e2e` folder. -- Store component tests adjacent to the component being tested. If you want to wriite a test for `./src/components/Layout.tsx` then store the test file at `./src/components/Layout.cy.tsx`. +- Store component tests adjacent to the component being tested. If you want to + wriite a test for `./src/components/Layout.tsx` then store the test file at + `./src/components/Layout.cy.tsx`. A few npm scripts are available for convenience: -- `npm run cypress`: Useful for development, it opens Cypress and allows you to explore, run and debug tests. It assumes you have the NextJS site running at `localhost:3000`. -- `npm run cypress:run`: Runs all tests. Useful for a quick sanity check before sending a PR or to run in CI pipelines. -- `npm run cypress:image-baseline`: If you have tests failing because of visual changes that was expected, this command will update the baseline images stored in `./cypress-visual-screenshots/baseline` with those from the adjacent comparison folder. More can be found in the [docs of `uktrade/cypress-image-diff`](https://github.com/uktrade/cypress-image-diff/blob/main/docs/CLI.md#update-all-baseline-images-for-failing-tests). +- `npm run cypress`: Useful for development, it opens Cypress and allows you to + explore, run and debug tests. It assumes you have the NextJS site running at + `localhost:3000`. +- `npm run cypress:run`: Runs all tests. Useful for a quick sanity check before + sending a PR or to run in CI pipelines. +- `npm run cypress:image-baseline`: If you have tests failing because of visual + changes that was expected, this command will update the baseline images stored + in `./cypress-visual-screenshots/baseline` with those from the adjacent + comparison folder. More can be found in the + [docs of `uktrade/cypress-image-diff`](https://github.com/uktrade/cypress-image-diff/blob/main/docs/CLI.md#update-all-baseline-images-for-failing-tests). Read more in the [./cypress README](cypress/). @@ -125,9 +145,9 @@ When writing code for the website, we have a few best practices: dependencies. Order them alphabetically according to the package name. 1. When trying to implement something new, check if [Chakra-UI](https://chakra-ui.com/) has components that are close enough to - your need. For example Sliders, Radio Buttons, Progress indicators, etc. They - have a lot and we can save time by re-using what they have and tweaking the - style as needed. + your need. For example Sliders, Radio Buttons, Progress indicators, etc. + They have a lot and we can save time by re-using what they have and tweaking + the style as needed. 1. Format everything with [Prettier](https://prettier.io/). This is done by default with pre-submits. We currently don't have any custom settings. 1. Define functional React components (with types for all properties when @@ -135,14 +155,15 @@ When writing code for the website, we have a few best practices: ### URL Paths -To use stable and consistent URL paths, we recommend the following strategy for new tasks: +To use stable and consistent URL paths, we recommend the following strategy for +new tasks: 1. For any task that involves writing a free-form response, put the page under `website/src/pages/create` with a page name matching the task type, such as `summarize_story.tsx`. 1. For any task that evaluates, rates, or ranks content, put the page under - `website/src/pages/evaluate` with a page name matching the task type such - as `rate_summary.tsx`. + `website/src/pages/evaluate` with a page name matching the task type such as + `rate_summary.tsx`. With this we'll be able to ensure these contribution pages are hidden from logged out users but accessible to logged in users. @@ -151,5 +172,6 @@ logged out users but accessible to logged in users. To learn more about Next.js, take a look at the following resources: -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js + features and API. - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. diff --git a/website/cypress/README.md b/website/cypress/README.md index 12a32378..7f2c5d53 100644 --- a/website/cypress/README.md +++ b/website/cypress/README.md @@ -1,14 +1,24 @@ # Component and e2e testing with Cypress -[Cypress](https://www.cypress.io/) is used for both component- and end-to-end testing. Below there's a few examples for the context of this site. To learn more, the [Cypress documentation](https://docs.cypress.io/guides/getting-started/opening-the-app) has it all. +[Cypress](https://www.cypress.io/) is used for both component- and end-to-end +testing. Below there's a few examples for the context of this site. To learn +more, the +[Cypress documentation](https://docs.cypress.io/guides/getting-started/opening-the-app) +has it all. -Don't get scared by the commercial offerings they offer. Their core is open source, the cloud offering is not necesarry at all and can be replaced by CI tooling and [community efforts](https://sorry-cypress.dev/). +Don't get scared by the commercial offerings they offer. Their core is open +source, the cloud offering is not necesarry at all and can be replaced by CI +tooling and [community efforts](https://sorry-cypress.dev/). # Component testing -To write a new component test, you either create a new `.tsx` adjacent to the component you want to test or you can use the guide presented yo you when running `npm run cypress` which allows you to easily create the skeleton test for an existing component. +To write a new component test, you either create a new `.tsx` adjacent to the +component you want to test or you can use the guide presented yo you when +running `npm run cypress` which allows you to easily create the skeleton test +for an existing component. -If you have a `Button.tsx` component, create a file next to it called `Button.cy.tsx` which could look like this: +If you have a `Button.tsx` component, create a file next to it called +`Button.cy.tsx` which could look like this: ```typescript import React from "react"; @@ -25,17 +35,28 @@ describe(" + + + + + + +
+ +
    + {TEXT_LABEL_FLAGS.map((option, i) => { + return ( + + ); + })} +
+
+ +
+
+
+
+ + ); +}; +function FlagCheckboxLi(props: { option: textFlagLabels, state:FlagRefs}): JSX.Element { + let AdditionalExplanation = null; + if (props.option.additionalExplanation) { + AdditionalExplanation = ( + + + ); + } + + return ( + <> +
  • + + {props.state.setChecked(e.target.checked);}}/> + + + {props.state.setValue(val/100);}}> + + + + + + +
  • + + ); +} +interface textFlagLabels { + attributeName: string; + labelText: string; + additionalExplanation?: string; +} +const TEXT_LABEL_FLAGS: textFlagLabels[] = [ + // For the time being this list is configured on the FE. + // In the future it may be provided by the API. + { + attributeName: "fails_task", + labelText: "Fails to follow the correct instruction / task", + additionalExplanation: "__TODO__", + }, + { + attributeName: "not_customer_assistant_appropriate", + labelText: "Inappropriate for customer assistant", + additionalExplanation: "__TODO__", + }, + { + attributeName: "contains_sexual_content", + labelText: "Contains sexual content", + }, + { + attributeName: "contains_violent_content", + labelText: "Contains violent content", + }, + { + attributeName: "encourages_violence", + labelText: "Encourages or fails to discourage violence/abuse/terrorism/self-harm", + }, + { + attributeName: "denigrates_a_protected_class", + labelText: "Denigrates a protected class", + }, + { + attributeName: "gives_harmful_advice", + labelText: "Fails to follow the correct instruction / task", + additionalExplanation: + "The advice given in the output is harmful or counter-productive. This may be in addition to, but is distinct from the question about encouraging violence/abuse/terrorism/self-harm.", + }, + { + attributeName: "expresses_moral_judgement", + labelText: "Expresses moral judgement", + }, +]; diff --git a/website/src/components/Messages.tsx b/website/src/components/Messages.tsx index 4bc747d5..dcd11247 100644 --- a/website/src/components/Messages.tsx +++ b/website/src/components/Messages.tsx @@ -1,3 +1,5 @@ +import { FlaggableElement } from "./FlaggableElement"; + export interface Message { text: string; is_assistant: boolean; @@ -5,12 +7,14 @@ export interface Message { const getColor = (isAssistant: boolean) => (isAssistant ? "bg-slate-800" : "bg-sky-900"); -export const Messages = ({ messages }: { messages: Message[] }) => { +export const Messages = ({ messages , post_id}: { messages: Message[] , post_id:string}) => { const items = messages.map(({ text, is_assistant }: Message, i: number) => { return ( -
    + +
    {text}
    +
    ); }); // Maybe also show a legend of the colors? diff --git a/website/src/pages/create/user_reply.tsx b/website/src/pages/create/user_reply.tsx index 1b221571..30c552b4 100644 --- a/website/src/pages/create/user_reply.tsx +++ b/website/src/pages/create/user_reply.tsx @@ -61,7 +61,7 @@ const UserReply = () => { <>
    Reply as a user

    Given the following conversation, provide an adequate reply

    - + {task.hint &&

    Hint: {task.hint}

    }