Merge branch 'main' of github.com:LAION-AI/Open-Chat-GPT

This commit is contained in:
Yannic Kilcher
2023-01-02 16:38:42 +01:00
117 changed files with 1229 additions and 416 deletions
+2 -2
View File
@@ -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
+30 -1
View File
@@ -1,3 +1,31 @@
# WARNING!
#
# When making changes to auto-formatters used in pre-commit hooks, you are
# likely to cause merge conflicts with main and/or other pull requests.
# Fixing them might revert other people's work. Expect pain!
# To avoid accidental reversions and keep it easy to review, please make sure
# that changes here are in a pull request by themselves, that it consists of
# two commits:
#
# 1. The changes to this file
# 2. Changes made by running `python3 -m pre_commit run --all-files`.
#
# Then each time your pull request is blocked by a merge conflict, do the
# following steps:
#
# git reset HEAD^1 && git checkout -f # discard the change commit
# git rebase main # re-apply other people's changes
# python3 -m pre_commit run --all-files # re-run the rules
# git add . # add the newly changed files
# git commit -m 'apply pre-commit' # commit it
# git push -f # force push back to your branch
#
# Keep in mind you may have to do this a few times, as changes here may impact
# other pull requests. Try to keep it up-to-date so they can go in when it'll
# cause least disruption.
#
# /WARNING!
exclude: "build|stubs|^bot/templates/|^notebooks/.*\\.ipynb$"
default_language_version:
@@ -19,6 +47,7 @@ repos:
- id: check-case-conflict
- id: detect-private-key
- id: fix-encoding-pragma
args: ["--remove"]
- id: forbid-submodules
- id: mixed-line-ending
- id: requirements-txt-fixer
@@ -50,7 +79,7 @@ repos:
rev: v2.7.1
hooks:
- id: prettier
args: ["--write"]
args: ["--prose-wrap=always", "--write"]
- repo: local
hooks:
+80 -41
View File
@@ -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.
## Im 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,15 @@ 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.
### 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.`**
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.
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.
+5 -2
View File
@@ -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.
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from logging.config import fileConfig
import sqlmodel
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""first revision
Revision ID: 23e5fea252dd
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""v1 db structure
Revision ID: cd7de470586e
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add auth_method to person
Revision ID: 6368515778c5
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add_auth_method_to_ix_person_username
Revision ID: 0daec5f8135f
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Adds text labels table.
Revision ID: 067c4002f2d9
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add_journal_table
Revision ID: 3358eb6834e6
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""post ref for work_package
Revision ID: d24b37426857
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Added lang column for ISO-639-1 codes
Revision ID: ef0b52902560
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add collective flag to task
Revision ID: 464ec4667aae
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add field trusted api client
Revision ID: 73ce3675c1f5
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""name changes: person->user, post->message, work_package->task
Revision ID: abb47e9d145a
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""add deleted field to post
Revision ID: 8d269bc4fdbd
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from http import HTTPStatus
from pathlib import Path
from typing import Optional
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from http import HTTPStatus
from secrets import token_hex
from typing import Generator
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from fastapi import APIRouter
from oasst_backend.api.v1 import frontend_messages, frontend_users, messages, stats, tasks, text_labels, users
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from fastapi import APIRouter, Depends
from oasst_backend.api import deps
from oasst_backend.api.v1 import utils
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import datetime
from uuid import UUID
-2
View File
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
import datetime
from uuid import UUID
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from fastapi import APIRouter, Depends
from oasst_backend.api import deps
from oasst_backend.models import ApiClient
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import random
from typing import Any, Optional, Tuple
from uuid import UUID
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pydantic
from fastapi import APIRouter, Depends, HTTPException
from fastapi.security.api_key import APIKey
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import datetime
from uuid import UUID
-2
View File
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from http import HTTPStatus
from uuid import UUID
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Any, Dict, List, Optional, Union
from pydantic import AnyHttpUrl, BaseSettings, PostgresDsn, validator
-1
View File
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__all__ = []
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union
from fastapi.encoders import jsonable_encoder
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from oasst_backend.config import settings
from oasst_backend.exceptions import OasstError, OasstErrorCode
from sqlmodel import create_engine
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from enum import IntEnum
from http import HTTPStatus
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import enum
from typing import Literal, Optional
from uuid import UUID
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .api_client import ApiClient
from .journal import Journal, JournalIntegration
from .message import Message
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Optional
from uuid import UUID, uuid4
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Literal
from oasst_backend.models.payload_column_type import payload_type
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid1, uuid4
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import json
from typing import Any, Generic, Type, TypeVar
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional
from uuid import UUID
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import datetime
import random
from collections import defaultdict
+6 -6
View File
@@ -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:
+29 -12
View File
@@ -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."
+51 -11
View File
@@ -1,16 +1,57 @@
# 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%20applications.commands).
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
### Bot Setup
1. Create a new discord application at the
[Discord Developer Portal](https://discord.com/developers/applications)
1. Go to the "Bot" tab and create a new bot
1. Scroll down to "Privileged Gateway Intents" and enable the following options:
- Server Members Intent
- Presence Intent
- Message Content Intent
This page also contains the bot token, which you will need to add to the `.env`
file later.
2. Go to the "OAuth2" tab scroll to "Default Authorization Link"
3. Set "AUTHORIZATION METHOD" to "In-app Authorization"
4. Select the "bot" and "applications.commands" scopes
5. For testing and local development, it's easiest to set "BOT PERMISSIONS" to
"Administrator"
Remember to save your changes.
6. Copy the "CLIENT ID" from the top of the page and replace it in the link
below to invite your bot.
```
https://discord.com/oauth2/authorize?client_id=YOUR_ID_HERE&permissions=8&scope=bot%20applications.commands
```
### Environment Setup
To run the bot:
@@ -22,16 +63,20 @@ pip install -e .
```
```bash
cd ../discord-bot
cp .env.example .env
# edit .env and add your bot token and other values
python -V # 3.10
pip install -r requirements.txt
# in the discord-bot folder
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,11 +91,6 @@ git add .
git commit -m "<good commit message>"
```
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.
### Resources
#### Structure
-1
View File
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
"""The official Open-Assistant Discord Bot."""
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Entry point for the bot."""
import logging
import os
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""API Client for interacting with the OASST backend."""
import enum
import typing as t
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Bot logic."""
from datetime import datetime
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Database schemas."""
import typing as t
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Extensions for the bot.
See: https://hikari-lightbulb.readthedocs.io/en/latest/guides/extensions.html
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Guild settings."""
import hikari
import lightbulb
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Hot reload plugin."""
from glob import glob
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Hot reload plugin."""
import typing as t
from datetime import datetime
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Task plugin for testing different data collection methods."""
# TODO: Delete this once user input method has been decided for final bot.
import asyncio
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Work plugin for collecting user data."""
import asyncio
import typing as t
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Configuration for the bot."""
from pydantic import BaseSettings, Field
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Utility functions."""
import typing as t
from datetime import datetime
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Message templates for the discord bot."""
import typing
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from uuid import uuid4
import pytest
+2
View File
@@ -87,6 +87,7 @@ services:
backend:
build:
dockerfile: docker/Dockerfile.backend
context: .
image: oasst-backend
environment:
- POSTGRES_HOST=db
@@ -103,6 +104,7 @@ services:
web:
build:
dockerfile: docker/Dockerfile.website
context: .
image: oasst-web
environment:
- DATABASE_URL=postgres://postgres:postgres@webdb/oasst_web
+7 -2
View File
@@ -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.
+9 -5
View File
@@ -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.
+52 -27
View File
@@ -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!"
<br>Agent: "Hello! How can I help you?"
User: "Hi!" <br>Agent: "Hello! How can I help you?"
User: "euirdteunvglfe23908230892309832098 AAAAAAAA"
<br>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" <br>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?!"
<br>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?!" <br>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, OpenAIs 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, OpenAIs 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.
+22 -11
View File
@@ -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.
+51 -20
View File
@@ -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.
+4 -2
View File
@@ -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
+9 -4
View File
@@ -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.
+1 -2
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
classification based ranking
@@ -8,7 +7,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
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
HFSummary
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
author: theblackcat102
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
from argparse import ArgumentParser
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from experimental_dataset import DataCollatorForSummaryScore, HFSummaryQuality
from rank_datasets import DataCollatorForPairRank, HFSummary, WebGPT
from torch.utils.data import DataLoader
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
from argparse import ArgumentParser
from dataclasses import dataclass
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import re
import yaml
+5 -2
View File
@@ -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.
@@ -1,135 +1,164 @@
{
"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 todays electric and hybrid cars, and which will drive tomorrows 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 worlds 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 todays electric and hybrid cars, and which will drive \n",
"tomorrows 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 worlds \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": null,
"metadata": {
"id": "t1G-ZiHbZZ-Y"
},
"outputs": [],
"source": [
"model_name = \"snrspeaks/t5-one-line-summary\"\n",
"\n",
"from transformers import AutoModelForSeq2SeqLM, AutoTokenizer\n",
"model = AutoModelForSeq2SeqLM.from_pretrained(model_name)\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)"
],
"metadata": {
"id": "t1G-ZiHbZZ-Y"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8BARyupEemZ-"
},
"source": [
"## Results\n",
"Please at least check what is generated here, it's usually good but sometimes it's bs"
],
"metadata": {
"id": "8BARyupEemZ-"
}
]
},
{
"cell_type": "code",
"source": [
"preds = []\n",
"\n",
"for i in range(0, len(essay_paragraphs)):\n",
" input_ids = tokenizer.encode(essay_paragraphs[i], return_tensors=\"pt\", add_special_tokens=True)\n",
" generated_ids = model.generate(input_ids=input_ids,num_beams=5,max_length=35,repetition_penalty=4.5,length_penalty=1.5,early_stopping=True,num_return_sequences=1)\n",
" preds.append(tokenizer.decode(generated_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True))\n",
"\n",
"print('Write an intro paragraph to an essay called', preds[0].lower())\n",
"\n",
"for i in range(1, len(preds) - 1):\n",
" print('Write a paragraph to an essay about', preds[i].lower())\n",
"\n",
"print('Write a concluding paragraph about', preds[len(preds) - 1].lower())"
],
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -137,24 +166,61 @@
"id": "eyR58KFRae7n",
"outputId": "b8e4bc29-be89-43c3-d1bc-7e90525c0e09"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Write an intro paragraph to an essay called the rise and fall of technology\n",
"Write a paragraph to an essay about technology that drives modern autonomy, hybrid cars, hover-taxis and space cabs\n",
"Write a paragraph to an essay about luddites: why technology is a blessing?\n",
"Write a paragraph to an essay about artificial emotional intelligence\n",
"Write a paragraph to an essay about how could that be a negative?\n",
"Write a paragraph to an essay about detecting and manipulating human emotions\n",
"Write a paragraph to an essay about the rise and fall of human-client skills\n",
"Write a paragraph to an essay about changing technology will keep human beings on their toes throughout their life\n",
"Write a concluding paragraph about human inventiveness and technology\n"
]
}
"outputs": [],
"source": [
"preds = []\n",
"\n",
"for para in essay_paragraphs:\n",
" input_ids = tokenizer.encode(para, return_tensors=\"pt\", add_special_tokens=True)\n",
" generated_ids = model.generate(input_ids=input_ids,\n",
" num_beams=5,\n",
" max_length=35,\n",
" repetition_penalty=4.5,\n",
" length_penalty=1.5,\n",
" early_stopping=True,\n",
" num_return_sequences=1)\n",
" preds.append(tokenizer.decode(generated_ids[0], \n",
" skip_special_tokens=True, \n",
" clean_up_tokenization_spaces=True))\n",
"\n",
"prompts = ['Write an intro paragraph to an essay called'] + \\\n",
" ['Write a paragraph to an essay about']*len(preds[1:-1]) + \\\n",
" ['Write a concluding paragraph about']\n",
"\n",
"assert len(preds) == len(prompts)\n",
"\n",
"for prompt, pred in zip(prompts, preds):\n",
" print(prompt, pred.lower())"
]
}
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -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 generates
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 finding a new model that better suits this
task would be great. Hugginface has a lot of models that could help.
@@ -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 finding
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 grammatical errors may be a good place to start.
+21 -13
View File
@@ -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
<img src="https://raw.githubusercontent.com/unitaryai/detoxify/master/examples.png" alt="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)
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import enum
from datetime import datetime
from typing import Literal, Optional, Union
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timezone
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# setup.py for the shared python modules
from distutils.core import setup
+9 -3
View File
@@ -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`.
+5 -2
View File
@@ -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.
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import numpy as np
from scipy import log2
from scipy.integrate import nquad
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import List
import numpy as np
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from dataclasses import dataclass, replace
from typing import Any
-1
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Simple REPL frontend."""
import random
+52 -30
View File
@@ -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.
+7
View File
@@ -22,4 +22,11 @@ export default defineConfig({
getCompareSnapshotsPlugin(on, config);
},
},
env: {
MAILDEV_PROTOCOL: "http",
MAILDEV_HOST: "localhost",
MAILDEV_SMTP_PORT: "1025",
MAILDEV_API_PORT: "1080",
},
});
+83 -15
View File
@@ -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,25 +35,36 @@ describe("<Button />", () => {
## What's happening here?
First we use `cy.mount` to mount our component under test. Notive how we specify `className` and inner text - this is where we arrange our component with fake data that we could assert on later.
First we use `cy.mount` to mount our component under test. Notive how we specify
`className` and inner text - this is where we arrange our component with fake
data that we could assert on later.
In the example above, we also use `cy.get` to select the rendered `button` element. Cypress has multiple ways to [select elements](https://docs.cypress.io/guides/references/best-practices), `get` is just one of them (and often not recommended).
In the example above, we also use `cy.get` to select the rendered `button`
element. Cypress has multiple ways to
[select elements](https://docs.cypress.io/guides/references/best-practices),
`get` is just one of them (and often not recommended).
At last, we use `captureSnapshot` which is a plugin that snaps a photo of the `button` element and compares it to a baseline located in the `./cypress-visual-screenshots/baseline/` folder. If there's too many unidentical pixels between the two, it will fail the test.
At last, we use `captureSnapshot` which is a plugin that snaps a photo of the
`button` element and compares it to a baseline located in the
`./cypress-visual-screenshots/baseline/` folder. If there's too many unidentical
pixels between the two, it will fail the test.
# End-to-end (e2e) testing
e2e tests are stored in the `./cypress/e2e` folder and should be named `{page}.cy.ts` and located in a relative folder structure that mirrors the page under test.
e2e tests are stored in the `./cypress/e2e` folder and should be named
`{page}.cy.ts` and located in a relative folder structure that mirrors the page
under test.
When running `npm run cypress` and selecting e2e testing, we assume you have the NextJS site running at `localhost:3000`.
When running `npm run cypress` and selecting e2e testing, we assume you have the
NextJS site running at `localhost:3000`.
An example test from this time of writing, could look as follows:
An example test could look as follows:
```typescript
describe("signin flow", () => {
it("redirects to a confirmation page on submit of valid email address", () => {
cy.visit("/auth/signin");
cy.get(".chakra-input").type(`test@example.com{enter}`);
cy.get('[data-cy="email-address"]').type(`test@example.com{enter}`);
cy.url().should("contain", "/auth/verify");
});
});
@@ -53,10 +74,57 @@ export {};
## What's happening here?
First we use [`cy.visit`](https://docs.cypress.io/api/commands/visit) to point the browser at the desired page. It appends relative paths to the configured `baseUrl` (found in `./cypress.config.ts`).
First we use [`cy.visit`](https://docs.cypress.io/api/commands/visit) to point
the browser at the desired page. It appends relative paths to the configured
`baseUrl` (found in `./cypress.config.ts`).
Cypress will [automatically await](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Timeouts) almost anything you do, but fail if the default timeout is reached.
Cypress will
[automatically await](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Timeouts)
almost anything you do, but fail if the default timeout is reached.
Then we get the email input field and type our email address. Notice the `{enter}` keyword, this will cause Cypress to hit the return key which we expect to submit the form.
Then we get the email input field and type our email address. We find the input
field using the data-cy attribute that we added in the source code of the
element on the page.
We then assert that the URL should contain `/auth/verify`. Again the timeout will make sure we are not waiting forever, and the test will fail if we do not manage to get there in a reasonable time.
```jsx
<Input data-cy="email-address" placeholder="Email Address" />
```
Using `data-cy` is how we ensure that selecting the element is robust to changes
in page design or function and is one of the
[best practices recommended by Cypress](https://docs.cypress.io/guides/references/best-practices#Selecting-Elements).
Next we call `type()` to use the keyboard, cypress will automatically focus the
element and send the keypress events. Notice the `{enter}` keyword, this will
cause Cypress to hit the return key which we expect to submit the form.
We then assert that the URL should contain `/auth/verify`. Again the timeout
will make sure we are not waiting forever, and the test will fail if we do not
manage to get there in a reasonable time.
## Authenticating in e2e tests
For end-to-end tests almost every test will need to first sign in to the
website. To make this easier we have a custom command for Cypress that makes
logging in with an email address a single command, `cy.signInWithEmail()`.
```typescript
describe("replying as the assistant", () => {
it("completes the current task on submit", () => {
cy.signInWithEmail("cypress@example.com");
cy.visit("/create/assistant_reply");
cy.get('[data-cy="reply"').type(
"You need to run pre-commit to make the reviewer happy."
);
cy.get('[data-cy="submit"]').click();
});
});
```
In this example we sign in as `cypress@example.com` before visiting the
`/create/assistant_reply` page that is only available when authenticated. We can
then continue on with our test as normal. Note: using `cy.signInWithEmail()`
requires that the maildev is running, which should have been started as part of
the `docker compose up` command that is required to do any end-to-end testing.
+31 -2
View File
@@ -1,10 +1,39 @@
import { faker } from "@faker-js/faker";
describe("signin flow", () => {
it("redirects to a confirmation page on submit of valid email address", () => {
cy.visit("/auth/signin");
cy.get(".chakra-input").type(`test@example.com`);
cy.get(".chakra-stack > .chakra-button").click();
cy.get('[data-cy="email-address"]').type(`test@example.com`);
cy.get('[data-cy="signin-email-button"]').click();
cy.url().should("contain", "/auth/verify");
});
it("emails a login link to the user when signing in with email", () => {
// Use random email to avoid possibility of tests passing just due to other tests or previous runs also causing emails to be sent
const emailAddress = faker.internet.email();
cy.log("emailAddress", emailAddress);
cy.request("GET", "/api/auth/csrf")
.then((response) => {
const csrfToken = response.body.csrfToken;
cy.request("POST", "/api/auth/signin/email", {
callbackUrl: "/",
email: emailAddress,
csrfToken,
json: "true",
});
})
.then((response) => {
cy.signInUsingEmailedLink(emailAddress).then(() => {
cy.get('[data-cy="username"]').should("exist");
});
});
});
it("shows the logged in users email address if logged in with email", () => {
const emailAddress = "user@example.com";
cy.signInWithEmail(emailAddress);
// The user will only see the email address if the window is wide enough, not technically required as even when hidden this will find it in the page.
cy.viewport(1920, 1000);
cy.contains('[data-cy="username"]', emailAddress);
});
});
export {};
@@ -0,0 +1,26 @@
import { faker } from "@faker-js/faker";
describe("replying as the assistant", () => {
it("completes the current task on submit and on request shows a new task", () => {
cy.signInWithEmail("cypress@example.com");
cy.visit("/create/assistant_reply");
cy.get('[data-cy="task-id"').then((taskIdElement) => {
const taskId = taskIdElement.text();
const reply = faker.lorem.sentence();
cy.log("reply", reply);
cy.get('[data-cy="reply"').type(reply);
cy.get('[data-cy="submit"]').click();
cy.get('[data-cy="next-task"]').click();
cy.get('[data-cy="task-id"').should((taskIdElement) => {
expect(taskIdElement.text()).not.to.eq(taskId);
});
});
});
});
export {};
@@ -0,0 +1,26 @@
import { faker } from "@faker-js/faker";
describe("replying as the prompter", () => {
it("completes the current task on submit and on request shows a new task", () => {
cy.signInWithEmail("cypress@example.com");
cy.visit("/create/user_reply");
cy.get('[data-cy="task-id"').then((taskIdElement) => {
const taskId = taskIdElement.text();
const reply = faker.lorem.sentence();
cy.log("reply", reply);
cy.get('[data-cy="reply"').type(reply);
cy.get('[data-cy="submit"]').click();
cy.get('[data-cy="next-task"]').click();
cy.get('[data-cy="task-id"').should((taskIdElement) => {
expect(taskIdElement.text()).not.to.eq(taskId);
});
});
});
});
export {};
@@ -0,0 +1,30 @@
describe("ranking prompter replies", () => {
it("completes the current task on submit and on request shows a new task", () => {
cy.signInWithEmail("cypress@example.com");
cy.visit("/evaluate/rank_user_replies");
cy.get('[data-cy="task-id"').then((taskIdElement) => {
const taskId = taskIdElement.text();
// Rank an item using the keyboard so that the submit button is enabled
cy.get('button[aria-roledescription="sortable"]')
.first()
.click()
.type("{enter}")
.wait(100)
.type("{downArrow}")
.wait(100)
.type("{enter}");
cy.get('[data-cy="submit"]').click();
cy.get('[data-cy="next-task"]').click();
cy.get('[data-cy="task-id"').should((taskIdElement) => {
expect(taskIdElement.text()).not.to.eq(taskId);
});
});
});
});
export {};

Some files were not shown because too many files have changed in this diff Show More