From aa26c4ad0387531d41ab5300f284dd2bac946048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6pf?= Date: Tue, 20 Dec 2022 00:55:39 +0100 Subject: [PATCH] fix bot script post oasst_shared creation --- .gitignore | 1 + bot/Makefile | 13 ---------- bot/README.md | 24 ++++++++++++------- bot/api_client.py | 2 +- bot/bot.py | 10 ++++---- bot/test_prompts.json | 10 -------- oasst-shared/oasst_shared/__init__.py | 0 oasst-shared/oasst_shared/schemas/__init__.py | 0 scripts/frontend-development/run-bot-local.sh | 9 +++++++ 9 files changed, 31 insertions(+), 38 deletions(-) delete mode 100644 bot/Makefile delete mode 100644 bot/test_prompts.json create mode 100644 oasst-shared/oasst_shared/__init__.py create mode 100644 oasst-shared/oasst_shared/schemas/__init__.py create mode 100755 scripts/frontend-development/run-bot-local.sh diff --git a/.gitignore b/.gitignore index 2c698b44..293cd36b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .venv +.env *.pyc *.swp *.egg-info diff --git a/bot/Makefile b/bot/Makefile deleted file mode 100644 index 87f07026..00000000 --- a/bot/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -install: - python -m pip install -U pip - python -m pip install -e . - -lint: ## [Local development] Run pylint and black - python -m pylint app - python -m black --check -l 120 app - -black: ## [Local development] Auto-format python code using black - python -m black -l 120 . - -run: - python -m bot diff --git a/bot/README.md b/bot/README.md index fcc3bc33..a585b37f 100644 --- a/bot/README.md +++ b/bot/README.md @@ -1,14 +1,20 @@ -# open-assistant +# Open-Assistant Data Collection Discord Bot -This is the github repo for the open-assistant project. -We are currently building a discord bot in order to make everyone contribute with great prompts and answers. -Join us! -https://discord.gg/ZUfPw6jP +This bot collects human feedback to create a dataset for RLHF-alignment of an assistant chat bot based on a large langugae model. You and other people can teach the bot how to respond to user requests by demonstration and by garding and ranking the bot's outputs. If you want to learn more about RLHF please refer [to OpenAI's InstructGPT blog post](https://openai.com/blog/instruction-following/). -## Project description +## Invite official bot -We are calling the community for help to collect ChatGPT-like Instruction-Fulfillment datasamples via Discord. People can post Instructions they think would make sense for ChatGPT-like systems & also provide a good reference answer for it. +To add the official Open-Assistant data collection bot to your discord server [click here](https://discord.com/api/oauth2/authorize?client_id=1054078345542910022&permissions=1634235579456&scope=bot). The bot needs access to read the contents of user text messages. -## Todo +## Bot token for development -Figure out ouath flow for the app to work inside the open-chat-gpt testing channel here. https://discord.gg/JJSKtRhv +To test the bot on your own discord server you need to register a discord application at the [Discord Developer Portal](https://discord.com/developers/applications) and get at bot token. + +1. Follow a tutorial on how to get a bot token, for example this one: [Creating a discord bot & getting a token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) +2. The bot script expects the bot token to be in an environment variable called `BOT_TOKEN`. + +The simplest way to configure the token is via an `.env` file: + +``` +BOT_TOKEN=XYZABC123... +``` diff --git a/bot/api_client.py b/bot/api_client.py index 6fe39c8b..19a62188 100644 --- a/bot/api_client.py +++ b/bot/api_client.py @@ -3,7 +3,7 @@ import enum from typing import Optional, Type import requests -from schemas import protocol as protocol_schema +from oasst_shared.schemas import protocol as protocol_schema class TaskType(str, enum.Enum): diff --git a/bot/bot.py b/bot/bot.py index 376b0b3c..2d809646 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -181,8 +181,8 @@ class OpenAssistantBot: return msg async def next_task(self): - task = self.backend.fetch_task(protocol_schema.TaskRequestType.rate_summary, user=None) - # task = self.backend.fetch_random_task(user=None) + # task = self.backend.fetch_task(protocol_schema.TaskRequestType.rate_summary, user=None) + task = self.backend.fetch_random_task(user=None) msg: discord.Message = None match task.type: @@ -202,9 +202,9 @@ class OpenAssistantBot: msg = await self.generate_rank_conversation(task) if msg is not None: - await self.backend.ack_task(task.id, msg.id) + self.backend.ack_task(task.id, msg.id) else: - await self.backend.nack_task(task.id, "not supported") + self.backend.nack_task(task.id, "not supported") async def background_timer(self): while True: @@ -212,7 +212,7 @@ class OpenAssistantBot: try: await self.next_task() except Exception as e: - print(e) + print(e.with_traceback()) await asyncio.sleep(30) def run(self): diff --git a/bot/test_prompts.json b/bot/test_prompts.json deleted file mode 100644 index be892986..00000000 --- a/bot/test_prompts.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "prompt": "tell me the name of two dogs", - "responses": ["Charles", "bobby"] - }, - { - "prompt": "Name one type of cheese made in france", - "responses": ["Munster", "Gouda"] - } -] diff --git a/oasst-shared/oasst_shared/__init__.py b/oasst-shared/oasst_shared/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/oasst-shared/oasst_shared/schemas/__init__.py b/oasst-shared/oasst_shared/schemas/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/frontend-development/run-bot-local.sh b/scripts/frontend-development/run-bot-local.sh new file mode 100755 index 00000000..7308c541 --- /dev/null +++ b/scripts/frontend-development/run-bot-local.sh @@ -0,0 +1,9 @@ +#!/bin/bash +parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) + +# switch to bot directory +pushd "$parent_path/../../bot" + +python3 __main__.py + +popd