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

[NeuralChat] Support user management in backend server #952

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
029ab8f
Support user management backend part
lvliang-intel Dec 17, 2023
c12f7ec
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 24, 2024
912d190
fix ut issues
lvliang-intel Jan 24, 2024
b19e91e
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 24, 2024
68998d6
fix copyright
lvliang-intel Jan 24, 2024
d17e1ff
fix pylint issues
lvliang-intel Jan 25, 2024
dbdd3b4
support IntelLDAP
lvliang-intel Jan 26, 2024
b9b0a95
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 26, 2024
97972c9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 30, 2024
36a54b5
update code
lvliang-intel Jan 30, 2024
6f3ece9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 30, 2024
4cff30d
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
cbdbb38
fix pylint issue
lvliang-intel Jan 31, 2024
ded96da
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
072a19c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
abc55bf
fix email issue
lvliang-intel Jan 31, 2024
5707d8a
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
8bd4ad3
Merge branch 'lvl/user_management' of https://github.com/intel/intel-…
lvliang-intel Jan 31, 2024
80c2915
only verify account and password
lvliang-intel Feb 2, 2024
180a970
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Feb 2, 2024
59cc602
fix pylint
lvliang-intel Feb 2, 2024
b0768ee
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Feb 2, 2024
63798e7
Merge branch 'main' into lvl/user_management
lvliang-intel Feb 2, 2024
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
6 changes: 6 additions & 0 deletions .github/workflows/script/formatScan/pylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ fi
pip install git+https://github.com/EleutherAI/lm-evaluation-harness.git@83dbfbf6070324f3e5872f63e49d49ff7ef4c9b3
pip install accelerate nlpaug nltk schema optimum-intel==1.11.0 optimum==1.13.3 peft==0.6.2

apt-get install libldap2-dev -y
apt-get install libsasl2-dev -y
export PIP_INDEX_URL=https://ubit-artifactory-or.intel.com/artifactory/api/pypi/iotg-rbhe-pypi-or-local/simple
export PIP_EXTRA_INDEX_URL=https://pypi.org/simple
pip install LDAPclient

echo "[DEBUG] list pipdeptree..."
pip install pipdeptree
pipdeptree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ function main() {
apt-get install -y libgl1-mesa-glx
apt-get install -y libgl1-mesa-dev
apt-get install libsm6 libxext6 -y
apt-get install libldap2-dev -y
apt-get install libsasl2-dev -y
wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb
dpkg -i libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb
python -m pip install --upgrade --force-reinstall torch==2.1.0
pip install paddlepaddle==2.4.2 paddlenlp==2.5.2 paddlespeech==1.4.1 paddle2onnx==1.0.6
export PIP_INDEX_URL=https://ubit-artifactory-or.intel.com/artifactory/api/pypi/iotg-rbhe-pypi-or-local/simple
export PIP_EXTRA_INDEX_URL=https://pypi.org/simple
pip install LDAPclient
cd ${WORKING_DIR} || exit 1
echo "test on ${test_name}"
if [[ $test_name == "PR-test" ]]; then
Expand Down
2 changes: 2 additions & 0 deletions intel_extension_for_transformers/neural_chat/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
accelerate
aiosqlite
cchardet
einops
evaluate
fastapi==0.103.2
fastapi-users[sqlalchemy,oauth]
fschat==0.2.32
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
huggingface_hub
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
--extra-index-url https://download.pytorch.org/whl/cpu
aiosqlite
cchardet
cchardet
einops
einops
evaluate
fastapi==0.103.2
fastapi-users[sqlalchemy,oauth]
fschat==0.2.32
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
intel_extension_for_pytorch==2.1.0
neural-compressor
neural-compressor
neural_speed
neural_speed
numpy==1.23.5
optimum
optimum-intel
peft==0.6.2
pydantic==1.10.13
python-dotenv
python-dotenv
python-multipart
python-multipart
rouge_score
shortuuid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
aiosqlite
cchardet
einops
evaluate
fastapi==0.103.2
fastapi-users[sqlalchemy,oauth]
fschat==0.2.32
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
intel_extension_for_pytorch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
--extra-index-url https://download.pytorch.org/whl/cpu
aiosqlite
cchardet
cchardet
einops
einops
evaluate
fastapi==0.103.2
fastapi-users[sqlalchemy,oauth]
fschat==0.2.32
git+https://github.com/EleutherAI/lm-evaluation-harness.git@cc9778fbe4fa1a709be2abed9deb6180fd40e7e2
neural-compressor
neural-compressor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already have neural-compressor

neural_speed
numpy==1.23.5
optimum
optimum-intel
peft
pydantic==1.10.13
python-dotenv
python-dotenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python-dotenv is also there

python-multipart
python-multipart
rouge_score
shortuuid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
aiosqlite
cchardet
einops
evaluate
fastapi==0.103.2
fastapi-users[sqlalchemy,oauth]
fschat==0.2.32
neural-compressor
numpy==1.23.5
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from dotenv import load_dotenv

from functools import lru_cache

from pydantic import BaseSettings

from intel_extension_for_transformers.utils import logger

load_dotenv()


class Settings(BaseSettings):
mysql_user: str = os.environ.get("MYSQL_USER", "root")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to organize those settings in a more structured way e.g., database related, auth related (base auth, child auth ...)

mysql_password: str = os.environ.get("MYSQL_PASSWORD")
mysql_host: str = os.environ.get("MYSQL_HOST", "localhost")
mysql_db: str = os.getenv("MYSQL_DB", "inc")
google_oauth_client_id: str = os.getenv("GOOGLE_OAUTH_CLIENT_ID", "")
google_oauth_client_secret: str = os.getenv("GOOGLE_OAUTH_CLIENT_SECRET", "")
github_oauth_client_id: str = os.getenv("GITHUB_OAUTH_CLIENT_ID", "")
github_oauth_client_secret: str = os.getenv("GITHUB_OAUTH_CLIENT_SECRET", "")
facebook_oauth_client_id: str = os.getenv("FACEBOOK_OAUTH_CLIENT_ID", "")
facebook_oauth_client_secret: str = os.getenv("FACEBOOK_OAUTH_CLIENT_SECRET", "")
microsoft_oauth_client_id: str = os.getenv("MICROSOFT_OAUTH_CLIENT_ID", "")
microsoft_oauth_client_secret: str = os.getenv("MICROSOFT_OAUTH_CLIENT_SECRET", "")


@lru_cache()
def get_settings() -> BaseSettings:
logger.info("Loading config settings from the environment...")
return Settings()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import AsyncGenerator, List

from fastapi import Depends
from fastapi_users.db import (
SQLAlchemyBaseOAuthAccountTableUUID,
SQLAlchemyBaseUserTableUUID,
SQLAlchemyUserDatabase,
)
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, relationship, mapped_column
from sqlalchemy import String, Boolean, Column

DATABASE_URL = "sqlite+aiosqlite:///users.db"


class Base(DeclarativeBase):
pass


class OAuthAccount(SQLAlchemyBaseOAuthAccountTableUUID, Base):
pass


class User(SQLAlchemyBaseUserTableUUID, Base):
role = Column(String(length=50), default='user', nullable=False)
is_vipuser = Column(Boolean, default=False, nullable=False)
wwid = Column(String(length=50), nullable=True)
account = Column(String(length=50), nullable=True)
name = Column(String(length=255), nullable=True)
given_name = Column(String(length=255), nullable=True)
distinguished_name = Column(String(length=255), nullable=True)
idsid = Column(String(length=50), nullable=True)
generic = Column(Boolean, default=False, nullable=False)
SuperGroup = Column(String(length=50), nullable=True)
Group = Column(String(length=50), nullable=True)
Division = Column(String(length=50), nullable=True)
DivisionLong = Column(String(length=255), nullable=True)
CostCenterLong = Column(String(length=255), nullable=True)
mgrWWID = Column(String(length=50), nullable=True)

oauth_accounts: Mapped[List[OAuthAccount]] = relationship(
"OAuthAccount", lazy="joined"
)



engine = create_async_engine(DATABASE_URL)
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)


async def create_db_and_tables():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)


async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
async with async_session_maker() as session:
yield session


async def get_user_db(session: AsyncSession = Depends(get_async_session)):
yield SQLAlchemyUserDatabase(session, User, OAuthAccount)
Loading
Loading