-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial implementation of Personas API in klatchat * Added personas endpoints and optimized middleware * Support for generic configs management --------- Co-authored-by: NeonKirill <[email protected]>
- Loading branch information
1 parent
67fa984
commit 19adcf8
Showing
25 changed files
with
948 additions
and
91 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework | ||
# All trademark and other rights reserved by their respective owners | ||
# Copyright 2008-2022 Neongecko.com Inc. | ||
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, | ||
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo | ||
# BSD-3 License | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from this | ||
# software without specific prior written permission. | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# Import blueprint here so it will be included | ||
from . import ( | ||
admin as admin_blueprint, | ||
auth as auth_blueprint, | ||
chat as chat_blueprint, | ||
users as users_blueprint, | ||
languages as languages_blueprint, | ||
files_api as files_api_blueprint, | ||
preferences as preferences_blueprint, | ||
personas as personas_blueprint, | ||
configs as configs_blueprint, | ||
) |
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,68 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework | ||
# All trademark and other rights reserved by their respective owners | ||
# Copyright 2008-2022 Neongecko.com Inc. | ||
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, | ||
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo | ||
# BSD-3 License | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from this | ||
# software without specific prior written permission. | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from fastapi import APIRouter, Depends | ||
from starlette.responses import JSONResponse | ||
|
||
from chat_server.server_utils.dependencies import CurrentUserDependency | ||
from chat_server.server_utils.exceptions import ( | ||
ItemNotFoundException, | ||
UserUnauthorizedException, | ||
) | ||
from chat_server.server_utils.http_utils import KlatAPIResponse | ||
from chat_server.server_utils.models.configs import SetConfigModel, ConfigModel | ||
from utils.database_utils.mongo_utils.queries.wrapper import MongoDocumentsAPI | ||
|
||
router = APIRouter( | ||
prefix="/configs", | ||
responses={"404": {"description": "Unknown endpoint"}}, | ||
) | ||
|
||
|
||
@router.get("/{config_property}") | ||
async def get_config_data(model: ConfigModel = Depends()) -> JSONResponse: | ||
"""Retrieves configured data by name""" | ||
items = MongoDocumentsAPI.CONFIGS.get_by_name( | ||
config_name=model.config_property, version=model.version | ||
) | ||
return JSONResponse(content=items) | ||
|
||
|
||
@router.put("/{config_property}") | ||
async def update_config( | ||
current_user: CurrentUserDependency, model: SetConfigModel = Depends() | ||
) -> JSONResponse: | ||
"""Updates provided config by name""" | ||
if "admin" not in current_user.roles: | ||
raise UserUnauthorizedException | ||
updated_data = MongoDocumentsAPI.CONFIGS.update_by_name( | ||
config_name=model.config_property, version=model.version, data=model.data | ||
) | ||
if updated_data.matched_count == 0: | ||
raise ItemNotFoundException | ||
return KlatAPIResponse.OK |
Oops, something went wrong.