Skip to content

Commit 74209da

Browse files
Merge branch 'main' into main
2 parents 78803e0 + 26b2db5 commit 74209da

46 files changed

Lines changed: 35345 additions & 8748 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ We can then take the resulting model and continue with completion sampling step
3333

3434
We are not going to stop at replicating ChatGPT. We want to build the assistant of the future, able to not only write email and cover letters, but do meaningful work, use APIs, dynamically research information, and much more, with the ability to be personalized and extended by anyone. And we want to do this in a way that is open and accessible, which means we must not only build a great assistant, but also make it small and efficient enough to run on consumer hardware.
3535

36+
### Slide Decks
37+
38+
[Important Data Structures](https://docs.google.com/presentation/d/1iaX_nxasVWlvPiSNs0cllR9L_1neZq0RJxd6MFEalUY/edit?usp=sharing)
39+
3640
## How can you help?
3741

3842
All open source projects begins with people like you. Open source is the belief that if we collaborate we can together gift our knowledge and technology to the world for the benefit of humanity.
3943

4044
## I’m in! Now what?
4145

42-
[Fill out the contributor signup form](https://docs.google.com/forms/d/e/1FAIpQLSeuggO7UdYkBvGLEJldDvxp6DwaRbW5p7dl96UzFkZgziRTrQ/viewform)
43-
4446
[Join the LAION Discord Server!](https://discord.com/invite/mVcgxMPD7e)
4547

48+
[and / or the YK Discord Server](https://ykilcher.com/discord)
49+
4650
[Visit the Notion](https://ykilcher.com/open-assistant)
4751

4852
### Taking on Tasks
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
"""post ref for work_package
3+
4+
Revision ID: d24b37426857
5+
Revises: 3358eb6834e6
6+
Create Date: 2022-12-28 11:42:26.773704
7+
8+
"""
9+
import sqlalchemy as sa
10+
import sqlmodel
11+
from alembic import op
12+
from sqlalchemy.dialects import postgresql
13+
14+
# revision identifiers, used by Alembic.
15+
revision = "d24b37426857"
16+
down_revision = "3358eb6834e6"
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.add_column("post", sa.Column("depth", sa.Integer(), server_default=sa.text("0"), nullable=False))
24+
op.add_column("post", sa.Column("children_count", sa.Integer(), server_default=sa.text("0"), nullable=False))
25+
op.add_column("post_reaction", sa.Column("work_package_id", postgresql.UUID(as_uuid=True), nullable=False))
26+
op.drop_constraint("post_reaction_post_id_fkey", "post_reaction", type_="foreignkey")
27+
op.create_foreign_key(None, "post_reaction", "work_package", ["work_package_id"], ["id"])
28+
op.drop_column("post_reaction", "post_id")
29+
op.add_column("work_package", sa.Column("done", sa.Boolean(), server_default=sa.text("false"), nullable=False))
30+
op.add_column("work_package", sa.Column("ack", sa.Boolean(), nullable=True))
31+
op.add_column("work_package", sa.Column("frontend_ref_post_id", sqlmodel.sql.sqltypes.AutoString(), nullable=True))
32+
op.add_column("work_package", sa.Column("thread_id", sqlmodel.sql.sqltypes.GUID(), nullable=True))
33+
op.add_column("work_package", sa.Column("parent_post_id", sqlmodel.sql.sqltypes.GUID(), nullable=True))
34+
# ### end Alembic commands ###
35+
36+
37+
def downgrade() -> None:
38+
# ### commands auto generated by Alembic - please adjust! ###
39+
op.drop_column("work_package", "parent_post_id")
40+
op.drop_column("work_package", "thread_id")
41+
op.drop_column("work_package", "frontend_ref_post_id")
42+
op.drop_column("work_package", "ack")
43+
op.drop_column("work_package", "done")
44+
op.add_column("post_reaction", sa.Column("post_id", postgresql.UUID(), autoincrement=False, nullable=False))
45+
op.drop_constraint(None, "post_reaction", type_="foreignkey")
46+
op.create_foreign_key("post_reaction_post_id_fkey", "post_reaction", "post", ["post_id"], ["id"])
47+
op.drop_column("post_reaction", "work_package_id")
48+
op.drop_column("post", "children_count")
49+
op.drop_column("post", "depth")
50+
# ### end Alembic commands ###

backend/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from http import HTTPStatus
23
from pathlib import Path
34

45
import alembic.command
@@ -7,10 +8,29 @@
78
from loguru import logger
89
from oasst_backend.api.v1.api import api_router
910
from oasst_backend.config import settings
11+
from oasst_backend.exceptions import OasstError, OasstErrorCode
1012
from starlette.middleware.cors import CORSMiddleware
1113

1214
app = fastapi.FastAPI(title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json")
1315

16+
17+
@app.exception_handler(OasstError)
18+
async def oasst_exception_handler(request: fastapi.Request, ex: OasstError):
19+
logger.error(f"{request.method} {request.url} failed: {repr(ex)}")
20+
return fastapi.responses.JSONResponse(
21+
status_code=int(ex.http_status_code), content={"message": ex.message, "error_code": ex.error_code}
22+
)
23+
24+
25+
@app.exception_handler(Exception)
26+
async def unhandled_exception_handler(request: fastapi.Request, ex: Exception):
27+
logger.exception(f"{request.method} {request.url} failed [UNHANDLED]: {repr(ex)}")
28+
status = HTTPStatus.INTERNAL_SERVER_ERROR
29+
return fastapi.responses.JSONResponse(
30+
status_code=status.value, content={"message": status.name, "error_code": OasstErrorCode.GENERIC_ERROR}
31+
)
32+
33+
1434
# Set all CORS enabled origins
1535
if settings.BACKEND_CORS_ORIGINS:
1636
app.add_middleware(

backend/oasst_backend/api/deps.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# -*- coding: utf-8 -*-
2+
from http import HTTPStatus
23
from secrets import token_hex
34
from typing import Generator
45
from uuid import UUID
56

6-
from fastapi import HTTPException, Security
7+
from fastapi import Security
78
from fastapi.security.api_key import APIKey, APIKeyHeader, APIKeyQuery
89
from loguru import logger
910
from oasst_backend.config import settings
1011
from oasst_backend.database import engine
12+
from oasst_backend.exceptions import OasstError, OasstErrorCode
1113
from oasst_backend.models import ApiClient
1214
from sqlmodel import Session
13-
from starlette.status import HTTP_403_FORBIDDEN
1415

1516

1617
def get_db() -> Generator:
@@ -36,22 +37,26 @@ def api_auth(
3637
api_key: APIKey,
3738
db: Session,
3839
) -> ApiClient:
39-
40-
if api_key is None and not settings.DEBUG_SKIP_API_KEY_CHECK:
41-
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials")
42-
43-
if settings.DEBUG_SKIP_API_KEY_CHECK or settings.DEBUG_ALLOW_ANY_API_KEY:
44-
# make sure that a dummy api key exits in db (foreign key references)
45-
ANY_API_KEY_ID = UUID("00000000-1111-2222-3333-444444444444")
46-
api_client: ApiClient = db.query(ApiClient).filter(ApiClient.id == ANY_API_KEY_ID).first()
47-
if api_client is None:
48-
token = token_hex(32)
49-
logger.info(f"ANY_API_KEY missing, inserting api_key: {token}")
50-
api_client = ApiClient(id=ANY_API_KEY_ID, api_key=token, description="ANY_API_KEY, random token")
51-
db.add(api_client)
52-
db.commit()
53-
return api_client
54-
55-
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
56-
if api_client is not None and api_client.enabled:
57-
return api_client
40+
if api_key or settings.DEBUG_SKIP_API_KEY_CHECK:
41+
42+
if settings.DEBUG_SKIP_API_KEY_CHECK or settings.DEBUG_ALLOW_ANY_API_KEY:
43+
# make sure that a dummy api key exits in db (foreign key references)
44+
ANY_API_KEY_ID = UUID("00000000-1111-2222-3333-444444444444")
45+
api_client: ApiClient = db.query(ApiClient).filter(ApiClient.id == ANY_API_KEY_ID).first()
46+
if api_client is None:
47+
token = token_hex(32)
48+
logger.info(f"ANY_API_KEY missing, inserting api_key: {token}")
49+
api_client = ApiClient(id=ANY_API_KEY_ID, api_key=token, description="ANY_API_KEY, random token")
50+
db.add(api_client)
51+
db.commit()
52+
return api_client
53+
54+
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
55+
if api_client is not None and api_client.enabled:
56+
return api_client
57+
58+
raise OasstError(
59+
"Could not validate credentials",
60+
error_code=OasstErrorCode.API_CLIENT_NOT_AUTHORIZED,
61+
http_status_code=HTTPStatus.FORBIDDEN,
62+
)

0 commit comments

Comments
 (0)