Skip to content

Python SDK Removal #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
100 changes: 1 addition & 99 deletions api/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import_wizard as cognition_import_wizard,
)
from exceptions.exceptions import BadPasswordError
from submodules.s3 import controller as s3
from submodules.model.business_objects import (
attribute,
general,
organization,
tokenization,
project,
)
Expand All @@ -27,10 +25,8 @@
from controller.transfer import manager as transfer_manager
from controller.upload_task import manager as upload_task_manager
from controller.auth import manager as auth_manager
from controller.transfer import association_transfer_manager
from controller.project import manager as project_manager
from controller.attribute import manager as attribute_manager

from controller.project import manager as project_manager
from submodules.model import enums, exceptions
from util.notification import create_notification
from submodules.model.enums import NotificationType
Expand Down Expand Up @@ -98,72 +94,6 @@ async def post(self, request) -> PlainTextResponse:
return PlainTextResponse("OK")


class FileExport(HTTPEndpoint):
def get(self, request) -> JSONResponse:
project_id = request.path_params["project_id"]
user_id = request.query_params["user_id"]
num_samples = request.query_params.get("num_samples")
try:
auth_manager.check_project_access_from_user_id(
user_id, project_id, from_api=True
)
except exceptions.EntityNotFoundException:
return JSONResponse({"error": "Could not find project"}, status_code=404)
except exceptions.AccessDeniedException:
return JSONResponse({"error": "Access denied"}, status_code=403)
result = transfer_manager.export_records(project_id, num_samples)
return JSONResponse(result)


class KnowledgeBaseExport(HTTPEndpoint):
def get(self, request) -> JSONResponse:
project_id = request.path_params["project_id"]
list_id = request.path_params["knowledge_base_id"]
user_id = request.query_params["user_id"]
try:
auth_manager.check_project_access_from_user_id(
user_id, project_id, from_api=True
)
except exceptions.EntityNotFoundException:
return JSONResponse({"error": "Could not find project"}, status_code=404)
except exceptions.AccessDeniedException:
return JSONResponse({"error": "Access denied"}, status_code=403)
result = transfer_manager.export_knowledge_base(project_id, list_id)
return JSONResponse(result)


class PrepareFileImport(HTTPEndpoint):
async def post(self, request) -> JSONResponse:
project_id = request.path_params["project_id"]
request_body = await request.json()

user_id = request_body["user_id"]
try:
auth_manager.check_project_access_from_user_id(
user_id, project_id, from_api=True
)
except exceptions.EntityNotFoundException:
return JSONResponse({"error": "Could not find project"}, status_code=404)
except exceptions.AccessDeniedException:
return JSONResponse({"error": "Access denied"}, status_code=403)
file_name = request_body["file_name"]
file_type = request_body["file_type"]
file_import_options = request_body.get("file_import_options")
task = upload_task_manager.create_upload_task(
user_id,
project_id,
file_name,
file_type,
file_import_options,
upload_type=enums.UploadTypes.DEFAULT.value,
)
org_id = organization.get_id_by_project_id(project_id)
credentials_and_id = s3.get_upload_credentials_and_id(
org_id, f"{project_id}/{task.id}"
)
return JSONResponse(credentials_and_id)


class JSONImport(HTTPEndpoint):
async def post(self, request) -> JSONResponse:
project_id = request.path_params["project_id"]
Expand Down Expand Up @@ -239,34 +169,6 @@ def put(self, request) -> PlainTextResponse:
return PlainTextResponse("OK")


class AssociationsImport(HTTPEndpoint):
async def post(self, request) -> JSONResponse:
# Will be removed as part of the python sdk removal
return JSONResponse({"error": "Not supported anymore"}, status_code=404)

project_id = request.path_params["project_id"]
request_body = await request.json()
user_id = request_body["user_id"]
try:
auth_manager.check_project_access_from_user_id(
user_id, project_id, from_api=True
)
except exceptions.EntityNotFoundException:
return JSONResponse({"error": "Could not find project"}, status_code=404)
except exceptions.AccessDeniedException:
return JSONResponse({"error": "Access denied"}, status_code=403)
new_associations_added = association_transfer_manager.import_associations(
project_id,
user_id,
request_body["name"],
request_body["label_task_name"],
request_body["associations"],
request_body["indices"],
request_body["source_type"],
)
return JSONResponse(new_associations_added)


class UploadTaskInfo(HTTPEndpoint):
def get(self, request) -> JSONResponse:
project_id = request.path_params["project_id"]
Expand Down
13 changes: 1 addition & 12 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
)
from api.project import ProjectDetails
from api.transfer import (
AssociationsImport,
FileExport,
JSONImport,
KnowledgeBaseExport,
Notify,
PrepareFileImport,
UploadTaskInfo,
JSONImport,
CognitionImport,
CognitionPrepareProject,
)
Expand Down Expand Up @@ -124,13 +120,6 @@
Route("/notify/{path:path}", Notify),
Route("/healthcheck", Healthcheck),
Route("/project/{project_id:str}", ProjectDetails),
Route(
"/project/{project_id:str}/knowledge_base/{knowledge_base_id:str}",
KnowledgeBaseExport,
),
Route("/project/{project_id:str}/associations", AssociationsImport),
Route("/project/{project_id:str}/export", FileExport),
Route("/project/{project_id:str}/import_file", PrepareFileImport),
Route("/project/{project_id:str}/import_json", JSONImport),
Route(
"/project/{project_id:str}/cognition/continue/{task_id:str}", CognitionImport
Expand Down