Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple asr models at the same time #164

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5afdf8b
multiple asr models
SanderGi Sep 20, 2023
3e66d59
Fix: add trailing slash at the end of canonical URLs
nikochiko Sep 20, 2023
8f76750
if the user submits an api call with only a run id, assume their uid …
devxpy Sep 21, 2023
80ecccb
fix type error
devxpy Sep 21, 2023
630411d
force create personal channels button
devxpy Sep 22, 2023
cb69ab6
handle user_team_not_in_channel
devxpy Sep 22, 2023
80b42a3
slack personal channel support for shortcuts
devxpy Sep 22, 2023
0d2e55a
slack personal channel support for shortcuts
devxpy Sep 22, 2023
2d4b4c0
remove the dm query param
devxpy Sep 22, 2023
d637105
send back the connected example_id and run_id with slack shortcuts re…
devxpy Sep 22, 2023
f0241a8
Add Procfile to start all services with one command
Sep 20, 2023
053837d
Procfile: aoivd specifying an explicit shell from gooey-ui's command
Sep 20, 2023
719efc2
Add instructions for postgresql installation, prefer background servi…
nikochiko Sep 20, 2023
d3eaa4c
Use sqlcreate helper for creating user/db
nikochiko Sep 21, 2023
3f7b9d9
Added metadata images for workflows
ravishankar63 Sep 15, 2023
c89524c
added docsummary and lipsync images
ravishankar63 Sep 21, 2023
5beb24f
done
SanderGi Sep 26, 2023
48b1e7d
fix slack text split
devxpy Sep 27, 2023
4e8b854
use member join event instead of message event
SanderGi Sep 23, 2023
72531bf
smol refactor: invert if-condition
devxpy Sep 27, 2023
0f9fddf
fix attr error
devxpy Sep 27, 2023
2accf94
add /__/slack/get-response-for-msg/{msg_id}/ for apple shortcuts
devxpy Sep 27, 2023
6d494bb
fix TypeError
devxpy Sep 27, 2023
b24e3b4
fix KeyError 'team'
devxpy Sep 27, 2023
fdadabb
invoke shortcut via the shortcuts://run-shortcuts url
devxpy Sep 27, 2023
e9ba0b8
return raw_tts_text from videobots & get-response-for-msg api
devxpy Sep 27, 2023
bda8f22
citation symbols
devxpy Sep 27, 2023
363b354
better tests that run faster
devxpy Oct 3, 2023
98ee8ff
update lock file
devxpy Oct 3, 2023
0b2747e
fix imports
devxpy Oct 3, 2023
88c3afc
fix slack test
devxpy Oct 3, 2023
ef13ddb
fix img2img request spec
devxpy Oct 3, 2023
5e040b1
fix img2img request spec
devxpy Oct 3, 2023
b859658
fix bulk runner for img2img
devxpy Oct 3, 2023
319327f
bugfix: strip qr_code_data *before* checking for none/blank
nikochiko Oct 4, 2023
7629659
refactor asr code
devxpy Oct 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
APP_BASE_URL=http://localhost:3000
API_BASE_URL=http://localhost:8080
GS_BUCKET_NAME=dara-c1b52.appspot.com
PGHOST=127.0.0.1
PGPORT=5432
PGUSER=gooey
PGDATABASE=gooey
PGPASSWORD=gooey
22 changes: 22 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# this Procfile can be run with `honcho`, and it can start multiple processes
# with a single command. Handy for development. All of the below commands are
# setup to run in dev mode only, and not in prod.
#
# The assumptions here are that:
# - you have redis installed but not running as a background service
# - you have rabbitmq installed but not running as a background service
# - your local gooey-ui repo is at ../gooey-ui/
#
# You can comment any of the processes if you have background services running
# for them. You can also change the path for the `ui` process from `../gooey-ui/`
# to wherever your local gooey-ui directory is.

api: poetry run uvicorn server:app --host 127.0.0.1 --port 8080 --reload

admin: poetry run python manage.py runserver 127.0.0.1:8000

dashboard: poetry run streamlit run Home.py --server.port 8501 --server.headless true

celery: poetry run celery -A celeryapp worker

ui: cd ../gooey-ui/; PORT=3000 npm run dev
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
## Setup

* Install [pyenv](https://github.com/pyenv/pyenv) & install the same python version as in our [Dockerfile](Dockerfile)
* Install [poetry](https://python-poetry.org/docs/)
* Create & active a virtualenv (e.g. `poetry shell`)
* Create & activate a virtualenv (e.g. `poetry shell`)
* Run `poetry install --with dev`
* Install [redis](https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/), [rabbitmq](https://www.rabbitmq.com/install-homebrew.html), and [postgresql](https://formulae.brew.sh/formula/postgresql@15) (e.g. `brew install redis rabbitmq postgresql@15`)
* Enable background services for `redis`, `rabbitmq`, and `postgresql` (e.g. with `brew services start redis` and similar for `rabbitmq` and `postgresql`)
* Use `sqlcreate` helper to create a user and database for gooey:
* `./manage.py sqlcreate | psql postgres`
* make sure you are able to access the database with `psql -W -U gooey gooey` (and when prompted for password, entering `gooey`)
* Create an `.env` file from `.env.example` (Read [12factor.net/config](https://12factor.net/config))
* Run `./manage.py migrate`
* Install the zbar library (`brew install zbar`)

## Run

### API + GUI server

```bash
uvicorn server:app --host 0.0.0.0 --port 8080 --reload
```

Open [localhost:8080](localhost:8080) in your browser

### Admin Site
You can start all required processes in one command with Honcho:

```bash
python3 manage.py runserver 0.0.0.0:8000
```shell
$ poetry run honcho start
```

Open [localhost:8000](localhost:8000) in your browser

The processes that it starts are defined in [`Procfile`](Procfile).
Currently they are these:

### Usage Dashboard
| Service | Port |
| ------- | ---- |
| API + GUI Server | 8080 |
| Admin site | 8000 |
| Usage dashboard | 8501 |
| Celery | - |
| UI | 3000 |

```
streamlit run Home.py --server.port 8501
```
This default startup assumes that Redis, RabbitMQ, and PostgreSQL are installed and running
as background services on ports 6379, 5672, and 5432 respectively.
It also assumes that the gooey-ui repo can be found at `../gooey-ui/` (adjacent to where the
gooey-server repo sits). You can open the Procfile and comment this out if you don't need
to run it.

Open [localhost:8501](localhost:8501) in your browser
**Note:** the Celery worker must be manually restarted on code changes. You
can do this by stopping and starting Honcho.

## To run any recipe

* Save `serviceAccountKey.json` to project root
* Install & start [redis](https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/)
* Install & start [rabbitmq](https://www.rabbitmq.com/install-homebrew.html)
* Run the celery worker (**Note:** you must manually restart it on code changes)
```bash
celery -A celeryapp worker
```

## To connect to our GPU cluster

Expand Down
29 changes: 15 additions & 14 deletions auth_backend.py → auth/auth_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,37 @@
from starlette.concurrency import run_in_threadpool

from app_users.models import AppUser
from daras_ai_v2.crypto import get_random_string, get_random_doc_id
from daras_ai_v2.crypto import get_random_doc_id
from daras_ai_v2.db import FIREBASE_SESSION_COOKIE, ANONYMOUS_USER_COOKIE
from gooeysite.bg_db_conn import db_middleware

# quick and dirty way to bypass authentication for testing
_forced_auth_user = []
authlocal = []


@contextmanager
def force_authentication():
user = AppUser.objects.create(
is_anonymous=True, uid=get_random_doc_id(), balance=10**9
authlocal.append(
AppUser.objects.get_or_create(
email="[email protected]",
defaults=dict(is_anonymous=True, uid=get_random_doc_id(), balance=10**9),
)[0]
)
try:
_forced_auth_user.append(user)
yield
yield authlocal[0]
finally:
_forced_auth_user.clear()
authlocal.clear()


class SessionAuthBackend(AuthenticationBackend):
async def authenticate(self, conn):
return await run_in_threadpool(authenticate, conn)
if authlocal:
return AuthCredentials(["authenticated"]), authlocal[0]
return await run_in_threadpool(_authenticate, conn)


@db_middleware
def authenticate(conn):
if _forced_auth_user:
return AuthCredentials(["authenticated"]), _forced_auth_user[0]

def _authenticate(conn):
session_cookie = conn.session.get(FIREBASE_SESSION_COOKIE)
if not session_cookie:
# Session cookie is unavailable. Check if anonymous user is available.
Expand All @@ -51,7 +52,7 @@ def authenticate(conn):
# Session cookie is unavailable. Force user to login.
return AuthCredentials(), None

user = verify_session_cookie(session_cookie)
user = _verify_session_cookie(session_cookie)
if not user:
# Session cookie was invalid
conn.session.pop(FIREBASE_SESSION_COOKIE, None)
Expand All @@ -60,7 +61,7 @@ def authenticate(conn):
return AuthCredentials(["authenticated"]), user


def verify_session_cookie(firebase_cookie: str) -> UserRecord | None:
def _verify_session_cookie(firebase_cookie: str) -> UserRecord | None:
# Verify the session cookie. In this case an additional check is added to detect
# if the user's Firebase session was revoked, user deleted/disabled, etc.
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import threading

from fastapi import Header
from fastapi.exceptions import HTTPException

from app_users.models import AppUser
from auth_backend import _forced_auth_user
from auth.auth_backend import authlocal
from daras_ai_v2 import db
from daras_ai_v2.crypto import PBKDF2PasswordHasher

Expand All @@ -15,9 +17,8 @@ def api_auth_header(
description=f"{auth_keyword} $GOOEY_API_KEY",
),
) -> AppUser:
if _forced_auth_user:
return _forced_auth_user[0]

if authlocal:
return authlocal[0]
return authenticate(authorization)


Expand Down
12 changes: 12 additions & 0 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Conversation,
BotIntegration,
)
from bots.tasks import create_personal_channels_for_all_members
from gooeysite.custom_widgets import JSONEditorWidget


Expand Down Expand Up @@ -84,6 +85,15 @@ class Media:
]


def create_personal_channels(modeladmin, request, queryset):
for bi in queryset:
create_personal_channels_for_all_members.delay(bi.id)
modeladmin.message_user(
request,
f"Started creating personal channels for {queryset.count()} bots in the background.",
)


@admin.register(BotIntegration)
class BotIntegrationAdmin(admin.ModelAdmin):
search_fields = [
Expand Down Expand Up @@ -190,6 +200,8 @@ class BotIntegrationAdmin(admin.ModelAdmin):
),
]

actions = [create_personal_channels]

@admin.display(description="Messages")
def view_messsages(self, bi: BotIntegration):
return list_related_html_url(
Expand Down
3 changes: 2 additions & 1 deletion bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Workflow(models.IntegerChoices):
RELATED_QNA_MAKER = (27, "Related QnA Maker")
RELATED_QNA_MAKER_DOC = (28, "Related QnA Maker Doc")
EMBEDDINGS = (29, "Embeddings")
BULK_RUNNER = (30, "Bulk Runner")

@property
def short_slug(self):
Expand Down Expand Up @@ -239,7 +240,7 @@ def submit_api_call(
kwds=dict(
page_cls=Workflow(self.workflow).page_cls,
query_params=dict(
example_id=self.example_id, run_id=self.id, uid=self.uid
example_id=self.example_id, run_id=self.run_id, uid=self.uid
),
user=current_user,
request_body=request_body,
Expand Down
4 changes: 2 additions & 2 deletions bots/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CHATML_ROLE_ASSISSTANT = "assistant"


def test_add_balance_direct():
def test_add_balance_direct(transactional_db):
pk = AppUser.objects.create(balance=0, is_anonymous=False).pk
amounts = [[random.randint(-100, 10_000) for _ in range(100)] for _ in range(5)]

Expand All @@ -28,7 +28,7 @@ def worker(amts):
assert AppUser.objects.get(pk=pk).balance == sum(map(sum, amounts))


def test_create_bot_integration_conversation_message():
def test_create_bot_integration_conversation_message(transactional_db):
# Create a new BotIntegration with WhatsApp as the platform
bot_integration = BotIntegration.objects.create(
name="My Bot Integration",
Expand Down
Loading