This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
[NeuralChat] Support user management in backend server #952
Open
lvliang-intel
wants to merge
23
commits into
main
Choose a base branch
from
lvl/user_management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 c12f7ec
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 912d190
fix ut issues
lvliang-intel b19e91e
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 68998d6
fix copyright
lvliang-intel d17e1ff
fix pylint issues
lvliang-intel dbdd3b4
support IntelLDAP
lvliang-intel b9b0a95
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 97972c9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 36a54b5
update code
lvliang-intel 6f3ece9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 4cff30d
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel cbdbb38
fix pylint issue
lvliang-intel ded96da
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 072a19c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] abc55bf
fix email issue
lvliang-intel 5707d8a
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 8bd4ad3
Merge branch 'lvl/user_management' of https://github.com/intel/intel-…
lvliang-intel 80c2915
only verify account and password
lvliang-intel 180a970
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 59cc602
fix pylint
lvliang-intel b0768ee
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel 63798e7
Merge branch 'main' into lvl/user_management
lvliang-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
intel_extension_for_transformers/neural_chat/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
intel_extension_for_transformers/neural_chat/requirements_cpu.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
intel_extension_for_transformers/neural_chat/requirements_hpu.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
intel_extension_for_transformers/neural_chat/requirements_pc.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
neural_speed | ||
numpy==1.23.5 | ||
optimum | ||
optimum-intel | ||
peft | ||
pydantic==1.10.13 | ||
python-dotenv | ||
python-dotenv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. python-dotenv is also there |
||
python-multipart | ||
python-multipart | ||
rouge_score | ||
shortuuid | ||
|
2 changes: 2 additions & 0 deletions
2
intel_extension_for_transformers/neural_chat/requirements_xpu.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
intel_extension_for_transformers/neural_chat/server/config/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
48 changes: 48 additions & 0 deletions
48
intel_extension_for_transformers/neural_chat/server/config/config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
16 changes: 16 additions & 0 deletions
16
intel_extension_for_transformers/neural_chat/server/database/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
79 changes: 79 additions & 0 deletions
79
intel_extension_for_transformers/neural_chat/server/database/user_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already have neural-compressor