Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #56 from mindvalley/chore/merge-upstream-1709202401
Browse files Browse the repository at this point in the history
matching code with latest upstream
  • Loading branch information
onimsha authored Sep 17, 2024
2 parents f8c5834 + dce8c32 commit bb90741
Show file tree
Hide file tree
Showing 72 changed files with 1,843 additions and 655 deletions.
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ founders@danswer.ai for more information. Please visit https://github.com/danswe

# Default DANSWER_VERSION, typically overriden during builds by GitHub Actions.
ARG DANSWER_VERSION=0.3-dev
ENV DANSWER_VERSION=${DANSWER_VERSION}
ENV DANSWER_VERSION=${DANSWER_VERSION} \
DANSWER_RUNNING_IN_DOCKER="true"

RUN echo "DANSWER_VERSION: ${DANSWER_VERSION}"
# Install system dependencies
Expand Down
18 changes: 10 additions & 8 deletions backend/Dockerfile.model_server
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ visit https://github.com/danswer-ai/danswer."

# Default DANSWER_VERSION, typically overriden during builds by GitHub Actions.
ARG DANSWER_VERSION=0.3-dev
ENV DANSWER_VERSION=${DANSWER_VERSION}
ENV DANSWER_VERSION=${DANSWER_VERSION} \
DANSWER_RUNNING_IN_DOCKER="true"


RUN echo "DANSWER_VERSION: ${DANSWER_VERSION}"

COPY ./requirements/model_server.txt /tmp/requirements.txt
Expand All @@ -21,16 +24,15 @@ RUN apt-get remove -y --allow-remove-essential perl-base && \
# Download tokenizers, distilbert for the Danswer model
# Download model weights
# Run Nomic to pull in the custom architecture and have it cached locally
# RUN python -c "from transformers import AutoTokenizer; \
# from huggingface_hub import snapshot_download; \
# snapshot_download(repo_id='danswer/hybrid-intent-token-classifier', revision='v1.0.3'); \
# snapshot_download('nomic-ai/nomic-embed-text-v1'); \
# from sentence_transformers import SentenceTransformer; \
# SentenceTransformer(model_name_or_path='nomic-ai/nomic-embed-text-v1', trust_remote_code=True);"
RUN python -c "from transformers import AutoTokenizer; \
AutoTokenizer.from_pretrained('mixedbread-ai/mxbai-rerank-xsmall-v1'); \
from huggingface_hub import snapshot_download; \
snapshot_download(repo_id='danswer/hybrid-intent-token-classifier', revision='v1.0.3'); \
snapshot_download('mixedbread-ai/mxbai-rerank-xsmall-v1');"

# In case the user has volumes mounted to /root/.cache/huggingface that they've downloaded while
# running Danswer, don't overwrite it with the built in cache folder
# RUN mv /root/.cache/huggingface /root/.cache/temp_huggingface
RUN mv /root/.cache/huggingface /root/.cache/temp_huggingface

WORKDIR /app

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def upgrade() -> None:
op.add_column(
"search_settings",
sa.Column(
"multipass_indexing", sa.Boolean(), nullable=False, server_default="true"
"multipass_indexing", sa.Boolean(), nullable=False, server_default="false"
),
)
op.add_column(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""server default chosen assistants
Revision ID: 35e6853a51d5
Revises: c99d76fcd298
Create Date: 2024-09-13 13:20:32.885317
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "35e6853a51d5"
down_revision = "c99d76fcd298"
branch_labels = None
depends_on = None

DEFAULT_ASSISTANTS = [-2, -1, 0]


def upgrade() -> None:
op.alter_column(
"user",
"chosen_assistants",
type_=postgresql.JSONB(astext_type=sa.Text()),
nullable=False,
server_default=sa.text(f"'{DEFAULT_ASSISTANTS}'::jsonb"),
)


def downgrade() -> None:
op.alter_column(
"user",
"chosen_assistants",
type_=postgresql.JSONB(astext_type=sa.Text()),
nullable=True,
server_default=None,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Create Date: 2024-04-13 18:07:29.153817
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""match_any_keywords flag for standard answers
Revision ID: 5c7fdadae813
Revises: efb35676026c
Create Date: 2024-09-13 18:52:59.256478
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "5c7fdadae813"
down_revision = "efb35676026c"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"standard_answer",
sa.Column(
"match_any_keywords",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("standard_answer", "match_any_keywords")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Create Date: 2024-04-15 01:36:02.952809
"""

import json
from typing import cast
from alembic import op
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""add nullable to persona id in Chat Session
Revision ID: c99d76fcd298
Revises: 5c7fdadae813
Create Date: 2024-07-09 19:27:01.579697
"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "c99d76fcd298"
down_revision = "5c7fdadae813"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column(
"chat_session", "persona_id", existing_type=sa.INTEGER(), nullable=True
)


def downgrade() -> None:
op.alter_column(
"chat_session",
"persona_id",
existing_type=sa.INTEGER(),
nullable=False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Create Date: 2024-04-28 16:59:33.199153
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""standard answer match_regex flag
Revision ID: efb35676026c
Revises: 52a219fb5233
Create Date: 2024-09-11 13:55:46.101149
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "efb35676026c"
down_revision = "0ebb1d516877"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"standard_answer",
sa.Column(
"match_regex", sa.Boolean(), nullable=False, server_default=sa.false()
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("standard_answer", "match_regex")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Create Date: 2024-04-25 17:05:09.695703
"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
15 changes: 14 additions & 1 deletion backend/danswer/auth/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ async def oauth_callback(
associate_by_email: bool = False,
is_verified_by_default: bool = False,
) -> models.UOAP:
verify_email_in_whitelist(account_email)
verify_email_domain(account_email)

user = await super().oauth_callback( # type: ignore
Expand Down Expand Up @@ -267,6 +268,7 @@ async def oauth_callback(
)
user.is_verified = is_verified_by_default
user.has_web_login = True

return user

async def on_after_register(
Expand Down Expand Up @@ -413,6 +415,7 @@ async def optional_user(
async def double_check_user(
user: User | None,
optional: bool = DISABLE_AUTH,
include_expired: bool = False,
) -> User | None:
if optional:
return None
Expand All @@ -429,7 +432,11 @@ async def double_check_user(
detail="Access denied. User is not verified.",
)

if user.oidc_expiry and user.oidc_expiry < datetime.now(timezone.utc):
if (
user.oidc_expiry
and user.oidc_expiry < datetime.now(timezone.utc)
and not include_expired
):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Access denied. User's OIDC token has expired.",
Expand All @@ -438,6 +445,12 @@ async def double_check_user(
return user


async def current_user_with_expired_token(
user: User | None = Depends(optional_user),
) -> User | None:
return await double_check_user(user, include_expired=True)


async def current_user(
user: User | None = Depends(optional_user),
) -> User | None:
Expand Down
Loading

0 comments on commit bb90741

Please sign in to comment.