From 55a4cf1fd096f49583365bfac31e6c62636204a6 Mon Sep 17 00:00:00 2001 From: d_auras Date: Thu, 5 Jan 2023 11:12:11 +0100 Subject: [PATCH 01/43] finally hooked up redis insights to redis --- ansible/dev.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index d022ba3c..04252c0d 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -10,6 +10,42 @@ state: present driver: bridge + - name: Set up Redis + community.docker.docker_container: + name: redis + #name: oasst-redis + image: redis + state: started + restart_policy: always + network_mode: oasst + ports: + - 6379:6379 + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 2s + timeout: 2s + retries: 10 + command: redis-server /usr/local/etc/redis/redis.conf + volumes: + - "./redis.conf:/usr/local/etc/redis/redis.conf" + + - name: Set up Redis Insights + community.docker.docker_container: + name: redis-insights + #name: oasst-redis-insights + image: redislabs/redisinsight:latest + #command: pip install redis-cli python entry.pyc + state: started + restart_policy: always + network_mode: oasst + ports: + - 8001:8001 + env: + REDIS_URL: redis://redis:6379 + REDIS_HOST: redis + #environment: + #- REDIS_URL=redis://redis:6379 + - name: Create postgres containers community.docker.docker_container: name: "{{ item.name }}" From 8921b4f8dd9d2157f5e69b3bd1b231d08c0baec3 Mon Sep 17 00:00:00 2001 From: d_auras Date: Thu, 5 Jan 2023 11:31:13 +0100 Subject: [PATCH 02/43] added test files and README, ready for pull request --- ansible/README.md | 3 +++ ansible/dev.yaml | 12 ++---------- ansible/test.inventory.ini | 2 ++ 3 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 ansible/README.md create mode 100644 ansible/test.inventory.ini diff --git a/ansible/README.md b/ansible/README.md new file mode 100644 index 00000000..b15bf75c --- /dev/null +++ b/ansible/README.md @@ -0,0 +1,3 @@ +To test the ansible playbook on localhost run ```ansible-playbook -i test.inventory.ini dev.yaml```. +Point Redis Insights to the Redis database by visiting localhost:8001 in a browser and select "I already have a database" followed by "Connect to a Redis Database". +For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```. diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 04252c0d..c9195966 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -12,8 +12,7 @@ - name: Set up Redis community.docker.docker_container: - name: redis - #name: oasst-redis + name: oasst-redis image: redis state: started restart_policy: always @@ -31,20 +30,13 @@ - name: Set up Redis Insights community.docker.docker_container: - name: redis-insights - #name: oasst-redis-insights + name: oasst-redis-insights image: redislabs/redisinsight:latest - #command: pip install redis-cli python entry.pyc state: started restart_policy: always network_mode: oasst ports: - 8001:8001 - env: - REDIS_URL: redis://redis:6379 - REDIS_HOST: redis - #environment: - #- REDIS_URL=redis://redis:6379 - name: Create postgres containers community.docker.docker_container: diff --git a/ansible/test.inventory.ini b/ansible/test.inventory.ini new file mode 100644 index 00000000..bfe6d93f --- /dev/null +++ b/ansible/test.inventory.ini @@ -0,0 +1,2 @@ +[test] +dev ansible_connection=local From 43227b2cdcd241534355a5c8b075966bcc0d2b05 Mon Sep 17 00:00:00 2001 From: d_auras Date: Thu, 5 Jan 2023 11:42:02 +0100 Subject: [PATCH 03/43] fixed line breaks in README --- ansible/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ansible/README.md b/ansible/README.md index b15bf75c..b8bd2a48 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -1,3 +1,4 @@ -To test the ansible playbook on localhost run ```ansible-playbook -i test.inventory.ini dev.yaml```. -Point Redis Insights to the Redis database by visiting localhost:8001 in a browser and select "I already have a database" followed by "Connect to a Redis Database". -For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```. +To test the ansible playbook on localhost run ```ansible-playbook -i test.inventory.ini dev.yaml```.\ +In case you're missing the ansible docker depencency install it with ```ansible-galaxy collection install community.docker```.\ +Point Redis Insights to the Redis database by visiting localhost:8001 in a browser and select "I already have a database" followed by "Connect to a Redis Database".\ +For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```.\ From aa09245f7346b02bb13e6c0767993ecdd1f18393 Mon Sep 17 00:00:00 2001 From: d_auras Date: Thu, 5 Jan 2023 11:44:39 +0100 Subject: [PATCH 04/43] fixed last trailing line break in README --- ansible/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/README.md b/ansible/README.md index b8bd2a48..370f9e1e 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -1,4 +1,4 @@ To test the ansible playbook on localhost run ```ansible-playbook -i test.inventory.ini dev.yaml```.\ In case you're missing the ansible docker depencency install it with ```ansible-galaxy collection install community.docker```.\ Point Redis Insights to the Redis database by visiting localhost:8001 in a browser and select "I already have a database" followed by "Connect to a Redis Database".\ -For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```.\ +For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```. From d379193bed67db15fd9c56929320cc0fc1c7eccd Mon Sep 17 00:00:00 2001 From: rasdani <73563550+rasdani@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:15:20 +0100 Subject: [PATCH 05/43] add REDIS_HOST environment variable to backend to comply fully with `docker-compose.yaml` --- ansible/dev.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index ca2a11d9..eea49a3e 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -79,6 +79,7 @@ network_mode: oasst env: POSTGRES_HOST: oasst-postgres + REDIS_HOST: oasst-redis DEBUG_ALLOW_ANY_API_KEY: "true" DEBUG_USE_SEED_DATA: "true" MAX_WORKERS: "1" From a40e6ec31d17f988d7154b663263de5d15d4d740 Mon Sep 17 00:00:00 2001 From: d_auras Date: Thu, 5 Jan 2023 16:25:58 +0100 Subject: [PATCH 06/43] ran pre-commit again --- ansible/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ansible/README.md b/ansible/README.md index 370f9e1e..2ab1943e 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -1,4 +1,7 @@ -To test the ansible playbook on localhost run ```ansible-playbook -i test.inventory.ini dev.yaml```.\ -In case you're missing the ansible docker depencency install it with ```ansible-galaxy collection install community.docker```.\ -Point Redis Insights to the Redis database by visiting localhost:8001 in a browser and select "I already have a database" followed by "Connect to a Redis Database".\ -For host, port and name fill in ```oasst-redis```, ```6379``` and ```redis```. +To test the ansible playbook on localhost run +`ansible-playbook -i test.inventory.ini dev.yaml`.\ +In case you're missing the ansible docker depencency install it with `ansible-galaxy collection install community.docker`.\ +Point Redis Insights to the Redis database by visiting localhost:8001 in a +browser and select "I already have a database" followed by "Connect to a Redis +Database".\ +For host, port and name fill in `oasst-redis`, `6379` and `redis`. From 2870524aa780f55b2bd03d7d1aad1516864f187b Mon Sep 17 00:00:00 2001 From: d_auras Date: Fri, 6 Jan 2023 20:03:15 +0100 Subject: [PATCH 07/43] ansible copies redis.conf to managed node now --- ansible/dev.yaml | 5 +++++ ansible/redis.conf | 2 ++ ansible/remote.inventory.ini | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 ansible/redis.conf create mode 100644 ansible/remote.inventory.ini diff --git a/ansible/dev.yaml b/ansible/dev.yaml index eea49a3e..90f7a85a 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -10,6 +10,11 @@ state: present driver: bridge + - name: Copy redis.conf to managed node + ansible.builtin.copy: + src: ./redis.conf + dest: ./redis.conf + - name: Set up Redis community.docker.docker_container: name: oasst-redis diff --git a/ansible/redis.conf b/ansible/redis.conf new file mode 100644 index 00000000..58da1e05 --- /dev/null +++ b/ansible/redis.conf @@ -0,0 +1,2 @@ +maxmemory 100mb +maxmemory-policy allkeys-lru diff --git a/ansible/remote.inventory.ini b/ansible/remote.inventory.ini new file mode 100644 index 00000000..a3afb2df --- /dev/null +++ b/ansible/remote.inventory.ini @@ -0,0 +1,3 @@ +[dev] +;list your remote hosts here +ubuntu-ssh From c1dab2d213e4c6684edb78e1b0b6de5f672ea64a Mon Sep 17 00:00:00 2001 From: d_auras Date: Fri, 6 Jan 2023 21:46:51 +0100 Subject: [PATCH 08/43] deleted my remote.inventory.ini --- ansible/remote.inventory.ini | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 ansible/remote.inventory.ini diff --git a/ansible/remote.inventory.ini b/ansible/remote.inventory.ini deleted file mode 100644 index a3afb2df..00000000 --- a/ansible/remote.inventory.ini +++ /dev/null @@ -1,3 +0,0 @@ -[dev] -;list your remote hosts here -ubuntu-ssh From c3696759917b2cc03c2424e1a99a9b55d59b4e57 Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Fri, 6 Jan 2023 20:51:49 +1100 Subject: [PATCH 09/43] website: Automate e2e testing with a simpler method than #376 --- .github/workflows/test-e2e.yaml | 37 +++++++++++++++++++++++++++++++++ docker-compose.yaml | 5 +++++ 2 files changed, 42 insertions(+) create mode 100644 .github/workflows/test-e2e.yaml diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml new file mode 100644 index 00000000..f2759808 --- /dev/null +++ b/.github/workflows/test-e2e.yaml @@ -0,0 +1,37 @@ +name: E2E Tests (Website) + +on: + push: + branches: + - main + paths: + - backend/** + - website/** + pull_request: + paths: + - backend/** + - website/** + +jobs: + test-e2e: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Start website, backend, etc + run: docker compose up ci --build -d + - name: Run Cypress tests + uses: cypress-io/github-action@v5.0.2 + with: + browser: chrome + working-directory: website + - uses: actions/upload-artifact@v3 + if: failure() # NOTE: screenshots will be generated only if E2E test failed + with: + name: cypress-screenshots + path: website/cypress/screenshots + - uses: actions/upload-artifact@v3 + if: always() + with: + name: cypress-videos + path: website/cypress/videos diff --git a/docker-compose.yaml b/docker-compose.yaml index 6bc42c51..6896bf18 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,6 +11,11 @@ services: image: sverrirab/sleep depends_on: [db, webdb, adminer, maildev, backend, redis] + # Used by CI automations. + ci: + image: sverrirab/sleep + depends_on: [db, webdb, maildev, backend, redis, web] + # This DB is for the FastAPI Backend. db: image: postgres From 11d55d572a06ba42193f846405128d9da21f9957 Mon Sep 17 00:00:00 2001 From: jojopirker Date: Sun, 8 Jan 2023 12:28:38 +0100 Subject: [PATCH 10/43] message embeddings in Messages table --- ...dded_minilm_embedding_column_to_message.py | 29 +++++++++++++++++++ backend/oasst_backend/api/v1/hugging_face.py | 7 +---- backend/oasst_backend/api/v1/tasks.py | 15 +++++++++- backend/oasst_backend/config.py | 1 + backend/oasst_backend/models/message.py | 5 ++-- .../oasst_backend/models/message_embedding.py | 0 backend/oasst_backend/prompt_repository.py | 9 ++++-- backend/oasst_backend/utils/hugging_face.py | 10 +++++++ docker-compose.yaml | 1 + scripts/backend-development/run-local.sh | 1 + 10 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py create mode 100644 backend/oasst_backend/models/message_embedding.py diff --git a/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py b/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py new file mode 100644 index 00000000..843f03bc --- /dev/null +++ b/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py @@ -0,0 +1,29 @@ +"""added miniLM_embedding column to message + +Revision ID: 023548d474f7 +Revises: ba61fe17fb6e +Create Date: 2023-01-08 11:06:25.613290 + +""" +from alembic import op +import sqlalchemy as sa +import sqlmodel + + +# revision identifiers, used by Alembic. +revision = '023548d474f7' +down_revision = 'ba61fe17fb6e' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('message', sa.Column('miniLM_embedding', sa.ARRAY(sa.Float()), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('message', 'miniLM_embedding') + # ### end Alembic commands ### diff --git a/backend/oasst_backend/api/v1/hugging_face.py b/backend/oasst_backend/api/v1/hugging_face.py index 1e7f1ffe..a8d8aeb9 100644 --- a/backend/oasst_backend/api/v1/hugging_face.py +++ b/backend/oasst_backend/api/v1/hugging_face.py @@ -1,19 +1,14 @@ -from enum import Enum from typing import List from fastapi import APIRouter, Depends from oasst_backend.api import deps from oasst_backend.models import ApiClient from oasst_backend.schemas.hugging_face import ToxicityClassification -from oasst_backend.utils.hugging_face import HuggingFaceAPI +from oasst_backend.utils.hugging_face import HF_url, HuggingFaceAPI router = APIRouter() -class HF_url(str, Enum): - HUGGINGFACE_TOXIC_ROBERTA = "https://api-inference.huggingface.co/models/unitary/multilingual-toxic-xlm-roberta" - - @router.get("/text_toxicity") async def get_text_toxicity( msg: str, diff --git a/backend/oasst_backend/api/v1/tasks.py b/backend/oasst_backend/api/v1/tasks.py index adfb2907..2248b85a 100644 --- a/backend/oasst_backend/api/v1/tasks.py +++ b/backend/oasst_backend/api/v1/tasks.py @@ -7,7 +7,9 @@ from fastapi.security.api_key import APIKey from loguru import logger from oasst_backend.api import deps from oasst_backend.api.v1.utils import prepare_conversation +from oasst_backend.config import settings from oasst_backend.prompt_repository import PromptRepository +from oasst_backend.utils.hugging_face import HF_url, HuggingFaceAPI from oasst_shared.exceptions import OasstError, OasstErrorCode from oasst_shared.schemas import protocol as protocol_schema from sqlmodel import Session @@ -253,7 +255,7 @@ def tasks_acknowledge_failure( @router.post("/interaction", response_model=protocol_schema.TaskDone) -def tasks_interaction( +async def tasks_interaction( *, db: Session = Depends(deps.get_db), api_key: APIKey = Depends(deps.get_api_key), @@ -273,11 +275,22 @@ def tasks_interaction( f"Frontend reports text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." ) + embedding = None + if not settings.DEBUG_SKIP_EMBEDDING_COMPUTATION: + try: + hugging_face_api = HuggingFaceAPI(HF_url.HUGGINGFACE_MINILM_EMBEDDING.value) + embedding = await hugging_face_api.post(interaction.text) + except: + logger.error( + f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." + ) + # here we store the text reply in the database pr.store_text_reply( text=interaction.text, frontend_message_id=interaction.message_id, user_frontend_message_id=interaction.user_message_id, + miniLM_embedding=embedding, ) return protocol_schema.TaskDone() diff --git a/backend/oasst_backend/config.py b/backend/oasst_backend/config.py index 1765af7a..ed394412 100644 --- a/backend/oasst_backend/config.py +++ b/backend/oasst_backend/config.py @@ -25,6 +25,7 @@ class Settings(BaseSettings): DEBUG_USE_SEED_DATA_PATH: Optional[FilePath] = ( Path(__file__).parent.parent / "test_data/generic/test_generic_data.json" ) + DEBUG_SKIP_EMBEDDING_COMPUTATION: bool = False HUGGING_FACE_API_KEY: str = "" diff --git a/backend/oasst_backend/models/message.py b/backend/oasst_backend/models/message.py index 6d24fd13..c7c2abbb 100644 --- a/backend/oasst_backend/models/message.py +++ b/backend/oasst_backend/models/message.py @@ -1,6 +1,6 @@ from datetime import datetime from http import HTTPStatus -from typing import Optional +from typing import List, Optional from uuid import UUID, uuid4 import sqlalchemy as sa @@ -8,7 +8,7 @@ import sqlalchemy.dialects.postgresql as pg from oasst_backend.models.db_payload import MessagePayload from oasst_shared.exceptions.oasst_api_error import OasstError, OasstErrorCode from sqlalchemy import false -from sqlmodel import Field, Index, SQLModel +from sqlmodel import ARRAY, Field, Float, Index, SQLModel from .payload_column_type import PayloadContainer, payload_column_type @@ -40,6 +40,7 @@ class Message(SQLModel, table=True): depth: int = Field(sa_column=sa.Column(sa.Integer, default=0, server_default=sa.text("0"), nullable=False)) children_count: int = Field(sa_column=sa.Column(sa.Integer, default=0, server_default=sa.text("0"), nullable=False)) deleted: bool = Field(sa_column=sa.Column(sa.Boolean, nullable=False, server_default=false())) + miniLM_embedding: List[float] = Field(sa_column=sa.Column(ARRAY(Float)), nullable=True) def ensure_is_message(self) -> None: if not self.payload or not isinstance(self.payload.payload, MessagePayload): diff --git a/backend/oasst_backend/models/message_embedding.py b/backend/oasst_backend/models/message_embedding.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 7c7dd7b6..8bb1eb4a 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -2,7 +2,7 @@ import datetime import random from collections import defaultdict from http import HTTPStatus -from typing import Optional +from typing import List, Optional from uuid import UUID, uuid4 import oasst_backend.models.db_payload as db_payload @@ -122,7 +122,9 @@ class PromptRepository: ) return task - def store_text_reply(self, text: str, frontend_message_id: str, user_frontend_message_id: str) -> Message: + def store_text_reply( + self, text: str, frontend_message_id: str, user_frontend_message_id: str, miniLM_embedding: List[float] = None + ) -> Message: self.validate_frontend_message_id(frontend_message_id) self.validate_frontend_message_id(user_frontend_message_id) @@ -163,6 +165,7 @@ class PromptRepository: role=role, payload=db_payload.MessagePayload(text=text), depth=depth, + miniLM_embedding=miniLM_embedding, ) if not task.collective: task.done = True @@ -366,6 +369,7 @@ class PromptRepository: payload: db_payload.MessagePayload, payload_type: str = None, depth: int = 0, + miniLM_embedding: List[float] = None, ) -> Message: if payload_type is None: if payload is None: @@ -385,6 +389,7 @@ class PromptRepository: payload_type=payload_type, payload=PayloadContainer(payload=payload), depth=depth, + miniLM_embedding=miniLM_embedding, ) self.db.add(message) self.db.commit() diff --git a/backend/oasst_backend/utils/hugging_face.py b/backend/oasst_backend/utils/hugging_face.py index 0df913f5..867c537c 100644 --- a/backend/oasst_backend/utils/hugging_face.py +++ b/backend/oasst_backend/utils/hugging_face.py @@ -1,3 +1,4 @@ +from enum import Enum from typing import Any, Dict import aiohttp @@ -5,6 +6,11 @@ from oasst_backend.config import settings from oasst_shared.exceptions import OasstError, OasstErrorCode +class HF_url(str, Enum): + HUGGINGFACE_TOXIC_ROBERTA = ("https://api-inference.huggingface.co/models/unitary/multilingual-toxic-xlm-roberta",) + HUGGINGFACE_MINILM_EMBEDDING = "https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2" + + class HuggingFaceAPI: """Class Object to make post calls to endpoints for inference in models hosted in HuggingFace""" @@ -41,6 +47,10 @@ class HuggingFaceAPI: async with session.post(self.api_url, headers=self.headers, json=payload) as response: # If we get a bad response if response.status != 200: + from loguru import logger + + logger.error(response) + logger.info(self.headers) raise OasstError( "Response Error Detoxify HuggingFace", error_code=OasstErrorCode.HUGGINGFACE_API_ERROR ) diff --git a/docker-compose.yaml b/docker-compose.yaml index 6bc42c51..5b0032f4 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -95,6 +95,7 @@ services: - DEBUG_SKIP_API_KEY_CHECK=True - DEBUG_USE_SEED_DATA=True - MAX_WORKERS=1 + - DEBUG_SKIP_EMBEDDING_COMPUTATION=True depends_on: db: condition: service_healthy diff --git a/scripts/backend-development/run-local.sh b/scripts/backend-development/run-local.sh index 3ed0e936..f0f6d16c 100755 --- a/scripts/backend-development/run-local.sh +++ b/scripts/backend-development/run-local.sh @@ -6,6 +6,7 @@ pushd "$parent_path/../../backend" export DEBUG_SKIP_API_KEY_CHECK=True export DEBUG_USE_SEED_DATA=True +export DEBUG_SKIP_EMBEDDING_COMPUTATION=True uvicorn main:app --reload --port 8080 --host 0.0.0.0 From 34e7d1db8a272551a9f29bddb1f34ba7a3df8952 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 14:36:38 +0100 Subject: [PATCH 11/43] [NEW] Except OasstError --- backend/oasst_backend/api/v1/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/oasst_backend/api/v1/tasks.py b/backend/oasst_backend/api/v1/tasks.py index 2248b85a..8656a063 100644 --- a/backend/oasst_backend/api/v1/tasks.py +++ b/backend/oasst_backend/api/v1/tasks.py @@ -280,7 +280,7 @@ async def tasks_interaction( try: hugging_face_api = HuggingFaceAPI(HF_url.HUGGINGFACE_MINILM_EMBEDDING.value) embedding = await hugging_face_api.post(interaction.text) - except: + except OasstError: logger.error( f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." ) From a677e40cffcc026a431c333af64b42b823c5af7a Mon Sep 17 00:00:00 2001 From: jojopirker Date: Sun, 8 Jan 2023 16:46:53 +0100 Subject: [PATCH 12/43] insert embedding now to new table --- ...dded_minilm_embedding_column_to_message.py | 12 ++--- ...8_embedding_for_message_now_in_its_own_.py | 49 +++++++++++++++++++ backend/oasst_backend/api/v1/tasks.py | 25 +++++----- backend/oasst_backend/models/__init__.py | 2 + backend/oasst_backend/models/message.py | 5 +- .../oasst_backend/models/message_embedding.py | 15 ++++++ backend/oasst_backend/prompt_repository.py | 15 ++++-- backend/oasst_backend/utils/hugging_face.py | 6 ++- 8 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 backend/alembic/versions/2023_01_08_1603-35bdc1a08bb8_embedding_for_message_now_in_its_own_.py diff --git a/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py b/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py index 843f03bc..9b81105f 100644 --- a/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py +++ b/backend/alembic/versions/2023_01_08_1106-3d96bb92e33a_added_minilm_embedding_column_to_message.py @@ -5,25 +5,23 @@ Revises: ba61fe17fb6e Create Date: 2023-01-08 11:06:25.613290 """ -from alembic import op import sqlalchemy as sa -import sqlmodel - +from alembic import op # revision identifiers, used by Alembic. -revision = '023548d474f7' -down_revision = 'ba61fe17fb6e' +revision = "023548d474f7" +down_revision = "ba61fe17fb6e" branch_labels = None depends_on = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.add_column('message', sa.Column('miniLM_embedding', sa.ARRAY(sa.Float()), nullable=True)) + op.add_column("message", sa.Column("miniLM_embedding", sa.ARRAY(sa.Float()), nullable=True)) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('message', 'miniLM_embedding') + op.drop_column("message", "miniLM_embedding") # ### end Alembic commands ### diff --git a/backend/alembic/versions/2023_01_08_1603-35bdc1a08bb8_embedding_for_message_now_in_its_own_.py b/backend/alembic/versions/2023_01_08_1603-35bdc1a08bb8_embedding_for_message_now_in_its_own_.py new file mode 100644 index 00000000..b732b792 --- /dev/null +++ b/backend/alembic/versions/2023_01_08_1603-35bdc1a08bb8_embedding_for_message_now_in_its_own_.py @@ -0,0 +1,49 @@ +"""embedding for message now in its own table + +Revision ID: 35bdc1a08bb8 +Revises: 023548d474f7 +Create Date: 2023-01-08 16:03:48.454207 + +""" +import sqlalchemy as sa +import sqlmodel +from alembic import op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "35bdc1a08bb8" +down_revision = "023548d474f7" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "message_embedding", + sa.Column("message_id", postgresql.UUID(as_uuid=True), nullable=False), + sa.Column("embedding", sa.ARRAY(sa.Float()), nullable=True), + sa.Column("model", sqlmodel.sql.sqltypes.AutoString(length=256), nullable=False), + sa.ForeignKeyConstraint( + ["message_id"], + ["message.id"], + ), + sa.PrimaryKeyConstraint("message_id", "model"), + ) + op.drop_column("message", "miniLM_embedding") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "message", + sa.Column( + "miniLM_embedding", + postgresql.ARRAY(postgresql.DOUBLE_PRECISION(precision=53)), + autoincrement=False, + nullable=True, + ), + ) + op.drop_table("message_embedding") + # ### end Alembic commands ### diff --git a/backend/oasst_backend/api/v1/tasks.py b/backend/oasst_backend/api/v1/tasks.py index 8656a063..e033c25e 100644 --- a/backend/oasst_backend/api/v1/tasks.py +++ b/backend/oasst_backend/api/v1/tasks.py @@ -9,7 +9,7 @@ from oasst_backend.api import deps from oasst_backend.api.v1.utils import prepare_conversation from oasst_backend.config import settings from oasst_backend.prompt_repository import PromptRepository -from oasst_backend.utils.hugging_face import HF_url, HuggingFaceAPI +from oasst_backend.utils.hugging_face import HF_embeddingModel, HF_url, HuggingFaceAPI from oasst_shared.exceptions import OasstError, OasstErrorCode from oasst_shared.schemas import protocol as protocol_schema from sqlmodel import Session @@ -275,24 +275,27 @@ async def tasks_interaction( f"Frontend reports text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." ) - embedding = None + # here we store the text reply in the database + newMessage = pr.store_text_reply( + text=interaction.text, + frontend_message_id=interaction.message_id, + user_frontend_message_id=interaction.user_message_id, + ) + if not settings.DEBUG_SKIP_EMBEDDING_COMPUTATION: try: - hugging_face_api = HuggingFaceAPI(HF_url.HUGGINGFACE_MINILM_EMBEDDING.value) + hugging_face_api = HuggingFaceAPI( + f"{HF_url.HUGGINGFACE_FEATURE_EXTRACTION.value}{HF_embeddingModel.MINILM.value}" + ) embedding = await hugging_face_api.post(interaction.text) + pr.insert_message_embedding( + message_id=newMessage.id, model=HF_embeddingModel.MINILM.value, embedding=embedding + ) except OasstError: logger.error( f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." ) - # here we store the text reply in the database - pr.store_text_reply( - text=interaction.text, - frontend_message_id=interaction.message_id, - user_frontend_message_id=interaction.user_message_id, - miniLM_embedding=embedding, - ) - return protocol_schema.TaskDone() case protocol_schema.MessageRating: logger.info( diff --git a/backend/oasst_backend/models/__init__.py b/backend/oasst_backend/models/__init__.py index a856b155..0873381c 100644 --- a/backend/oasst_backend/models/__init__.py +++ b/backend/oasst_backend/models/__init__.py @@ -1,6 +1,7 @@ from .api_client import ApiClient from .journal import Journal, JournalIntegration from .message import Message +from .message_embedding import MessageEmbedding from .message_reaction import MessageReaction from .message_tree_state import MessageTreeState from .task import Task @@ -13,6 +14,7 @@ __all__ = [ "User", "UserStats", "Message", + "MessageEmbedding", "MessageReaction", "MessageTreeState", "Task", diff --git a/backend/oasst_backend/models/message.py b/backend/oasst_backend/models/message.py index c7c2abbb..6d24fd13 100644 --- a/backend/oasst_backend/models/message.py +++ b/backend/oasst_backend/models/message.py @@ -1,6 +1,6 @@ from datetime import datetime from http import HTTPStatus -from typing import List, Optional +from typing import Optional from uuid import UUID, uuid4 import sqlalchemy as sa @@ -8,7 +8,7 @@ import sqlalchemy.dialects.postgresql as pg from oasst_backend.models.db_payload import MessagePayload from oasst_shared.exceptions.oasst_api_error import OasstError, OasstErrorCode from sqlalchemy import false -from sqlmodel import ARRAY, Field, Float, Index, SQLModel +from sqlmodel import Field, Index, SQLModel from .payload_column_type import PayloadContainer, payload_column_type @@ -40,7 +40,6 @@ class Message(SQLModel, table=True): depth: int = Field(sa_column=sa.Column(sa.Integer, default=0, server_default=sa.text("0"), nullable=False)) children_count: int = Field(sa_column=sa.Column(sa.Integer, default=0, server_default=sa.text("0"), nullable=False)) deleted: bool = Field(sa_column=sa.Column(sa.Boolean, nullable=False, server_default=false())) - miniLM_embedding: List[float] = Field(sa_column=sa.Column(ARRAY(Float)), nullable=True) def ensure_is_message(self) -> None: if not self.payload or not isinstance(self.payload.payload, MessagePayload): diff --git a/backend/oasst_backend/models/message_embedding.py b/backend/oasst_backend/models/message_embedding.py index e69de29b..697a776b 100644 --- a/backend/oasst_backend/models/message_embedding.py +++ b/backend/oasst_backend/models/message_embedding.py @@ -0,0 +1,15 @@ +from typing import List +from uuid import UUID + +import sqlalchemy as sa +import sqlalchemy.dialects.postgresql as pg +from sqlmodel import ARRAY, Field, Float, SQLModel + + +class MessageEmbedding(SQLModel, table=True): + __tablename__ = "message_embedding" + __table_args__ = (sa.PrimaryKeyConstraint("message_id", "model"),) + + message_id: UUID = Field(sa_column=sa.Column(pg.UUID(as_uuid=True), sa.ForeignKey("message.id"), nullable=False)) + model: str = Field(max_length=256, nullable=False) + embedding: List[float] = Field(sa_column=sa.Column(ARRAY(Float)), nullable=True) diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 8bb1eb4a..efdc1b33 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -8,7 +8,7 @@ from uuid import UUID, uuid4 import oasst_backend.models.db_payload as db_payload from loguru import logger from oasst_backend.journal_writer import JournalWriter -from oasst_backend.models import ApiClient, Message, MessageReaction, Task, TextLabels, User +from oasst_backend.models import ApiClient, Message, MessageEmbedding, MessageReaction, Task, TextLabels, User from oasst_backend.models.payload_column_type import PayloadContainer from oasst_shared.exceptions import OasstError, OasstErrorCode from oasst_shared.schemas import protocol as protocol_schema @@ -165,7 +165,6 @@ class PromptRepository: role=role, payload=db_payload.MessagePayload(text=text), depth=depth, - miniLM_embedding=miniLM_embedding, ) if not task.collective: task.done = True @@ -369,7 +368,6 @@ class PromptRepository: payload: db_payload.MessagePayload, payload_type: str = None, depth: int = 0, - miniLM_embedding: List[float] = None, ) -> Message: if payload_type is None: if payload is None: @@ -389,13 +387,22 @@ class PromptRepository: payload_type=payload_type, payload=PayloadContainer(payload=payload), depth=depth, - miniLM_embedding=miniLM_embedding, ) self.db.add(message) self.db.commit() self.db.refresh(message) return message + def insert_message_embedding(self, message_id: UUID, model: str, embedding: List[float]) -> MessageEmbedding: + if None in (message_id, model, embedding): + raise OasstError("Paramters missing to add embedding", OasstErrorCode.GENERIC_ERROR) + + model = MessageEmbedding(message_id=message_id, model=model, embedding=embedding) + self.db.add(model) + self.db.commit() + self.db.refresh(model) + return model + def insert_reaction(self, task_id: UUID, payload: db_payload.ReactionPayload) -> MessageReaction: if self.user_id is None: raise OasstError("User required", OasstErrorCode.USER_NOT_SPECIFIED) diff --git a/backend/oasst_backend/utils/hugging_face.py b/backend/oasst_backend/utils/hugging_face.py index 867c537c..7a9fa8e3 100644 --- a/backend/oasst_backend/utils/hugging_face.py +++ b/backend/oasst_backend/utils/hugging_face.py @@ -8,7 +8,11 @@ from oasst_shared.exceptions import OasstError, OasstErrorCode class HF_url(str, Enum): HUGGINGFACE_TOXIC_ROBERTA = ("https://api-inference.huggingface.co/models/unitary/multilingual-toxic-xlm-roberta",) - HUGGINGFACE_MINILM_EMBEDDING = "https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2" + HUGGINGFACE_FEATURE_EXTRACTION = "https://api-inference.huggingface.co/pipeline/feature-extraction/" + + +class HF_embeddingModel(str, Enum): + MINILM = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2" class HuggingFaceAPI: From 7101e0e7d527ec608362006927185bf0145de088 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 20:17:14 +0100 Subject: [PATCH 13/43] [NEW] Message embedding created_date --- backend/oasst_backend/models/message_embedding.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/oasst_backend/models/message_embedding.py b/backend/oasst_backend/models/message_embedding.py index 697a776b..74da5004 100644 --- a/backend/oasst_backend/models/message_embedding.py +++ b/backend/oasst_backend/models/message_embedding.py @@ -1,4 +1,5 @@ -from typing import List +from datetime import datetime +from typing import List, Optional from uuid import UUID import sqlalchemy as sa @@ -13,3 +14,8 @@ class MessageEmbedding(SQLModel, table=True): message_id: UUID = Field(sa_column=sa.Column(pg.UUID(as_uuid=True), sa.ForeignKey("message.id"), nullable=False)) model: str = Field(max_length=256, nullable=False) embedding: List[float] = Field(sa_column=sa.Column(ARRAY(Float)), nullable=True) + + # In the case that the Message Embedding is created afterwards + created_date: Optional[datetime] = Field( + sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()) + ) From 19eee6be58fd7bd7298169207ba195a331fa7185 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 20:53:25 +0100 Subject: [PATCH 14/43] [NEW] Removing embedding param in function Store Text Reply --- backend/oasst_backend/prompt_repository.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index dde5003d..919da19b 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -96,7 +96,6 @@ class PromptRepository: text: str, frontend_message_id: str, user_frontend_message_id: str, - miniLM_embedding: Optional[List[float]] = None, ) -> Message: validate_frontend_message_id(frontend_message_id) validate_frontend_message_id(user_frontend_message_id) From 225a136ad1f65948c14da5cf513d7ed2f2420156 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 20:58:19 +0100 Subject: [PATCH 15/43] [NEW] Refactor name of message_embedding object --- backend/oasst_backend/prompt_repository.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 919da19b..3feb77bc 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -233,11 +233,11 @@ class PromptRepository: if None in (message_id, model, embedding): raise OasstError("Paramters missing to add embedding", OasstErrorCode.GENERIC_ERROR) - model = MessageEmbedding(message_id=message_id, model=model, embedding=embedding) - self.db.add(model) + message_embedding = MessageEmbedding(message_id=message_id, model=model, embedding=embedding) + self.db.add(message_embedding) self.db.commit() - self.db.refresh(model) - return model + self.db.refresh(message_embedding) + return message_embedding def insert_reaction(self, task_id: UUID, payload: db_payload.ReactionPayload) -> MessageReaction: if self.user_id is None: From 412736f52c67d3330733c94f773f0f96b923854e Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 20:59:46 +0100 Subject: [PATCH 16/43] [NEW] insert_message_embedding: documentation --- backend/oasst_backend/prompt_repository.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 3feb77bc..c31c0061 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -230,6 +230,20 @@ class PromptRepository: ) def insert_message_embedding(self, message_id: UUID, model: str, embedding: List[float]) -> MessageEmbedding: + """Insert the embedding of a new message in the database. + + Args: + message_id (UUID): the identifier of the message we want to save its embedding + model (str): the model used for creating the embedding + embedding (List[float]): the values obtained from the message & model + + Raises: + OasstError: if misses some of the before params + + Returns: + MessageEmbedding: the instance in the database of the embedding saved for that message + """ + if None in (message_id, model, embedding): raise OasstError("Paramters missing to add embedding", OasstErrorCode.GENERIC_ERROR) From e241a8bf28019261523f2b873f261a759a35a89c Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 21:01:15 +0100 Subject: [PATCH 17/43] [NEW] Adding consistency in the URLs --- backend/oasst_backend/api/v1/tasks.py | 2 +- backend/oasst_backend/utils/hugging_face.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/oasst_backend/api/v1/tasks.py b/backend/oasst_backend/api/v1/tasks.py index 3bdacf49..186a6ac8 100644 --- a/backend/oasst_backend/api/v1/tasks.py +++ b/backend/oasst_backend/api/v1/tasks.py @@ -285,7 +285,7 @@ async def tasks_interaction( if not settings.DEBUG_SKIP_EMBEDDING_COMPUTATION: try: hugging_face_api = HuggingFaceAPI( - f"{HF_url.HUGGINGFACE_FEATURE_EXTRACTION.value}{HF_embeddingModel.MINILM.value}" + f"{HF_url.HUGGINGFACE_FEATURE_EXTRACTION.value}/{HF_embeddingModel.MINILM.value}" ) embedding = await hugging_face_api.post(interaction.text) pr.insert_message_embedding( diff --git a/backend/oasst_backend/utils/hugging_face.py b/backend/oasst_backend/utils/hugging_face.py index 7a9fa8e3..80be074d 100644 --- a/backend/oasst_backend/utils/hugging_face.py +++ b/backend/oasst_backend/utils/hugging_face.py @@ -8,7 +8,7 @@ from oasst_shared.exceptions import OasstError, OasstErrorCode class HF_url(str, Enum): HUGGINGFACE_TOXIC_ROBERTA = ("https://api-inference.huggingface.co/models/unitary/multilingual-toxic-xlm-roberta",) - HUGGINGFACE_FEATURE_EXTRACTION = "https://api-inference.huggingface.co/pipeline/feature-extraction/" + HUGGINGFACE_FEATURE_EXTRACTION = "https://api-inference.huggingface.co/pipeline/feature-extraction" class HF_embeddingModel(str, Enum): From 70620520b49680e9aa5cee89395fa87ffffeef55 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Sun, 8 Jan 2023 21:29:12 +0100 Subject: [PATCH 18/43] [NEW] Created date --- ...23_01_08_2128-aac6b2f66006_created_date.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 backend/alembic/versions/2023_01_08_2128-aac6b2f66006_created_date.py diff --git a/backend/alembic/versions/2023_01_08_2128-aac6b2f66006_created_date.py b/backend/alembic/versions/2023_01_08_2128-aac6b2f66006_created_date.py new file mode 100644 index 00000000..6d40d896 --- /dev/null +++ b/backend/alembic/versions/2023_01_08_2128-aac6b2f66006_created_date.py @@ -0,0 +1,30 @@ +"""Created date + +Revision ID: aac6b2f66006 +Revises: 35bdc1a08bb8 +Create Date: 2023-01-08 21:28:27.342729 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "aac6b2f66006" +down_revision = "35bdc1a08bb8" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "message_embedding", + sa.Column("created_date", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("message_embedding", "created_date") + # ### end Alembic commands ### From b930d2b9c7f6e29823cbf348d21dc15e2d2181ab Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Mon, 9 Jan 2023 10:09:54 +1100 Subject: [PATCH 19/43] Trigger e2e testing on changes to oasst-shared --- .github/workflows/test-e2e.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index f2759808..44ef5b04 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -5,10 +5,12 @@ on: branches: - main paths: + - oasst-shared/** - backend/** - website/** pull_request: paths: + - oasst-shared/** - backend/** - website/** From 69dc6bf68d653d1796ac8e889331ebd53c19a7de Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 09:44:01 +0900 Subject: [PATCH 20/43] Adding a bare bones feature flag setup --- website/README.md | 28 ++++++++++++++++++++++++ website/package-lock.json | 17 ++++++++++++++ website/package.json | 1 + website/src/components/Header/Header.tsx | 4 ++++ website/src/flags.ts | 3 +++ website/src/pages/_app.tsx | 10 ++++++--- 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 website/src/flags.ts diff --git a/website/README.md b/website/README.md index 11e3ccc4..37f6991b 100644 --- a/website/README.md +++ b/website/README.md @@ -153,6 +153,34 @@ When writing code for the website, we have a few best practices: 1. Define functional React components (with types for all properties when feasible). +### Developing New Features + +When working on new features or making significant changes that can't be done +within a single Pull Request, we ask that you make use of Feature Flags. + +We've set up +[`react-feature-flags`](https://www.npmjs.com/package/react-feature-flags) to +make this easier. To get started: + +1. Add a new flag entry to `website/src/flags.ts`. We have an example flag you + can copy as an example. Be sure to `isActive` to true when testing your + features but false when submitting your PR. +1. Use your flag wherever you add a new UI element. This can be done with: + +```js +import { Flags } from "react-feature-flags"; +... + + + +``` + + You can see an example of how this works by checking `website/src/components/Header/Headers.tsx` where we use `flagTest`. + +1. Once you've finished building out the feature and it is ready for everyone + to use, it's safe to remove the `Flag` wrappers around your component and + the entry in `flags.ts`. + ### URL Paths To use stable and consistent URL paths, we recommend the following strategy for diff --git a/website/package-lock.json b/website/package-lock.json index ef867a98..81a9cd5d 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -39,6 +39,7 @@ "postcss-focus-visible": "^7.1.0", "react": "18.2.0", "react-dom": "18.2.0", + "react-feature-flags": "^1.0.0", "react-icons": "^4.7.1", "swr": "^2.0.0", "tailwindcss": "^3.2.4", @@ -26424,6 +26425,16 @@ "resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.0.tgz", "integrity": "sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==" }, + "node_modules/react-feature-flags": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/react-feature-flags/-/react-feature-flags-1.0.0.tgz", + "integrity": "sha512-KBFUkXjF7ifGWEQr2Ida4LdAtKGDOwFdTRlXipWxGP9a43vUBxP6IscpYQofGjlzlBcgmFKuzubcVheB6NliEg==", + "peerDependencies": { + "prop-types": "^15.5.4", + "react": ">= 16.3.0", + "react-dom": ">= 16.3.0" + } + }, "node_modules/react-focus-lock": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/react-focus-lock/-/react-focus-lock-2.9.2.tgz", @@ -50838,6 +50849,12 @@ "resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.0.tgz", "integrity": "sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==" }, + "react-feature-flags": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/react-feature-flags/-/react-feature-flags-1.0.0.tgz", + "integrity": "sha512-KBFUkXjF7ifGWEQr2Ida4LdAtKGDOwFdTRlXipWxGP9a43vUBxP6IscpYQofGjlzlBcgmFKuzubcVheB6NliEg==", + "requires": {} + }, "react-focus-lock": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/react-focus-lock/-/react-focus-lock-2.9.2.tgz", diff --git a/website/package.json b/website/package.json index d00a3f4d..032125dd 100644 --- a/website/package.json +++ b/website/package.json @@ -53,6 +53,7 @@ "postcss-focus-visible": "^7.1.0", "react": "18.2.0", "react-dom": "18.2.0", + "react-feature-flags": "^1.0.0", "react-icons": "^4.7.1", "swr": "^2.0.0", "tailwindcss": "^3.2.4", diff --git a/website/src/components/Header/Header.tsx b/website/src/components/Header/Header.tsx index 4ea453c6..d0dc8a06 100644 --- a/website/src/components/Header/Header.tsx +++ b/website/src/components/Header/Header.tsx @@ -2,6 +2,7 @@ import { Box, Button, Text, useColorMode } from "@chakra-ui/react"; import Image from "next/image"; import Link from "next/link"; import { useSession } from "next-auth/react"; +import { Flags } from "react-feature-flags"; import { FaUser } from "react-icons/fa"; import { UserMenu } from "./UserMenu"; @@ -42,6 +43,9 @@ export function Header(props) {
+ +
FlagTest
+
diff --git a/website/src/flags.ts b/website/src/flags.ts new file mode 100644 index 00000000..2e59ec1a --- /dev/null +++ b/website/src/flags.ts @@ -0,0 +1,3 @@ +const flags = [{ name: "flagTest", isActive: false }]; + +export default flags; diff --git a/website/src/pages/_app.tsx b/website/src/pages/_app.tsx index ab7655cd..69d212e8 100644 --- a/website/src/pages/_app.tsx +++ b/website/src/pages/_app.tsx @@ -3,7 +3,9 @@ import "focus-visible"; import type { AppProps } from "next/app"; import { SessionProvider } from "next-auth/react"; +import { FlagsProvider } from "react-feature-flags"; import { getDefaultLayout, NextPageWithLayout } from "src/components/Layout"; +import flags from "src/flags"; import { Chakra, getServerSideProps } from "../styles/Chakra"; @@ -16,9 +18,11 @@ function MyApp({ Component, pageProps: { session, cookies, ...pageProps } }: App const page = getLayout(); return ( - - {page} - + + + {page} + + ); } export { getServerSideProps }; From ad6202009b13497499807da0547b405c27dd2b07 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 13:38:17 +0900 Subject: [PATCH 21/43] Allowing the ansible workflow to run manually --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bb844a34..e7b8806c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,6 +1,7 @@ name: Release on: + workflow_dispatch: release: types: [released] From 491d8e7413f48f2645ceb6cded35c169e7eab216 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 13:39:49 +0900 Subject: [PATCH 22/43] Changing the email provider values --- ansible/dev.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 577abd68..6e2b15c9 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -69,11 +69,11 @@ network_mode: oasst env: FASTAPI_URL: http://oasst-backend:8080 - FASTAPI_KEY: "123" + FASTAPI_KEY: 123 DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres NEXTAUTH_SECRET: O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98= EMAIL_SERVER_HOST: oasst-maildev - EMAIL_SERVER_PORT: "25" + EMAIL_SERVER_PORT: 1025 EMAIL_FROM: info@example.com NEXTAUTH_URL: http://web.dev.open-assistant.io/ DEBUG_LOGIN: "true" From d2dd96b43a97766946eed0b605406cde31aefd2f Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 13:47:01 +0900 Subject: [PATCH 23/43] Wrapping numbers in quotes after learning ansible --- ansible/dev.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 6e2b15c9..940e6cbc 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -69,11 +69,11 @@ network_mode: oasst env: FASTAPI_URL: http://oasst-backend:8080 - FASTAPI_KEY: 123 + FASTAPI_KEY: "1234" DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres NEXTAUTH_SECRET: O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98= EMAIL_SERVER_HOST: oasst-maildev - EMAIL_SERVER_PORT: 1025 + EMAIL_SERVER_PORT: "1025" EMAIL_FROM: info@example.com NEXTAUTH_URL: http://web.dev.open-assistant.io/ DEBUG_LOGIN: "true" From 310763ebb8643c137b997d5cada550e4e60cb05e Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 14:07:30 +0900 Subject: [PATCH 24/43] Adding discord credentials to dev deployment --- .github/workflows/release.yaml | 3 +++ ansible/dev.yaml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e7b8806c..17b00357 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,6 +30,9 @@ jobs: deploy-dev: needs: [build-backend, build-web, build-bot] runs-on: ubuntu-latest + env: + WEB_DISCORD_CLIENT_ID: ${{ secrets.DEV_WEB_DISCORD_CLIENT_ID }} + WEB_DISCORD_CLIENT_SECRET: ${{ secrets.DEV_WEB_DISCORD_CLIENT_SECRET }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 940e6cbc..16cb0a17 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -39,6 +39,8 @@ state: started restart_policy: always network_mode: oasst + ports: + - 1080:1080 - name: Run the oasst oasst-backend community.docker.docker_container: @@ -68,6 +70,8 @@ restart_policy: always network_mode: oasst env: + DISCORD_CLIENT_ID: "{{ lookup('WEB_DISCORD_CLIENT_ID') }} " + DISCORD_CLIENT_SECRET: "{{ lookup('WEB_DISCORD_CLIENT_SECRET') }} " FASTAPI_URL: http://oasst-backend:8080 FASTAPI_KEY: "1234" DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres From f22abd524bd252f1df4b7bdc824cddacf28400b1 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 14:16:49 +0900 Subject: [PATCH 25/43] Adding discord credentials to dev deployment --- ansible/dev.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 16cb0a17..53f920df 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -70,8 +70,10 @@ restart_policy: always network_mode: oasst env: - DISCORD_CLIENT_ID: "{{ lookup('WEB_DISCORD_CLIENT_ID') }} " - DISCORD_CLIENT_SECRET: "{{ lookup('WEB_DISCORD_CLIENT_SECRET') }} " + DISCORD_CLIENT_ID: + "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_ID') }} " + DISCORD_CLIENT_SECRET: + "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_SECRET') }} " FASTAPI_URL: http://oasst-backend:8080 FASTAPI_KEY: "1234" DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres From 00e51af787b67c1b8c13adb70150affe0ec36fb6 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 14:43:45 +0900 Subject: [PATCH 26/43] Adding the email secrets and environment variables --- .github/workflows/release.yaml | 4 ++++ ansible/dev.yaml | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 17b00357..eec73daa 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -33,6 +33,10 @@ jobs: env: WEB_DISCORD_CLIENT_ID: ${{ secrets.DEV_WEB_DISCORD_CLIENT_ID }} WEB_DISCORD_CLIENT_SECRET: ${{ secrets.DEV_WEB_DISCORD_CLIENT_SECRET }} + WEB_EMAIL_SERVER_HOST: ${{ secrets.DEV_WEB_EMAIL_SERVER_HOST }} + WEB_EMAIL_SERVER_PASSWORD: ${{ secrets.DEV_WEB_EMAIL_SERVER_PASSWORD }} + WEB_EMAIL_SERVER_PORT: ${{ secrets.DEV_WEB_EMAIL_SERVER_PORT }} + WEB_EMAIL_SERVER_USER: ${{ secrets.DEV_WEB_EMAIL_SERVER_USER }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 53f920df..cf0d70a4 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -71,16 +71,22 @@ network_mode: oasst env: DISCORD_CLIENT_ID: - "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_ID') }} " + "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_ID') }}" DISCORD_CLIENT_SECRET: - "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_SECRET') }} " + "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_SECRET') }}" + EMAIL_SERVER_FROM: open-assistent@laion.ai + EMAIL_SERVER_HOST: + "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_HOST') }}" + EMAIL_SERVER_PASSWORD: + "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_PASSWORD') }}" + EMAIL_SERVER_PORT: + "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_PORT') }}" + EMAIL_SERVER_USER: + "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_USER') }}" FASTAPI_URL: http://oasst-backend:8080 FASTAPI_KEY: "1234" DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres NEXTAUTH_SECRET: O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98= - EMAIL_SERVER_HOST: oasst-maildev - EMAIL_SERVER_PORT: "1025" - EMAIL_FROM: info@example.com NEXTAUTH_URL: http://web.dev.open-assistant.io/ DEBUG_LOGIN: "true" ports: From 0e9fd9a14059321ba6ef02e595c348795077db80 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 14:56:13 +0900 Subject: [PATCH 27/43] Seeing the admin users, email from, and next auth secret secrets --- .github/workflows/release.yaml | 2 ++ ansible/dev.yaml | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index eec73daa..dea9c15d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -31,12 +31,14 @@ jobs: needs: [build-backend, build-web, build-bot] runs-on: ubuntu-latest env: + WEB_ADMIN_USERS: ${{ secrets.DEV_WEB_ADMIN_USERS }} WEB_DISCORD_CLIENT_ID: ${{ secrets.DEV_WEB_DISCORD_CLIENT_ID }} WEB_DISCORD_CLIENT_SECRET: ${{ secrets.DEV_WEB_DISCORD_CLIENT_SECRET }} WEB_EMAIL_SERVER_HOST: ${{ secrets.DEV_WEB_EMAIL_SERVER_HOST }} WEB_EMAIL_SERVER_PASSWORD: ${{ secrets.DEV_WEB_EMAIL_SERVER_PASSWORD }} WEB_EMAIL_SERVER_PORT: ${{ secrets.DEV_WEB_EMAIL_SERVER_PORT }} WEB_EMAIL_SERVER_USER: ${{ secrets.DEV_WEB_EMAIL_SERVER_USER }} + WEB_NEXTAUTH_SECRET: ${{ secrets.DEV_WEB_NEXTAUTH_SECRET }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/ansible/dev.yaml b/ansible/dev.yaml index cf0d70a4..48be673e 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -70,11 +70,14 @@ restart_policy: always network_mode: oasst env: + ADMIN_USERS: "{{ lookup('ansible.builtin.env', 'WEB_ADMIN_USERS') }}" + DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres + DEBUG_LOGIN: "true" DISCORD_CLIENT_ID: "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_ID') }}" DISCORD_CLIENT_SECRET: "{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_SECRET') }}" - EMAIL_SERVER_FROM: open-assistent@laion.ai + EMAIL_FROM: open-assistent@laion.ai EMAIL_SERVER_HOST: "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_HOST') }}" EMAIL_SERVER_PASSWORD: @@ -85,10 +88,9 @@ "{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_USER') }}" FASTAPI_URL: http://oasst-backend:8080 FASTAPI_KEY: "1234" - DATABASE_URL: postgres://postgres:postgres@oasst-postgres-web/postgres - NEXTAUTH_SECRET: O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98= + NEXTAUTH_SECRET: + "{{ lookup('ansible.builtin.env', 'WEB_NEXTAUTH_SECRET') }}" NEXTAUTH_URL: http://web.dev.open-assistant.io/ - DEBUG_LOGIN: "true" ports: - 3000:3000 command: bash wait-for-postgres.sh node server.js From 2ca2abf4c193f6b9e95371989a96ab4d161fc7b8 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 15:25:02 +0900 Subject: [PATCH 28/43] Adding some debug stuff on admin --- website/src/pages/admin/index.tsx | 1 + website/src/pages/api/auth/[...nextauth].ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/website/src/pages/admin/index.tsx b/website/src/pages/admin/index.tsx index 9cbea222..7bfdad63 100644 --- a/website/src/pages/admin/index.tsx +++ b/website/src/pages/admin/index.tsx @@ -22,6 +22,7 @@ const AdminIndex = () => { if (status === "loading") { return; } + console.log("checking role: " + session?.user?.role); if (session?.user?.role === "admin") { return; } diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index 363c1404..4108d53c 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -69,6 +69,8 @@ const adminUserMap = process.env.ADMIN_USERS.split(",").reduce((result, entry) = result.set(authType, s); return result; }, new Map()); +console.log(adminUserMap); +console.log(process.env.ADMIN_USERS); export const authOptions: AuthOptions = { // Ensure we can store user data in a database. @@ -97,6 +99,7 @@ export const authOptions: AuthOptions = { where: { id: token.sub }, select: { role: true }, }); + console.log("found role: " + role); token.role = role; return token; }, @@ -118,6 +121,7 @@ export const authOptions: AuthOptions = { // Update the database if the user is an admin. if (adminForAccountType.has(account.providerAccountId)) { + console.log("updating admin"); await prisma.user.update({ data: { role: "admin", From 5b70b6c35cc021ab84df6e96a26791f5881ef29f Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 15:34:45 +0900 Subject: [PATCH 29/43] Revert "Adding some debug stuff on admin" This reverts commit 2ca2abf4c193f6b9e95371989a96ab4d161fc7b8. --- website/src/pages/admin/index.tsx | 1 - website/src/pages/api/auth/[...nextauth].ts | 4 ---- 2 files changed, 5 deletions(-) diff --git a/website/src/pages/admin/index.tsx b/website/src/pages/admin/index.tsx index 7bfdad63..9cbea222 100644 --- a/website/src/pages/admin/index.tsx +++ b/website/src/pages/admin/index.tsx @@ -22,7 +22,6 @@ const AdminIndex = () => { if (status === "loading") { return; } - console.log("checking role: " + session?.user?.role); if (session?.user?.role === "admin") { return; } diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index 4108d53c..363c1404 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -69,8 +69,6 @@ const adminUserMap = process.env.ADMIN_USERS.split(",").reduce((result, entry) = result.set(authType, s); return result; }, new Map()); -console.log(adminUserMap); -console.log(process.env.ADMIN_USERS); export const authOptions: AuthOptions = { // Ensure we can store user data in a database. @@ -99,7 +97,6 @@ export const authOptions: AuthOptions = { where: { id: token.sub }, select: { role: true }, }); - console.log("found role: " + role); token.role = role; return token; }, @@ -121,7 +118,6 @@ export const authOptions: AuthOptions = { // Update the database if the user is an admin. if (adminForAccountType.has(account.providerAccountId)) { - console.log("updating admin"); await prisma.user.update({ data: { role: "admin", From c1b3029f8ba0c0981e94d0942e2824c044d54a71 Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 15:46:45 +0900 Subject: [PATCH 30/43] Deleting the maildev stanza now that we're using a real email server --- ansible/dev.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 48be673e..8acdb8a4 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -32,16 +32,6 @@ - name: oasst-postgres - name: oasst-postgres-web - - name: Set up maildev - community.docker.docker_container: - name: oasst-maildev - image: maildev/maildev - state: started - restart_policy: always - network_mode: oasst - ports: - - 1080:1080 - - name: Run the oasst oasst-backend community.docker.docker_container: name: oasst-backend From 5e07480f149283a831aee1e033b47a5d590fb75b Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 9 Jan 2023 15:54:30 +0900 Subject: [PATCH 31/43] Remove the workflow dispatch option --- .github/workflows/release.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dea9c15d..1bf0ac6a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,7 +1,6 @@ name: Release on: - workflow_dispatch: release: types: [released] From b39b86309cdaf8a6d8b207b3278781fd80a47140 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Mon, 9 Jan 2023 09:03:02 +0100 Subject: [PATCH 32/43] [FIX] Import on top --- backend/oasst_backend/utils/hugging_face.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/oasst_backend/utils/hugging_face.py b/backend/oasst_backend/utils/hugging_face.py index 80be074d..ef440055 100644 --- a/backend/oasst_backend/utils/hugging_face.py +++ b/backend/oasst_backend/utils/hugging_face.py @@ -2,6 +2,7 @@ from enum import Enum from typing import Any, Dict import aiohttp +from loguru import logger from oasst_backend.config import settings from oasst_shared.exceptions import OasstError, OasstErrorCode @@ -51,7 +52,6 @@ class HuggingFaceAPI: async with session.post(self.api_url, headers=self.headers, json=payload) as response: # If we get a bad response if response.status != 200: - from loguru import logger logger.error(response) logger.info(self.headers) From ef7bd89df2124739973f703b51531c62324a6a15 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Mon, 9 Jan 2023 09:07:08 +0100 Subject: [PATCH 33/43] [NEW] ansible: DEBUG_SKIP_EMBEDDING_COMPUTATION --- ansible/dev.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible/dev.yaml b/ansible/dev.yaml index 577abd68..81ab12ee 100644 --- a/ansible/dev.yaml +++ b/ansible/dev.yaml @@ -55,6 +55,7 @@ DEBUG_USE_SEED_DATA: "true" MAX_WORKERS: "1" RATE_LIMIT: "false" + DEBUG_SKIP_EMBEDDING_COMPUTATION: "true" ports: - 8080:8080 From 91ee52595ea696677482a211b261fcc315c54e95 Mon Sep 17 00:00:00 2001 From: Adrian Cowan Date: Mon, 9 Jan 2023 19:14:53 +1100 Subject: [PATCH 34/43] website: Ignore screenshots and videos produced by cypress e2e tests These files are generated by running `npm run cypress:run` --- website/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/.gitignore b/website/.gitignore index 86e167da..0b9f1dbe 100644 --- a/website/.gitignore +++ b/website/.gitignore @@ -39,5 +39,7 @@ next-env.d.ts *.swp # cypress +/cypress/screenshots +/cypress/videos /cypress-visual-screenshots/diff /cypress-visual-screenshots/comparison From 4b4a564a8fb8a6308527dbeb65b6cafd108e0f75 Mon Sep 17 00:00:00 2001 From: Nil-Andreu Date: Mon, 9 Jan 2023 10:10:19 +0100 Subject: [PATCH 35/43] [NEW] Camelcase & 2x space --- backend/oasst_backend/api/v1/hugging_face.py | 4 ++-- backend/oasst_backend/api/v1/tasks.py | 8 ++++---- backend/oasst_backend/utils/hugging_face.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/oasst_backend/api/v1/hugging_face.py b/backend/oasst_backend/api/v1/hugging_face.py index a8d8aeb9..62d2ea6b 100644 --- a/backend/oasst_backend/api/v1/hugging_face.py +++ b/backend/oasst_backend/api/v1/hugging_face.py @@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends from oasst_backend.api import deps from oasst_backend.models import ApiClient from oasst_backend.schemas.hugging_face import ToxicityClassification -from oasst_backend.utils.hugging_face import HF_url, HuggingFaceAPI +from oasst_backend.utils.hugging_face import HfUrl, HuggingFaceAPI router = APIRouter() @@ -25,7 +25,7 @@ async def get_text_toxicity( ToxicityClassification: the score of toxicity of the message. """ - api_url: str = HF_url.HUGGINGFACE_TOXIC_ROBERTA.value + api_url: str = HfUrl.HUGGINGFACE_TOXIC_ROBERTA.value hugging_face_api = HuggingFaceAPI(api_url) response = await hugging_face_api.post(msg) diff --git a/backend/oasst_backend/api/v1/tasks.py b/backend/oasst_backend/api/v1/tasks.py index 186a6ac8..821ba562 100644 --- a/backend/oasst_backend/api/v1/tasks.py +++ b/backend/oasst_backend/api/v1/tasks.py @@ -9,7 +9,7 @@ from oasst_backend.api import deps from oasst_backend.api.v1.utils import prepare_conversation from oasst_backend.config import settings from oasst_backend.prompt_repository import PromptRepository, TaskRepository -from oasst_backend.utils.hugging_face import HF_embeddingModel, HF_url, HuggingFaceAPI +from oasst_backend.utils.hugging_face import HfEmbeddingModel, HfUrl, HuggingFaceAPI from oasst_shared.exceptions import OasstError, OasstErrorCode from oasst_shared.schemas import protocol as protocol_schema from sqlmodel import Session @@ -285,15 +285,15 @@ async def tasks_interaction( if not settings.DEBUG_SKIP_EMBEDDING_COMPUTATION: try: hugging_face_api = HuggingFaceAPI( - f"{HF_url.HUGGINGFACE_FEATURE_EXTRACTION.value}/{HF_embeddingModel.MINILM.value}" + f"{HfUrl.HUGGINGFACE_FEATURE_EXTRACTION.value}/{HfEmbeddingModel.MINILM.value}" ) embedding = await hugging_face_api.post(interaction.text) pr.insert_message_embedding( - message_id=newMessage.id, model=HF_embeddingModel.MINILM.value, embedding=embedding + message_id=newMessage.id, model=HfEmbeddingModel.MINILM.value, embedding=embedding ) except OasstError: logger.error( - f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." + f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}." ) return protocol_schema.TaskDone() diff --git a/backend/oasst_backend/utils/hugging_face.py b/backend/oasst_backend/utils/hugging_face.py index ef440055..87c6288e 100644 --- a/backend/oasst_backend/utils/hugging_face.py +++ b/backend/oasst_backend/utils/hugging_face.py @@ -7,12 +7,12 @@ from oasst_backend.config import settings from oasst_shared.exceptions import OasstError, OasstErrorCode -class HF_url(str, Enum): +class HfUrl(str, Enum): HUGGINGFACE_TOXIC_ROBERTA = ("https://api-inference.huggingface.co/models/unitary/multilingual-toxic-xlm-roberta",) HUGGINGFACE_FEATURE_EXTRACTION = "https://api-inference.huggingface.co/pipeline/feature-extraction" -class HF_embeddingModel(str, Enum): +class HfEmbeddingModel(str, Enum): MINILM = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2" From 225aa58f89465a437e3be8e3e79e0ba86d699548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6pf?= Date: Mon, 9 Jan 2023 11:07:05 +0100 Subject: [PATCH 36/43] Fix expiry test in Task.expired() Co-authored-by: Hemang Joshi --- backend/oasst_backend/models/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/oasst_backend/models/task.py b/backend/oasst_backend/models/task.py index a980c1b5..d923be97 100644 --- a/backend/oasst_backend/models/task.py +++ b/backend/oasst_backend/models/task.py @@ -35,4 +35,4 @@ class Task(SQLModel, table=True): @property def expired(self) -> bool: - return self.expiry_date is not None and datetime.utcnow() < self.expiry_date + return self.expiry_date is not None and datetime.utcnow() > self.expiry_date From c22b26d21a8960197fdffa30b7ed708bfb1f8332 Mon Sep 17 00:00:00 2001 From: mrcabbage972 Date: Mon, 9 Jan 2023 05:45:54 -0500 Subject: [PATCH 37/43] Expanding survey of relevant research (#557) Expanding survey of relevant research --- docs/docs/research/general.md | 70 ++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/docs/docs/research/general.md b/docs/docs/research/general.md index 56f935ac..4186ebac 100644 --- a/docs/docs/research/general.md +++ b/docs/docs/research/general.md @@ -1,7 +1,63 @@ -# General +# Research This page lists research papers that are relevant to the project. +## Table of Contents + +- Reinforcement Learning from Human Feedback +- Generating Text From Language Models +- Automatically Generating Instruction Data for Training +- Uncertainty Estimation of Language Model Outputs + +## Reinforcement Learning from Human Feedback + +Reinforcement Learning from Human Feedback (RLHF) is a method for fine-tuning a +generative language models based on a reward model that is learned from human +preference data. This method facilitates the learning of instruction-tuned +models, among other things. + +### Learning to summarize from human feedback [[ArXiv](https://arxiv.org/pdf/2009.01325.pdf)], [[Github](https://github.com/openai/summarize-from-feedback)] + +> In this work, we show that it is possible to significantly improve summary +> quality by training a model to optimize for human preferences. We collect a +> large, high-quality dataset of human comparisons between summaries, train a +> model to predict the human-preferred summary, and use that model as a reward +> function to fine-tune a summarization policy using reinforcement learning. + +### Training language models to follow instructions with human feedback [[ArXiv](https://arxiv.org/pdf/2203.02155.pdf)] + +> Starting with a set of labeler-written prompts and prompts submitted through +> the OpenAI API, we collect a dataset of labeler demonstrations of the desired +> model behavior, which we use to fine-tune GPT-3 using supervised learning. We +> then collect a dataset of rankings of model outputs, which we use to further +> fine-tune this supervised model using reinforcement learning from human +> feedback. + +### Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback [[ArXiv](https://arxiv.org/pdf/2204.05862.pdf)] + +> We apply preference modeling and reinforcement learning from human feedback +> (RLHF) to finetune language models to act as helpful and harmless assistants. +> We find this alignment training improves performance on almost all NLP +> evaluations, and is fully compatible with training for specialized skills such +> as python coding and summarization. + +## Generating Text From Language Models + +A language model generates output text token by token, autoregressively. The +large search space of this task requires some method of narrowing down the set +of tokens to be considered in each step. This method, in turn, has a big impact +on the quality of the resulting text. + +### RANKGEN: Improving Text Generation with Large Ranking Models [[ArXiv](https://arxiv.org/pdf/2205.09726.pdf)], [[Github](https://github.com/martiansideofthemoon/rankgen)] + +> Given an input sequence (or prefix), modern language models often assign high +> probabilities to output sequences that are repetitive, incoherent, or +> irrelevant to the prefix; as such, model-generated text also contains such +> artifacts. To address these issues we present RankGen, a 1.2B parameter +> encoder model for English that scores model generations given a prefix. +> RankGen can be flexibly incorporated as a scoring function in beam search and +> used to decode from any pretrained language model. + ## Automatically Generating Instruction Data for Training This line of work is about significantly reducing the need for manually @@ -32,3 +88,15 @@ models. > 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. + +## Uncertainty Estimation of Language Model Outputs + +### Teaching models to express their uncertainty in words [[Arxiv](https://arxiv.org/pdf/2205.14334.pdf)] + +> We show that a GPT-3 model can learn to express uncertainty about its own +> answers in natural language -- without use of model logits. When given a +> question, the model generates both an answer and a level of confidence (e.g. +> "90% confidence" or "high confidence"). These levels map to probabilities that +> are well calibrated. The model also remains moderately calibrated under +> distribution shift, and is sensitive to uncertainty in its own answers, rather +> than imitating human examples. From a206a9a9abbe60a076f043bde5f379ac83b3646a Mon Sep 17 00:00:00 2001 From: Andrew Maguire Date: Mon, 9 Jan 2023 14:11:35 +0000 Subject: [PATCH 38/43] add example notebook (#512) adds an example notebook and some docs --- notebooks/README.md | 12 ++- notebooks/example/README.md | 48 +++++++++ notebooks/example/data/data.csv | 3 + notebooks/example/example.ipynb | 160 +++++++++++++++++++++++++++++ notebooks/example/requirements.txt | 1 + 5 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 notebooks/example/README.md create mode 100644 notebooks/example/data/data.csv create mode 100644 notebooks/example/example.ipynb create mode 100644 notebooks/example/requirements.txt diff --git a/notebooks/README.md b/notebooks/README.md index edb5da33..2eea7a15 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -1,10 +1,14 @@ # 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 folder with some useful notebooks, all the notebooks have a markdown +file with the same name (or a README.md if its a single notebook folder) +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 +Contributing to 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, it makes it easier for people to know what your notebook is about. + +Check out the [example notebook](example/) for a reference example you can use +as a starting point. diff --git a/notebooks/example/README.md b/notebooks/example/README.md new file mode 100644 index 00000000..2136834d --- /dev/null +++ b/notebooks/example/README.md @@ -0,0 +1,48 @@ +# Example Notebook + +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andrewm4894/Open-Assistant/blob/main/notebooks/example/example.ipynb) + +This folder contains an example reference notebook structure and approach for +this project. Please try and follow this structure as closely as possible. While +things will not exactly be the same for each notebook some principles we would +like to try ensure are: + +1. Each notebook or collection of related or dependant notebooks should live in + its own folder. +1. Each notebook should have a markdown file with the same name as the notebook + (or README.md if it's a single notebook folder) that explains what the + notebook does and how to use it. +1. Add an "Open in Colab" badge to the top of the notebook (see the markdown + cell near the top of `example.ipynb` as an example you can adapt). +1. Make it as easy as possible for someone to run the notebook in Google Colab + or some other environment based on standard practices like providing a + `requirements.txt` file or anything else needed to successfully run the + notebook. + +## Running in Google Colab + +At the top of the [example notebook](example.ipynb) there is a code cell that +will (once uncommented): + +1. clone the repository into your colab instance. +1. `cd` into the relevant notebook directory. +1. run `pip install -r requirements.txt` to install the required packages. + +At this point you can run the notebook as normal and the folder structure will +match that of the repository and the colab notebook will be running from the +same directory that the notebook lives in so relative links etc should work as +expected (for example `example.ipynb` will read some sample data from +`data/data.csv`). + +If you are adding a notebook please try and add a similar cell to the top of the +notebook so that it is easy for others to run the notebook in colab. If your +notebook does not have any dependencies beyond what already comes as standard in +Google Colab then you do not need such a cell, just an "Open in Colab" badge +will suffice. + +## example.ipynb + +This notebook contains an example "Open In Colab" badge and a code cell to +prepare the colab environment to run the notebook. It also contains a code cell +that will read in some sample data from the `data` folder in the repository and +display it as a pandas dataframe. diff --git a/notebooks/example/data/data.csv b/notebooks/example/data/data.csv new file mode 100644 index 00000000..126a03bb --- /dev/null +++ b/notebooks/example/data/data.csv @@ -0,0 +1,3 @@ +row,text,label +1,some example data,1 +2,some more data,0 diff --git a/notebooks/example/example.ipynb b/notebooks/example/example.ipynb new file mode 100644 index 00000000..2c6b1e01 --- /dev/null +++ b/notebooks/example/example.ipynb @@ -0,0 +1,160 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example Notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andrewm4894/Open-Assistant/blob/example-notebook/notebooks/example/example.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# uncomment and run below lines to set up if running in colab\n", + "# !git clone https://github.com/andrewm4894/Open-Assistant.git\n", + "# %cd Open-Assistant/notebooks/example\n", + "# !pip install -r requirements.txt" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try to add a markdown section to the notebook that explains what the notebook is about and what it does. This will help people understand what the notebook is for and how to use it." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# import required packages\n", + "import pandas as pd\n", + "from transformers import pipeline" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Use Headings\n", + "\n", + "(it will help with link sharing to specific sections of the notebook)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make fancy markdown cells if you want." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
rowtextlabel
01some example data1
12some more data0
\n", + "
" + ], + "text/plain": [ + " row text label\n", + "0 1 some example data 1\n", + "1 2 some more data 0" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Do cool stuff here\n", + "df = pd.read_csv(\"data/data.csv\")\n", + "df.head()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.10.4" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/example/requirements.txt b/notebooks/example/requirements.txt new file mode 100644 index 00000000..976a2b1f --- /dev/null +++ b/notebooks/example/requirements.txt @@ -0,0 +1 @@ +transformers From 66891dd690d86f341c76bd249a89f7c2235ffe00 Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Mon, 9 Jan 2023 15:22:43 +0100 Subject: [PATCH 39/43] added paths to pull_request for deploy docs --- .github/workflows/deploy-docs-site.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-docs-site.yaml b/.github/workflows/deploy-docs-site.yaml index d3fee6cb..721a5b30 100644 --- a/.github/workflows/deploy-docs-site.yaml +++ b/.github/workflows/deploy-docs-site.yaml @@ -8,6 +8,9 @@ on: - ".github/workflows/deploy-docs-site.yaml" - "docs/**" pull_request: + paths: + - ".github/workflows/deploy-docs-site.yaml" + - "docs/**" jobs: deploy: From 420b3739eb90a58fd0ec99a6a0dc33d2467ee956 Mon Sep 17 00:00:00 2001 From: James Melvin Date: Mon, 9 Jan 2023 22:31:44 +0530 Subject: [PATCH 40/43] fix: retrieval of valid_labels from API to populate the TEXT_LABEL_FLAGS in FlaggableElements.tsx --- website/src/components/FlaggableElement.tsx | 59 +++++-------------- website/src/components/Messages.tsx | 24 +++++++- website/src/components/Tasks/CreateTask.tsx | 6 +- website/src/lib/oasst_api_client.ts | 33 +++++++++++ website/src/pages/api/new_task/[task_type].ts | 6 ++ 5 files changed, 79 insertions(+), 49 deletions(-) diff --git a/website/src/components/FlaggableElement.tsx b/website/src/components/FlaggableElement.tsx index 63370444..df7296cc 100644 --- a/website/src/components/FlaggableElement.tsx +++ b/website/src/components/FlaggableElement.tsx @@ -27,8 +27,22 @@ import poster from "src/lib/poster"; import { colors } from "styles/Theme/colors"; import useSWRMutation from "swr/mutation"; +interface textFlagLabels { + attributeName: string; + labelText: string; + additionalExplanation?: string; +} + export const FlaggableElement = (props) => { const [isEditing, setIsEditing] = useBoolean(); + const flaggable_labels = props.flaggable_labels; + const TEXT_LABEL_FLAGS = flaggable_labels.valid_labels.map((valid_label) => { + return { + attributeName: valid_label.name, + labelText: valid_label.display_text, + additionalExplanation: valid_label.help_text, + }; + }); const { trigger } = useSWRMutation("/api/set_label", poster, { onSuccess: () => { setIsEditing.off; @@ -181,48 +195,3 @@ export function FlagCheckbox(props: { ); } -interface textFlagLabels { - attributeName: string; - labelText: string; - additionalExplanation?: string; -} -const TEXT_LABEL_FLAGS: textFlagLabels[] = [ - // For the time being this list is configured on the FE. - // In the future it may be provided by the API. - // { - // attributeName: "fails_task", - // labelText: "Fails to follow the correct instruction / task", - // additionalExplanation: "__TODO__", - // }, - // { - // attributeName: "not_customer_assistant_appropriate", - // labelText: "Inappropriate for customer assistant", - // additionalExplanation: "__TODO__", - // }, - { - attributeName: "sexual_content", - labelText: "Contains sexual content", - }, - { - attributeName: "violence", - labelText: "Contains violent content", - }, - // { - // attributeName: "encourages_violence", - // labelText: "Encourages or fails to discourage violence/abuse/terrorism/self-harm", - // }, - // { - // attributeName: "denigrates_a_protected_class", - // labelText: "Denigrates a protected class", - // }, - // { - // attributeName: "gives_harmful_advice", - // labelText: "Fails to follow the correct instruction / task", - // additionalExplanation: - // "The advice given in the output is harmful or counter-productive. This may be in addition to, but is distinct from the question about encouraging violence/abuse/terrorism/self-harm.", - // }, - // { - // attributeName: "expresses_moral_judgement", - // labelText: "Expresses moral judgement", - // }, -]; diff --git a/website/src/components/Messages.tsx b/website/src/components/Messages.tsx index fb84559e..71ff237b 100644 --- a/website/src/components/Messages.tsx +++ b/website/src/components/Messages.tsx @@ -10,11 +10,31 @@ export interface Message { message_id: string; } -export const Messages = ({ messages, post_id }: { messages: Message[]; post_id: string }) => { +export interface ValidLabel { + name: string; + display_text: string; + help_text: string; +} + +export const Messages = ({ + messages, + post_id, + valid_labels, +}: { + messages: Message[]; + post_id: string; + valid_labels: ValidLabel[]; +}) => { const items = messages.map((messageProps: Message, i: number) => { const { message_id, text } = messageProps; return ( - + ); diff --git a/website/src/components/Tasks/CreateTask.tsx b/website/src/components/Tasks/CreateTask.tsx index 7dcb0d0f..7af262e1 100644 --- a/website/src/components/Tasks/CreateTask.tsx +++ b/website/src/components/Tasks/CreateTask.tsx @@ -18,7 +18,7 @@ export interface CreateTaskProps { } export const CreateTask = ({ tasks, taskType, trigger, onSkipTask, onNextTask, mainBgClasses }: CreateTaskProps) => { const task = tasks[0].task; - + const valid_labels = tasks[0].valid_labels; const [inputText, setInputText] = useState(""); const submitResponse = (task: { id: string }) => { @@ -42,7 +42,9 @@ export const CreateTask = ({ tasks, taskType, trigger, onSkipTask, onNextTask, m <>
{taskType.label}

{taskType.overview}

- {task.conversation ? : null} + {task.conversation ? ( + + ) : null} <>
{taskType.instruction}
diff --git a/website/src/lib/oasst_api_client.ts b/website/src/lib/oasst_api_client.ts index 889d8b5b..1bbb13a8 100644 --- a/website/src/lib/oasst_api_client.ts +++ b/website/src/lib/oasst_api_client.ts @@ -48,6 +48,33 @@ export class OasstApiClient { return await resp.json(); } + private async get(path: string): Promise { + const resp = await fetch(`${this.oasstApiUrl}${path}`, { + method: "GET", + headers: { + "X-API-Key": this.oasstApiKey, + "Content-Type": "application/json", + }, + }); + + if (resp.status == 204) { + return null; + } + + if (resp.status >= 300) { + const errorText = await resp.text(); + let error: any; + try { + error = JSON.parse(errorText); + } catch (e) { + throw new OasstError(errorText, 0, resp.status); + } + throw new OasstError(error.message ?? error, error.error_code, resp.status); + } + + return await resp.json(); + } + // TODO return a strongly typed Task? // This method is used to store a task in RegisteredTask.task. // This is a raw Json type, so we can't use it to strongly type the task. @@ -96,6 +123,12 @@ export class OasstApiClient { ...content, }); } + + //Fetch valid labels. This is called every task. though the call may be redundant + //keeping this for future where the valid labels may change per task + async fetch_valid_text(): Promise { + return this.get(`/api/v1/text_labels/valid_labels`); + } } export const oasstApiClient = diff --git a/website/src/pages/api/new_task/[task_type].ts b/website/src/pages/api/new_task/[task_type].ts index 9f3be55c..a685d589 100644 --- a/website/src/pages/api/new_task/[task_type].ts +++ b/website/src/pages/api/new_task/[task_type].ts @@ -23,6 +23,7 @@ const handler = async (req, res) => { // Fetch the new task. const task = await oasstApiClient.fetchTask(task_type, token); + const valid_labels = await oasstApiClient.fetch_valid_text(); // Store the task and link it to the user.. const registeredTask = await prisma.registeredTask.create({ @@ -36,6 +37,11 @@ const handler = async (req, res) => { }, }); + // Add the valid labels that can be used to flag messages in this Task + registeredTask["valid_labels"] = valid_labels; + // Update the backend with our Task ID + await oasstApiClient.ackTask(task.id, registeredTask.id); + // Send the results to the client. res.status(200).json(registeredTask); }; From c33c9887dd1452828dcf0c9cb8145c3e96d91d9c Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Mon, 9 Jan 2023 21:23:39 +0100 Subject: [PATCH 41/43] improved pull request workflow --- .github/workflows/pre-commit.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 0f82185f..8395a06e 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_request: + pull_request_target: workflow_call: jobs: @@ -17,7 +17,7 @@ jobs: python-version: "3.10" - uses: pre-commit/action@v3.0.0 - name: Post PR comment on failure - if: failure() && github.event_name == 'pull_request' + if: failure() && github.event_name == 'pull_request_target' uses: peter-evans/create-or-update-comment@v2 with: issue-number: ${{ github.event.pull_request.number }} From 156e1bca7d82ea8036297287cf0631bb440ed037 Mon Sep 17 00:00:00 2001 From: Yannic Kilcher Date: Mon, 9 Jan 2023 21:25:04 +0100 Subject: [PATCH 42/43] it was a bad fix --- .github/workflows/pre-commit.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 8395a06e..0f82185f 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_request_target: + pull_request: workflow_call: jobs: @@ -17,7 +17,7 @@ jobs: python-version: "3.10" - uses: pre-commit/action@v3.0.0 - name: Post PR comment on failure - if: failure() && github.event_name == 'pull_request_target' + if: failure() && github.event_name == 'pull_request' uses: peter-evans/create-or-update-comment@v2 with: issue-number: ${{ github.event.pull_request.number }} From defd453639f96798c3431dde454c6b51ee24624e Mon Sep 17 00:00:00 2001 From: Andrew Maguire Date: Mon, 9 Jan 2023 22:59:00 +0000 Subject: [PATCH 43/43] replace `andrewm4894` with `LAION-AI` now that example notebook is merged (#573) --- notebooks/example/README.md | 2 +- notebooks/example/example.ipynb | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/notebooks/example/README.md b/notebooks/example/README.md index 2136834d..763b4812 100644 --- a/notebooks/example/README.md +++ b/notebooks/example/README.md @@ -1,6 +1,6 @@ # Example Notebook -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andrewm4894/Open-Assistant/blob/main/notebooks/example/example.ipynb) +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/LAION-AI/Open-Assistant/blob/main/notebooks/example/example.ipynb) This folder contains an example reference notebook structure and approach for this project. Please try and follow this structure as closely as possible. While diff --git a/notebooks/example/example.ipynb b/notebooks/example/example.ipynb index 2c6b1e01..5f938c13 100644 --- a/notebooks/example/example.ipynb +++ b/notebooks/example/example.ipynb @@ -9,10 +9,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andrewm4894/Open-Assistant/blob/example-notebook/notebooks/example/example.ipynb)" + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/LAION-AI/Open-Assistant/blob/example-notebook/notebooks/example/example.ipynb)" ] }, { @@ -22,7 +23,7 @@ "outputs": [], "source": [ "# uncomment and run below lines to set up if running in colab\n", - "# !git clone https://github.com/andrewm4894/Open-Assistant.git\n", + "# !git clone https://github.com/LAION-AI/Open-Assistant.git\n", "# %cd Open-Assistant/notebooks/example\n", "# !pip install -r requirements.txt" ] @@ -146,12 +147,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]" }, "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" + "hash": "25d5c2324055587ceaeef27650c79ce8358ea61d7689f2e0b8ada5d53f85bce4" } } },